Revision 458 org.gvsig.projection.jcrs/trunk/org.gvsig.projection.jcrs/org.gvsig.projection.jcrs.lib/src/main/java/org/gvsig/crs/Crs.java
Crs.java | ||
---|---|---|
89 | 89 |
Color gridColor = basicGridColor; |
90 | 90 |
CRSDatum datum = null; |
91 | 91 |
|
92 |
private SpatialReference spatialReference = null; |
|
92 | 93 |
|
94 |
|
|
93 | 95 |
/** |
96 |
* @param spatialReference |
|
94 | 97 |
* |
95 | 98 |
*/ |
96 | 99 |
public Crs(SpatialReference spatialReference) { |
... | ... | |
101 | 104 |
* @param spatialReference |
102 | 105 |
*/ |
103 | 106 |
private void initFromSpatialReference(SpatialReference spatialReference) { |
107 |
this.spatialReference = spatialReference; |
|
104 | 108 |
String authorityCode = spatialReference.GetAuthorityCode(null); |
105 | 109 |
String authorityName = spatialReference.GetAuthorityName(null); |
106 | 110 |
spatialReference.Fixup(); |
... | ... | |
126 | 130 |
setWKT(spatialReference.ExportToWkt()); |
127 | 131 |
} |
128 | 132 |
|
133 |
/** |
|
134 |
* @param epsgCode |
|
135 |
* @param aut |
|
136 |
* @throws CrsException |
|
137 |
*/ |
|
129 | 138 |
public Crs(int epsgCode, int aut) throws CrsException { |
130 | 139 |
String strEpsgCode = ""; |
131 | 140 |
if (aut == 1) { |
... | ... | |
155 | 164 |
fullCode = code; |
156 | 165 |
else |
157 | 166 |
fullCode = "EPSG:" + code; |
158 |
String cod = ""; |
|
159 | 167 |
if (code.length() < 15) { |
160 | 168 |
code = code.substring(code.indexOf(":") + 1); |
161 | 169 |
try { |
... | ... | |
211 | 219 |
* @throws CrsException |
212 | 220 |
*/ |
213 | 221 |
public Crs(int epsg_cod, String code) throws CrsException { |
214 |
String fullCode; |
|
222 |
// String fullCode;
|
|
215 | 223 |
setWKT(code); |
216 | 224 |
setCode(epsg_cod); |
217 |
if (code != null || code.charAt(0) == 'E' || code.charAt(0) == 'G' || code.charAt(0) == 'P') |
|
218 |
fullCode = code; |
|
219 |
else |
|
220 |
fullCode = "EPSG:" + code; |
|
225 |
// if (code != null || code.charAt(0) == 'E' || code.charAt(0) == 'G' || code.charAt(0) == 'P')
|
|
226 |
// fullCode = code;
|
|
227 |
// else
|
|
228 |
// fullCode = "EPSG:" + code;
|
|
221 | 229 |
|
222 | 230 |
SpatialReference sr = new SpatialReference(); |
223 | 231 |
// Vector<String> vector = new Vector<String>(); |
... | ... | |
364 | 372 |
fullCode = code; |
365 | 373 |
else |
366 | 374 |
fullCode = "EPSG:" + code; |
367 |
String cod = ""; |
|
368 | 375 |
if (code.length() < 15) { |
369 | 376 |
code = code.substring(code.indexOf(":") + 1); |
370 | 377 |
try { |
... | ... | |
459 | 466 |
} |
460 | 467 |
|
461 | 468 |
/** |
462 |
* @return |
|
469 |
* @return datum
|
|
463 | 470 |
*/ |
464 | 471 |
public IDatum getDatum() { |
465 | 472 |
|
... | ... | |
467 | 474 |
} |
468 | 475 |
|
469 | 476 |
/** |
470 |
* @return |
|
477 |
* @return CrsWkt
|
|
471 | 478 |
*/ |
472 | 479 |
public CrsWkt getCrsWkt() { |
473 | 480 |
return crsWkt; |
... | ... | |
482 | 489 |
} |
483 | 490 |
|
484 | 491 |
/** |
485 |
* @return |
|
492 |
* @return wkt
|
|
486 | 493 |
*/ |
487 | 494 |
public String getWKT() { |
488 | 495 |
return this.wkt; |
... | ... | |
500 | 507 |
/** |
501 | 508 |
* Devuelve los parametros de la transformacion del crs fuente |
502 | 509 |
* |
503 |
* @return |
|
510 |
* @return source transformation parameters
|
|
504 | 511 |
*/ |
505 | 512 |
public String getSourceTransformationParams() { |
506 | 513 |
return this.sourceTrParams; |
... | ... | |
509 | 516 |
/** |
510 | 517 |
* Devuelve los parametros de la transformacion del crs destino |
511 | 518 |
* |
512 |
* @return |
|
519 |
* @return target transformation parameters
|
|
513 | 520 |
*/ |
514 | 521 |
public String getTargetTransformationParams() { |
515 | 522 |
return this.targetTrParams; |
516 | 523 |
} |
517 | 524 |
|
518 | 525 |
/** |
519 |
* @return |
|
526 |
* @return transformation parameters
|
|
520 | 527 |
*/ |
521 | 528 |
public String getTransformationParams() { |
522 | 529 |
return this.sourceTrParams; |
... | ... | |
524 | 531 |
|
525 | 532 |
/** |
526 | 533 |
* |
527 |
* @return |
|
534 |
* @return CrsProj
|
|
528 | 535 |
*/ |
529 | 536 |
public CrsProj getCrsProj() { |
530 | 537 |
if (crsProj == null) |
... | ... | |
539 | 546 |
/** |
540 | 547 |
* @param x |
541 | 548 |
* @param y |
542 |
* @return |
|
549 |
* @return a Point2D
|
|
543 | 550 |
*/ |
544 | 551 |
public Point2D createPoint(double x, double y) { |
545 | 552 |
return new Point2D.Double(x, y); |
... | ... | |
562 | 569 |
} |
563 | 570 |
|
564 | 571 |
/** |
565 |
* @return |
|
572 |
* @return grid color
|
|
566 | 573 |
*/ |
567 | 574 |
public Color getGridColor() { |
568 | 575 |
return gridColor; |
... | ... | |
570 | 577 |
|
571 | 578 |
/** |
572 | 579 |
* @param dest |
573 |
* @return |
|
580 |
* @return Coordinate transformation
|
|
574 | 581 |
*/ |
575 | 582 |
public ICoordTrans getCT(IProjection dest) { |
576 | 583 |
|
... | ... | |
616 | 623 |
|
617 | 624 |
/** |
618 | 625 |
* @param pt |
619 |
* @return |
|
626 |
* @return Point2D
|
|
620 | 627 |
*/ |
621 | 628 |
public Point2D toGeo(Point2D pt) { |
622 | 629 |
if (isProjected()) { |
... | ... | |
636 | 643 |
/** |
637 | 644 |
* @param gPt |
638 | 645 |
* @param mPt |
639 |
* @return |
|
646 |
* @return Point2D
|
|
640 | 647 |
*/ |
641 | 648 |
public Point2D fromGeo(Point2D gPt, Point2D mPt) { |
642 | 649 |
// TODO Auto-generated method stub |
... | ... | |
644 | 651 |
} |
645 | 652 |
|
646 | 653 |
/** |
647 |
* @return |
|
654 |
* @return true if is projected
|
|
648 | 655 |
*/ |
649 | 656 |
public boolean isProjected() { |
650 | 657 |
return !getCrsProj().isLatlong(); |
... | ... | |
655 | 662 |
* @param maxX |
656 | 663 |
* @param width |
657 | 664 |
* @param dpi |
658 |
* @return |
|
665 |
* @return scale
|
|
659 | 666 |
*/ |
660 | 667 |
public double getScale(double minX, double maxX, double width, double dpi) { |
661 | 668 |
double scale = 0D; |
... | ... | |
676 | 683 |
return scale; |
677 | 684 |
} |
678 | 685 |
|
686 |
/** |
|
687 |
* @param minX |
|
688 |
* @param maxX |
|
689 |
* @param minY |
|
690 |
* @param maxY |
|
691 |
* @param width |
|
692 |
* @param dpi |
|
693 |
* @return scale |
|
694 |
*/ |
|
679 | 695 |
public double getScale(double minX, double maxX, double minY, double maxY, double width, double dpi) { |
680 | 696 |
|
681 | 697 |
double scale = 0D; |
... | ... | |
715 | 731 |
} |
716 | 732 |
|
717 | 733 |
/** |
718 |
* @return |
|
734 |
* @return espg code
|
|
719 | 735 |
*/ |
720 | 736 |
public int getCode() { |
721 | 737 |
// TODO Auto-generated method stub |
... | ... | |
798 | 814 |
* @see org.cresques.cts.IProjection#export(java.lang.String) |
799 | 815 |
*/ |
800 | 816 |
public String export(String format) { |
801 |
SpatialReference spatialReference = getCrsProj().getSpatialReference(); |
|
802 |
if(format.equalsIgnoreCase(ICRSFactory.FORMAT_PROJ4)){ |
|
803 |
return spatialReference.ExportToProj4(); |
|
804 |
} else if(format.equalsIgnoreCase(ICRSFactory.FORMAT_WKT_ESRI)){ |
|
805 |
if(spatialReference.MorphToESRI() == 0){ |
|
817 |
if (this.spatialReference != null) { |
|
818 |
if (format.equalsIgnoreCase(ICRSFactory.FORMAT_PROJ4)) { |
|
819 |
return spatialReference.ExportToProj4(); |
|
820 |
} else if (format.equalsIgnoreCase(ICRSFactory.FORMAT_WKT_ESRI)) { |
|
821 |
if (spatialReference.MorphToESRI() == 0) { |
|
822 |
return spatialReference.ExportToWkt(); |
|
823 |
} |
|
824 |
return null; |
|
825 |
} else if (format.equalsIgnoreCase(ICRSFactory.FORMAT_WKT)) { |
|
806 | 826 |
return spatialReference.ExportToWkt(); |
827 |
} else { |
|
828 |
return null; |
|
807 | 829 |
} |
808 |
return null; |
|
809 |
} else if(format.equalsIgnoreCase(ICRSFactory.FORMAT_WKT)){ |
|
810 |
return spatialReference.ExportToWkt(); |
|
830 |
} else { |
|
831 |
|
|
832 |
SpatialReference spatialReference = getCrsProj().getSpatialReference(); |
|
833 |
SpatialReference auxSpatialReference = new SpatialReference(); |
|
834 |
if (format.equalsIgnoreCase(ICRSFactory.FORMAT_PROJ4)) { |
|
835 |
String proj4 = spatialReference.ExportToProj4(); |
|
836 |
auxSpatialReference.ImportFromProj4(proj4); |
|
837 |
if (auxSpatialReference.GetAuthorityName(null) != null) { |
|
838 |
return proj4; |
|
839 |
} |
|
840 |
return null; |
|
841 |
} else if (format.equalsIgnoreCase(ICRSFactory.FORMAT_WKT_ESRI)) { |
|
842 |
if (spatialReference.MorphToESRI() == 0) { |
|
843 |
String esri = spatialReference.ExportToWkt(); |
|
844 |
Vector<String> vector = new Vector<String>(); |
|
845 |
vector.add(esri); |
|
846 |
auxSpatialReference.ImportFromESRI(vector); |
|
847 |
auxSpatialReference.MorphFromESRI(); |
|
848 |
if (auxSpatialReference.GetAuthorityName(null) != null) { |
|
849 |
return esri; |
|
850 |
} |
|
851 |
return null; |
|
852 |
} |
|
853 |
return null; |
|
854 |
} else if (format.equalsIgnoreCase(ICRSFactory.FORMAT_WKT)) { |
|
855 |
String wkt = spatialReference.ExportToWkt(); |
|
856 |
auxSpatialReference.ImportFromWkt(wkt); |
|
857 |
if (auxSpatialReference.GetAuthorityName(null) != null) { |
|
858 |
return wkt; |
|
859 |
} |
|
860 |
return null; |
|
861 |
} else { |
|
862 |
return null; |
|
863 |
} |
|
811 | 864 |
} |
812 |
return null; |
|
813 | 865 |
} |
814 | 866 |
} |
Also available in: Unified diff