Revision 11105
branches/F2/libraries/libJCRS/src/org/gvsig/crs/CrsWkt.java | ||
---|---|---|
42 | 42 |
|
43 | 43 |
import java.util.ArrayList; |
44 | 44 |
|
45 |
import javax.units.ConversionException; |
|
46 |
import javax.units.Unit; |
|
47 |
|
|
45 | 48 |
import org.geotools.referencing.CRS; |
46 | 49 |
import org.geotools.referencing.crs.DefaultGeographicCRS; |
47 | 50 |
import org.geotools.referencing.crs.DefaultProjectedCRS; |
48 | 51 |
import org.geotools.referencing.datum.DefaultEllipsoid; |
49 | 52 |
import org.geotools.referencing.datum.DefaultGeodeticDatum; |
50 | 53 |
import org.geotools.referencing.datum.DefaultPrimeMeridian; |
54 |
|
|
51 | 55 |
import org.opengis.referencing.FactoryException; |
52 | 56 |
import org.opengis.referencing.NoSuchAuthorityCodeException; |
53 | 57 |
import org.opengis.referencing.NoSuchIdentifierException; |
54 | 58 |
import org.opengis.referencing.crs.CoordinateReferenceSystem; |
59 |
import org.opengis.referencing.datum.Ellipsoid; |
|
60 |
import org.opengis.referencing.datum.PrimeMeridian; |
|
55 | 61 |
|
56 | 62 |
/** |
57 | 63 |
* Clase que parsea una cadena wkt y consigue todos sus par?metros |
... | ... | |
77 | 83 |
private int contador = 0; |
78 | 84 |
private String[] authority = {"",""}; |
79 | 85 |
|
86 |
int divider=10000; |
|
87 |
|
|
88 |
/** |
|
89 |
* Small tolerance factor for rounding errors. |
|
90 |
*/ |
|
91 |
private static final double EPS = 1E-8; |
|
92 |
|
|
80 | 93 |
public CrsWkt(String wkt_spaces) { |
81 | 94 |
String aux; |
82 | 95 |
String wkt = ""; |
... | ... | |
548 | 561 |
try { |
549 | 562 |
source = CRS.decode(code); |
550 | 563 |
setWkt(source.toWKT()); |
564 |
|
|
551 | 565 |
if (source instanceof DefaultProjectedCRS) { |
552 | 566 |
DefaultProjectedCRS sour = (DefaultProjectedCRS) source; |
553 | 567 |
setProjcs(sour.getName().toString().split(":")[1]); |
... | ... | |
556 | 570 |
|
557 | 571 |
DefaultGeodeticDatum d = (DefaultGeodeticDatum) sour.getDatum(); |
558 | 572 |
setDatumName(d.getName().toString().split(":")[1]); |
559 |
setSpheroid((DefaultEllipsoid)d.getEllipsoid()); |
|
560 |
setPrimen((DefaultPrimeMeridian) d.getPrimeMeridian());
|
|
573 |
setSpheroid((DefaultEllipsoid)d.getEllipsoid());
|
|
574 |
setPrimen(d.getPrimeMeridian()); |
|
561 | 575 |
|
562 | 576 |
setProjection(sour.getConversionFromBase().getMethod().getName().toString().split(":")[1]); |
563 | 577 |
String str; |
... | ... | |
565 | 579 |
param_value= new String[sour.getConversionFromBase().getParameterValues().values().size()]; |
566 | 580 |
for (int i=0; i< sour.getConversionFromBase().getParameterValues().values().size();i++) { |
567 | 581 |
str = sour.getConversionFromBase().getParameterValues().values().get(i).toString(); |
582 |
Unit u = sour.getConversionFromBase().getParameterValues().parameter(str.split("=")[0]).getUnit(); |
|
583 |
double value = sour.getConversionFromBase().getParameterValues().parameter(str.split("=")[0]).doubleValue(); |
|
584 |
value = convert(value, u.toString()); |
|
568 | 585 |
param_name[i] = str.split("=")[0]; |
569 |
param_value [i] = str.split("=")[1];
|
|
586 |
param_value [i] = String.valueOf(value);
|
|
570 | 587 |
} |
571 | 588 |
|
572 |
//System.out.println("Hola: "+sour.getConversionFromBase().getParameterValues().values()); |
|
573 |
|
|
574 |
//System.out.println("Hola: "+d.getEllipsoid().getSemiMajorAxis()); |
|
575 | 589 |
} |
576 | 590 |
|
577 | 591 |
if (source instanceof DefaultGeographicCRS) { |
... | ... | |
581 | 595 |
|
582 | 596 |
DefaultGeodeticDatum d = (DefaultGeodeticDatum) sour.getDatum(); |
583 | 597 |
setDatumName(d.getName().toString().split(":")[1]); |
584 |
setSpheroid((DefaultEllipsoid)d.getEllipsoid()); |
|
585 |
setPrimen((DefaultPrimeMeridian) d.getPrimeMeridian());
|
|
598 |
setSpheroid((DefaultEllipsoid)d.getEllipsoid());
|
|
599 |
setPrimen(d.getPrimeMeridian()); |
|
586 | 600 |
|
587 |
//System.out.println("Hola: "+sour.getDatum()); |
|
588 | 601 |
} |
589 | 602 |
} catch (NoSuchIdentifierException e) { |
590 | 603 |
//System.out.println("Noooo: "+e); |
... | ... | |
620 | 633 |
} |
621 | 634 |
|
622 | 635 |
public void setSpheroid (DefaultEllipsoid ellips) { |
636 |
Unit u = ellips.getAxisUnit(); |
|
637 |
double semi_major = convert( ellips.getSemiMajorAxis(), u.toString()); |
|
638 |
double inv_f = convert( ellips.getInverseFlattening(), u.toString()); |
|
639 |
|
|
623 | 640 |
this.spheroid[0] = ellips.getName().toString().split(":")[1]; |
624 |
this.spheroid[1] = String.valueOf(ellips.getSemiMajorAxis());
|
|
625 |
this.spheroid[2] = String.valueOf(ellips.getInverseFlattening());
|
|
641 |
this.spheroid[1] = String.valueOf(semi_major);
|
|
642 |
this.spheroid[2] = String.valueOf(inv_f);
|
|
626 | 643 |
} |
627 | 644 |
|
628 |
public void setPrimen (DefaultPrimeMeridian prim) { |
|
629 |
this.primem[0] = prim.getName().toString().split(":")[1]; |
|
630 |
this.primem[1] = String.valueOf(prim.getGreenwichLongitude()); |
|
645 |
public void setPrimen (PrimeMeridian prim) { |
|
646 |
DefaultPrimeMeridian pm = new DefaultPrimeMeridian(prim); |
|
647 |
Unit u = pm.getAngularUnit(); |
|
648 |
double value = convert( pm.getGreenwichLongitude(), u.toString()); |
|
649 |
|
|
650 |
this.primem[0] = pm.getName().toString().split(":")[1]; |
|
651 |
this.primem[1] = String.valueOf(value); |
|
631 | 652 |
} |
632 | 653 |
|
633 | 654 |
public void setUnit () { |
... | ... | |
657 | 678 |
public String getWkt() { |
658 | 679 |
return wkt; |
659 | 680 |
} |
681 |
|
|
682 |
public double convert(double value, String measure) throws ConversionException { |
|
683 |
if (measure.equals("D.MS")) { |
|
684 |
value *= this.divider; |
|
685 |
int deg,min; |
|
686 |
deg = (int) (value/10000); value -= 10000*deg; |
|
687 |
min = (int) (value/ 100); value -= 100*min; |
|
688 |
if (min<=-60 || min>=60) { // Accepts NaN |
|
689 |
if (Math.abs(Math.abs(min) - 100) <= EPS) { |
|
690 |
if (min >= 0) deg++; else deg--; |
|
691 |
min = 0; |
|
692 |
} else { |
|
693 |
throw new ConversionException("Invalid minutes: "+min); |
|
694 |
} |
|
695 |
} |
|
696 |
if (value<=-60 || value>=60) { // Accepts NaN |
|
697 |
if (Math.abs(Math.abs(value) - 100) <= EPS) { |
|
698 |
if (value >= 0) min++; else min--; |
|
699 |
value = 0; |
|
700 |
} else { |
|
701 |
throw new ConversionException("Invalid secondes: "+value); |
|
702 |
} |
|
703 |
} |
|
704 |
value = ((value/60) + min)/60 + deg; |
|
705 |
return value; |
|
706 |
} |
|
707 |
if (measure.equals("grad") || measure.equals("grade")) |
|
708 |
return ((value * 180.0) / 200.0); |
|
709 |
if (measure.equals(""+(char)176)) |
|
710 |
return value; |
|
711 |
if (measure.equals("DMS") ) |
|
712 |
return value; |
|
713 |
if (measure.equals("m")) |
|
714 |
return value; |
|
715 |
|
|
716 |
throw new ConversionException("Conversion no contemplada: "+measure); |
|
717 |
} |
|
660 | 718 |
} |
Also available in: Unified diff