Revision 828
org.gvsig.geotools.proj/trunk/org.gvsig.geotools.proj/org.gvsig.geotools.proj.lib.impl/src/main/resources/META-INF/services/org.gvsig.tools.library.Library | ||
---|---|---|
1 |
org.gvsig.geotools.proj.lib.GtCRSLibrary |
org.gvsig.geotools.proj/trunk/org.gvsig.geotools.proj/org.gvsig.geotools.proj.lib.impl/src/main/java/org/cresques/cts/DatumAdapter.java | ||
---|---|---|
1 |
package org.cresques.cts; |
|
2 |
|
|
3 |
import org.gvsig.proj.catalog.datum.Ellipsoid; |
|
4 |
|
|
5 |
public class DatumAdapter implements IDatum { |
|
6 |
final Ellipsoid ellipsoid; |
|
7 |
public DatumAdapter(Ellipsoid ellipsoid) { |
|
8 |
this.ellipsoid = ellipsoid; |
|
9 |
} |
|
10 |
|
|
11 |
@Override |
|
12 |
public double getESemiMajorAxis() { |
|
13 |
return ellipsoid.getSemiMajorAxis(); |
|
14 |
} |
|
15 |
|
|
16 |
@Override |
|
17 |
public double getEIFlattening() { |
|
18 |
return ellipsoid.getInverseFlattening(); |
|
19 |
} |
|
20 |
|
|
21 |
} |
org.gvsig.geotools.proj/trunk/org.gvsig.geotools.proj/org.gvsig.geotools.proj.lib.impl/src/main/java/org/cresques/cts/CoordTransAdapter.java | ||
---|---|---|
1 |
package org.cresques.cts; |
|
2 |
|
|
3 |
import java.awt.geom.Point2D; |
|
4 |
import java.awt.geom.Rectangle2D; |
|
5 |
|
|
6 |
import org.cresques.cts.CoordTransRuntimeException; |
|
7 |
import org.cresques.cts.ICoordTrans; |
|
8 |
import org.cresques.cts.IProjection; |
|
9 |
import org.gvsig.proj.CoordinateReferenceSystem; |
|
10 |
import org.gvsig.proj.CoordinateTransformation; |
|
11 |
import org.gvsig.proj.catalog.exception.TransformationException; |
|
12 |
|
|
13 |
public class CoordTransAdapter implements ICoordTrans { |
|
14 |
CoordinateTransformation transformation; |
|
15 |
CRSAdapter source, target; |
|
16 |
|
|
17 |
public CoordTransAdapter(CoordinateTransformation transformation, |
|
18 |
CRSAdapter source, |
|
19 |
CRSAdapter target) { |
|
20 |
this.transformation = transformation; |
|
21 |
this.source = source; |
|
22 |
this.target = target; |
|
23 |
} |
|
24 |
|
|
25 |
@Override |
|
26 |
public IProjection getPOrig() { |
|
27 |
return source; |
|
28 |
} |
|
29 |
|
|
30 |
@Override |
|
31 |
public IProjection getPDest() { |
|
32 |
return target; |
|
33 |
} |
|
34 |
|
|
35 |
@Override |
|
36 |
public Point2D convert(Point2D ptOrig, Point2D ptDest) throws CoordTransRuntimeException { |
|
37 |
double[] point = new double[2]; |
|
38 |
point[0] = ptOrig.getX(); |
|
39 |
point[1] = ptOrig.getY(); |
|
40 |
try { |
|
41 |
transformation.apply(point, point); |
|
42 |
} catch (TransformationException e) { |
|
43 |
throw new CoordTransRuntimeException(source, target, point[0], point[1], e); |
|
44 |
} |
|
45 |
ptDest.setLocation(point[0], point[1]); |
|
46 |
return ptDest; |
|
47 |
} |
|
48 |
|
|
49 |
|
|
50 |
public Rectangle2D convert(Rectangle2D rect) throws CoordTransRuntimeException { |
|
51 |
Point2D pt1 = new Point2D.Double(rect.getMinX(), rect.getMinY()); |
|
52 |
Point2D pt2 = new Point2D.Double(rect.getMaxX(), rect.getMaxY()); |
|
53 |
Point2D pt3 = new Point2D.Double(rect.getMinX(), rect.getMaxY()); |
|
54 |
Point2D pt4 = new Point2D.Double(rect.getMaxX(), rect.getMinY()); |
|
55 |
pt1 = convert(pt1, pt1); |
|
56 |
pt2 = convert(pt2, pt2); |
|
57 |
pt3 = convert(pt3, pt3); |
|
58 |
pt4 = convert(pt4, pt4); |
|
59 |
|
|
60 |
double min_x = Math.min(Math.min(pt1.getX(), pt2.getX()), Math.min(pt3.getX(), pt4.getX())); |
|
61 |
double min_y = Math.min(Math.min(pt1.getY(), pt2.getY()), Math.min(pt3.getY(), pt4.getY())); |
|
62 |
double max_x = Math.max(Math.max(pt1.getX(), pt2.getX()), Math.max(pt3.getX(), pt4.getX())); |
|
63 |
double max_y = Math.max(Math.max(pt1.getY(), pt2.getY()), Math.max(pt3.getY(), pt4.getY())); |
|
64 |
|
|
65 |
return new Rectangle2D.Double(min_x, min_y, max_x - min_x, max_y - min_y); |
|
66 |
} |
|
67 |
|
|
68 |
@Override |
|
69 |
public ICoordTrans getInverted() { |
|
70 |
// TODO Auto-generated method stub |
|
71 |
return null; |
|
72 |
} |
|
73 |
|
|
74 |
} |
org.gvsig.geotools.proj/trunk/org.gvsig.geotools.proj/org.gvsig.geotools.proj.lib.impl/src/main/java/org/cresques/cts/CRSAdapter.java | ||
---|---|---|
1 |
package org.cresques.cts; |
|
2 |
|
|
3 |
import java.awt.geom.Point2D; |
|
4 |
|
|
5 |
import org.cresques.cts.ICoordTrans; |
|
6 |
import org.cresques.cts.IProjection; |
|
7 |
import org.gvsig.geotools.proj.lib.GtCRSManager; |
|
8 |
import org.gvsig.proj.CoordinateReferenceSystem; |
|
9 |
import org.gvsig.proj.CoordinateReferenceSystemLocator; |
|
10 |
import org.gvsig.proj.CoordinateTransformation; |
|
11 |
import org.gvsig.proj.catalog.CRSType; |
|
12 |
import org.gvsig.proj.catalog.datum.Ellipsoid; |
|
13 |
import org.gvsig.proj.catalog.exception.TransformationException; |
|
14 |
import org.gvsig.proj.catalog.exception.UnsupportedCoordinateReferenceSystemException; |
|
15 |
|
|
16 |
public class CRSAdapter implements IProjection { |
|
17 |
CoordinateReferenceSystem crs; |
|
18 |
CRSAdapter transformationTargetCrs = null; |
|
19 |
CoordinateTransformation coordTrans = null; |
|
20 |
|
|
21 |
public CRSAdapter(CoordinateReferenceSystem crs) { |
|
22 |
this.crs = crs; |
|
23 |
} |
|
24 |
|
|
25 |
public CRSAdapter(CoordinateReferenceSystem crs, |
|
26 |
CoordinateTransformation coordTransformation, |
|
27 |
CoordinateReferenceSystem transformationTargetCrs) { |
|
28 |
this.crs = crs; |
|
29 |
this.coordTrans = coordTransformation; |
|
30 |
this.transformationTargetCrs = new CRSAdapter(transformationTargetCrs); |
|
31 |
} |
|
32 |
|
|
33 |
@Override |
|
34 |
public String export(String format) { |
|
35 |
// TODO Auto-generated method stub |
|
36 |
return null; |
|
37 |
} |
|
38 |
|
|
39 |
@Override |
|
40 |
public String getAbrev() { |
|
41 |
return crs.getDefinition().getIdentifier(); |
|
42 |
} |
|
43 |
|
|
44 |
@Override |
|
45 |
public String getFullCode() { |
|
46 |
// TODO Auto-generated method stub |
|
47 |
return getAbrev(); |
|
48 |
} |
|
49 |
|
|
50 |
@Override |
|
51 |
public ICoordTrans getCT(IProjection dest) { |
|
52 |
if (coordTrans!=null && |
|
53 |
dest.getCoordinateReferenceSystem().equals(transformationTargetCrs)) { |
|
54 |
return new CoordTransAdapter( |
|
55 |
coordTrans, |
|
56 |
this, |
|
57 |
this.transformationTargetCrs); |
|
58 |
} |
|
59 |
return null; |
|
60 |
} |
|
61 |
|
|
62 |
@Override |
|
63 |
public Point2D toGeo(Point2D pt) { |
|
64 |
double[] point = new double[2]; |
|
65 |
point[0] = pt.getX(); |
|
66 |
point[1] = pt.getY(); |
|
67 |
try { |
|
68 |
point = crs.toGeo(point); |
|
69 |
} catch (TransformationException e) { |
|
70 |
throw new RuntimeException(e); |
|
71 |
} |
|
72 |
return new Point2D.Double(point[0], point[1]); |
|
73 |
} |
|
74 |
|
|
75 |
@Override |
|
76 |
public boolean isProjected() { |
|
77 |
return this.crs.isProjected(); |
|
78 |
} |
|
79 |
|
|
80 |
@Override |
|
81 |
public double getScale(double minX, double maxX, double width, double dpi) { |
|
82 |
// TODO Auto-generated method stub |
|
83 |
return 0; |
|
84 |
} |
|
85 |
|
|
86 |
@Override |
|
87 |
public CoordinateReferenceSystem getCoordinateReferenceSystem() { |
|
88 |
return crs; |
|
89 |
} |
|
90 |
|
|
91 |
public Object clone() { |
|
92 |
return new CRSAdapter(this.crs); |
|
93 |
} |
|
94 |
|
|
95 |
@Override |
|
96 |
public IDatum getDatum() { |
|
97 |
Ellipsoid ellipsoid = this.crs.getDefinition().getDatum().getEllipsoid(); |
|
98 |
if (ellipsoid!=null) { |
|
99 |
return new DatumAdapter(ellipsoid); |
|
100 |
} |
|
101 |
throw new UnsupportedOperationException("Datum is not available for non-geodetic CRSs"); |
|
102 |
} |
|
103 |
|
|
104 |
} |
org.gvsig.geotools.proj/trunk/org.gvsig.geotools.proj/org.gvsig.geotools.proj.lib.impl/src/main/java/org/gvsig/geotools/proj/lib/GtCrsLibrary.java | ||
---|---|---|
1 |
/** |
|
2 |
* gvSIG. Desktop Geographic Information System. |
|
3 |
* |
|
4 |
* Copyright (C) 2018gvSIG Association. |
|
5 |
* |
|
6 |
* This program is free software; you can redistribute it and/or |
|
7 |
* modify it under the terms of the GNU General Public License |
|
8 |
* as published by the Free Software Foundation; either version 2 |
|
9 |
* of the License, or (at your option) any later version. |
|
10 |
* |
|
11 |
* This program is distributed in the hope that it will be useful, |
|
12 |
* but WITHOUT ANY WARRANTY; without even the implied warranty of |
|
13 |
* MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the |
|
14 |
* GNU General Public License for more details. |
|
15 |
* |
|
16 |
* You should have received a copy of the GNU General Public License |
|
17 |
* along with this program; if not, write to the Free Software |
|
18 |
* Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, |
|
19 |
* MA 02110-1301, USA. |
|
20 |
* |
|
21 |
* For any additional information, do not hesitate to contact us |
|
22 |
* at info AT gvsig.com, or visit our website www.gvsig.com. |
|
23 |
*/ |
|
24 |
package org.gvsig.geotools.proj.lib; |
|
25 |
|
|
26 |
import org.gvsig.proj.CoordinateReferenceSystemLibrary; |
|
27 |
import org.gvsig.proj.CoordinateReferenceSystemLocator; |
|
28 |
import org.gvsig.tools.library.AbstractLibrary; |
|
29 |
import org.gvsig.tools.library.LibraryException; |
|
30 |
|
|
31 |
/** |
|
32 |
* Library to register the Geotools-based implementation of the |
|
33 |
* org.gvsig.proj API. |
|
34 |
* |
|
35 |
* @author Cesar Martinez Izquierdo |
|
36 |
*/ |
|
37 |
public class GtCrsLibrary extends AbstractLibrary { |
|
38 |
|
|
39 |
public GtCrsLibrary() { |
|
40 |
registerAsImplementationOf(CoordinateReferenceSystemLibrary.class); |
|
41 |
} |
|
42 |
|
|
43 |
@Override |
|
44 |
protected void doInitialize() throws LibraryException { |
|
45 |
CoordinateReferenceSystemLocator.registerManager(GtCoordinateReferenceSystemManager.class); |
|
46 |
} |
|
47 |
|
|
48 |
@Override |
|
49 |
protected void doPostInitialize() throws LibraryException { |
|
50 |
// TODO Auto-generated method stub |
|
51 |
|
|
52 |
} |
|
53 |
|
|
54 |
} |
org.gvsig.geotools.proj/trunk/org.gvsig.geotools.proj/org.gvsig.geotools.proj.lib.impl/src/main/java/org/gvsig/geotools/proj/lib/GtCoordinateReferenceSystemManager.java | ||
---|---|---|
1 |
package org.gvsig.geotools.proj.lib; |
|
2 |
|
|
3 |
import java.text.ParseException; |
|
4 |
|
|
5 |
import org.gvsig.geotools.proj.catalog.DefaultCRS; |
|
6 |
import org.gvsig.geotools.proj.catalog.DefaultTransformation; |
|
7 |
import org.gvsig.proj.CoordinateReferenceSystem; |
|
8 |
import org.gvsig.proj.CoordinateReferenceSystemManager; |
|
9 |
import org.gvsig.proj.CoordinateTransformation; |
|
10 |
import org.gvsig.proj.catalog.CRSCatalogLocator; |
|
11 |
import org.gvsig.proj.catalog.CRSCatalogManager; |
|
12 |
import org.gvsig.proj.catalog.CRSDefinition; |
|
13 |
import org.gvsig.proj.catalog.TextSerialization.Format; |
|
14 |
import org.gvsig.proj.catalog.TransformationDefinition; |
|
15 |
import org.gvsig.proj.catalog.exception.UnsupportedTransformationException; |
|
16 |
import org.gvsig.proj.catalog.exception.UnsupportedCoordinateReferenceSystemException; |
|
17 |
|
|
18 |
public class GtCoordinateReferenceSystemManager implements CoordinateReferenceSystemManager { |
|
19 |
private CRSCatalogManager catalogManager = null; |
|
20 |
|
|
21 |
public GtCoordinateReferenceSystemManager() { |
|
22 |
} |
|
23 |
|
|
24 |
@Override |
|
25 |
public CoordinateReferenceSystem getCoordinateReferenceSystem(CRSDefinition definition) |
|
26 |
throws UnsupportedCoordinateReferenceSystemException { |
|
27 |
if (definition instanceof DefaultCRS) { |
|
28 |
return (DefaultCRS) definition; |
|
29 |
} |
|
30 |
else { |
|
31 |
return new DefaultCRS(definition.toWKT()); |
|
32 |
} |
|
33 |
} |
|
34 |
|
|
35 |
@Override |
|
36 |
public CoordinateReferenceSystem parseCoordinateReferenceSystem(String def) |
|
37 |
throws UnsupportedCoordinateReferenceSystemException, ParseException { |
|
38 |
return new DefaultCRS(def); |
|
39 |
} |
|
40 |
|
|
41 |
@Override |
|
42 |
public CoordinateReferenceSystem parseCoordinateReferenceSystem(String def, Format format) |
|
43 |
throws UnsupportedCoordinateReferenceSystemException { |
|
44 |
if (format==Format.WKT1) { |
|
45 |
return new DefaultCRS(def); |
|
46 |
} |
|
47 |
throw new UnsupportedOperationException("Format not supported"); |
|
48 |
} |
|
49 |
|
|
50 |
@Override |
|
51 |
public CoordinateTransformation parseCoordinateTransformation(String wkt) |
|
52 |
throws UnsupportedTransformationException, ParseException { |
|
53 |
return new DefaultTransformation(wkt); |
|
54 |
} |
|
55 |
|
|
56 |
|
|
57 |
@Override |
|
58 |
public CoordinateTransformation parseCoordinateTransformation(String def, Format format) |
|
59 |
throws UnsupportedTransformationException, ParseException { |
|
60 |
if (format==Format.WKT1) { |
|
61 |
return new DefaultTransformation(def); |
|
62 |
} |
|
63 |
throw new UnsupportedOperationException("Format not supported"); |
|
64 |
} |
|
65 |
|
|
66 |
@Override |
|
67 |
public CoordinateTransformation getCoordinateTransformation(TransformationDefinition definition) |
|
68 |
throws UnsupportedTransformationException, ParseException { |
|
69 |
if (definition instanceof DefaultTransformation) { |
|
70 |
return (CoordinateTransformation) definition; |
|
71 |
} |
|
72 |
return new DefaultTransformation(definition.toWKT()); |
|
73 |
} |
|
74 |
|
|
75 |
@Override |
|
76 |
public void setCatalogManager(CRSCatalogManager manager) { |
|
77 |
this.catalogManager = manager; |
|
78 |
} |
|
79 |
|
|
80 |
public CRSCatalogManager getCatalogManager() { |
|
81 |
if( this.catalogManager == null ) { |
|
82 |
this.catalogManager = CRSCatalogLocator.getManager(); |
|
83 |
} |
|
84 |
return this.catalogManager; |
|
85 |
} |
|
86 |
} |
org.gvsig.geotools.proj/trunk/org.gvsig.geotools.proj/org.gvsig.geotools.proj.lib.impl/src/main/java/org/gvsig/geotools/proj/lib/GtCRSLibrary.java | ||
---|---|---|
1 |
/** |
|
2 |
* gvSIG. Desktop Geographic Information System. |
|
3 |
* |
|
4 |
* Copyright (C) 2018gvSIG Association. |
|
5 |
* |
|
6 |
* This program is free software; you can redistribute it and/or |
|
7 |
* modify it under the terms of the GNU General Public License |
|
8 |
* as published by the Free Software Foundation; either version 2 |
|
9 |
* of the License, or (at your option) any later version. |
|
10 |
* |
|
11 |
* This program is distributed in the hope that it will be useful, |
|
12 |
* but WITHOUT ANY WARRANTY; without even the implied warranty of |
|
13 |
* MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the |
|
14 |
* GNU General Public License for more details. |
|
15 |
* |
|
16 |
* You should have received a copy of the GNU General Public License |
|
17 |
* along with this program; if not, write to the Free Software |
|
18 |
* Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, |
|
19 |
* MA 02110-1301, USA. |
|
20 |
* |
|
21 |
* For any additional information, do not hesitate to contact us |
|
22 |
* at info AT gvsig.com, or visit our website www.gvsig.com. |
|
23 |
*/ |
|
24 |
package org.gvsig.geotools.proj.lib; |
|
25 |
|
|
26 |
import org.gvsig.proj.CoordinateReferenceSystemLibrary; |
|
27 |
import org.gvsig.proj.CoordinateReferenceSystemLocator; |
|
28 |
import org.gvsig.tools.library.AbstractLibrary; |
|
29 |
import org.gvsig.tools.library.LibraryException; |
|
30 |
|
|
31 |
/** |
|
32 |
* Library to register the Geotools-based implementation of the |
|
33 |
* org.gvsig.proj API. |
|
34 |
* |
|
35 |
* @author Cesar Martinez Izquierdo |
|
36 |
*/ |
|
37 |
public class GtCRSLibrary extends AbstractLibrary { |
|
38 |
|
|
39 |
public GtCRSLibrary() { |
|
40 |
registerAsImplementationOf(CoordinateReferenceSystemLibrary.class); |
|
41 |
} |
|
42 |
|
|
43 |
@Override |
|
44 |
protected void doInitialize() throws LibraryException { |
|
45 |
CoordinateReferenceSystemLocator.registerManager(GtCRSManager.class); |
|
46 |
} |
|
47 |
|
|
48 |
@Override |
|
49 |
protected void doPostInitialize() throws LibraryException { |
|
50 |
// TODO Auto-generated method stub |
|
51 |
|
|
52 |
} |
|
53 |
|
|
54 |
} |
org.gvsig.geotools.proj/trunk/org.gvsig.geotools.proj/org.gvsig.geotools.proj.lib.impl/src/main/java/org/gvsig/geotools/proj/lib/DefaultTransformation.java | ||
---|---|---|
1 |
package org.gvsig.geotools.proj.lib; |
|
2 |
|
|
3 |
import java.text.ParseException; |
|
4 |
import java.util.HashSet; |
|
5 |
import java.util.Set; |
|
6 |
|
|
7 |
import org.geotools.referencing.wkt.Parser; |
|
8 |
import org.gvsig.geotools.proj.catalog.DefaultCRSDefinition; |
|
9 |
import org.gvsig.geotools.proj.catalog.DefaultTransformationDefinition; |
|
10 |
import org.gvsig.proj.CoordinateReferenceSystem; |
|
11 |
import org.gvsig.proj.CoordinateReferenceSystemLocator; |
|
12 |
import org.gvsig.proj.CoordinateTransformation; |
|
13 |
import org.gvsig.proj.catalog.CRSDefinition; |
|
14 |
import org.gvsig.proj.catalog.TextSerialization.Format; |
|
15 |
import org.gvsig.proj.catalog.TextSerialization.WKTConvention; |
|
16 |
import org.gvsig.proj.catalog.TransformationDefinition; |
|
17 |
import org.gvsig.proj.catalog.exception.NoninvertibleTransformException; |
|
18 |
import org.gvsig.proj.catalog.exception.TransformationException; |
|
19 |
import org.gvsig.proj.catalog.exception.UnsupportedCoordinateReferenceSystemException; |
|
20 |
import org.gvsig.proj.catalog.ref.Extent; |
|
21 |
import org.opengis.referencing.ReferenceIdentifier; |
|
22 |
import org.opengis.referencing.operation.CoordinateOperation; |
|
23 |
import org.opengis.referencing.operation.MathTransform; |
|
24 |
import org.opengis.referencing.operation.TransformException; |
|
25 |
import org.opengis.referencing.operation.Transformation; |
|
26 |
|
|
27 |
public class DefaultTransformation implements |
|
28 |
CoordinateTransformation { |
|
29 |
final protected CoordinateOperation operation; |
|
30 |
protected MathTransform mathTransform = null; |
|
31 |
protected DefaultCRS source = null; |
|
32 |
protected DefaultCRS target = null; |
|
33 |
final protected boolean inverse; |
|
34 |
final protected TransformationDefinition definition; |
|
35 |
|
|
36 |
public DefaultTransformation(CoordinateOperation operation, TransformationDefinition definition) { |
|
37 |
this.operation = operation; |
|
38 |
this.definition = definition; |
|
39 |
this.inverse = false; |
|
40 |
} |
|
41 |
|
|
42 |
public DefaultTransformation(DefaultTransformationDefinition definition) |
|
43 |
throws UnsupportedOperationException, ParseException { |
|
44 |
this.definition = definition; |
|
45 |
this.operation = definition.getInternalOperation(); |
|
46 |
this.inverse = false; |
|
47 |
} |
|
48 |
|
|
49 |
public DefaultTransformation(CoordinateOperation operation, TransformationDefinition definition, boolean inverse) { |
|
50 |
this.operation = operation; |
|
51 |
this.definition = definition; |
|
52 |
this.inverse = inverse; |
|
53 |
} |
|
54 |
|
|
55 |
public boolean isInverse() { |
|
56 |
return inverse; |
|
57 |
} |
|
58 |
|
|
59 |
@Override |
|
60 |
public CoordinateReferenceSystem getSourceCRS() { |
|
61 |
// FIXME: concurrency |
|
62 |
if (source==null) { |
|
63 |
if (inverse) { |
|
64 |
source = new DefaultCRS(operation.getTargetCRS(), getDefinition().getSourceDefinition()); |
|
65 |
} |
|
66 |
else { |
|
67 |
source = new DefaultCRS(operation.getSourceCRS(), getDefinition().getSourceDefinition()); |
|
68 |
} |
|
69 |
} |
|
70 |
return source; |
|
71 |
} |
|
72 |
|
|
73 |
@Override |
|
74 |
public CoordinateReferenceSystem getTargetCRS() { |
|
75 |
// FIXME: concurrency |
|
76 |
if (target==null) { |
|
77 |
if (inverse) { |
|
78 |
target = new DefaultCRS(operation.getSourceCRS(), getDefinition().getTargetDefinition()); |
|
79 |
} |
|
80 |
else { |
|
81 |
target = new DefaultCRS(operation.getTargetCRS(), getDefinition().getTargetDefinition()); |
|
82 |
} |
|
83 |
} |
|
84 |
return target; |
|
85 |
} |
|
86 |
|
|
87 |
@Override |
|
88 |
public void apply(double[] point) throws TransformationException { |
|
89 |
try { |
|
90 |
getMathTransform().transform(point, 0, point, 0, 1); |
|
91 |
} catch (TransformException e) { |
|
92 |
throw new TransformationException(getDefinition().getIdentifier(), e); |
|
93 |
|
|
94 |
} |
|
95 |
} |
|
96 |
|
|
97 |
@Override |
|
98 |
public void apply(double[] srcPoint, double[] dstPoint) throws TransformationException { |
|
99 |
try { |
|
100 |
getMathTransform().transform(srcPoint, 0, dstPoint, 0, 1); |
|
101 |
} catch (TransformException e) { |
|
102 |
throw new TransformationException(getDefinition().getIdentifier(), e); |
|
103 |
|
|
104 |
} |
|
105 |
} |
|
106 |
|
|
107 |
|
|
108 |
@Override |
|
109 |
public void apply(double[] srcPts, int srcOff, double[] dstPts, int dstOff, int numPts) throws TransformationException { |
|
110 |
try { |
|
111 |
getMathTransform().transform(srcPts, srcOff, dstPts, dstOff, numPts); |
|
112 |
} catch (TransformException e) { |
|
113 |
throw new TransformationException(getDefinition().getIdentifier(), e); |
|
114 |
} |
|
115 |
} |
|
116 |
|
|
117 |
protected MathTransform getMathTransform() throws TransformationException { |
|
118 |
try { |
|
119 |
if (mathTransform==null) { |
|
120 |
if (inverse) { |
|
121 |
mathTransform = operation.getMathTransform().inverse(); |
|
122 |
} |
|
123 |
else { |
|
124 |
mathTransform = operation.getMathTransform(); |
|
125 |
} |
|
126 |
} |
|
127 |
|
|
128 |
} catch (TransformException e) { |
|
129 |
throw new TransformationException(getDefinition().getIdentifier(), e); |
|
130 |
} |
|
131 |
return mathTransform; |
|
132 |
} |
|
133 |
|
|
134 |
@Override |
|
135 |
public CoordinateTransformation getInverse() throws NoninvertibleTransformException { |
|
136 |
if (inverse) { |
|
137 |
return new DefaultTransformation(this.operation, this.definition, false); |
|
138 |
} |
|
139 |
return new DefaultTransformation(this.operation, this.definition, true); |
|
140 |
} |
|
141 |
|
|
142 |
@Override |
|
143 |
public TransformationDefinition getDefinition() { |
|
144 |
return definition; |
|
145 |
} |
|
146 |
|
|
147 |
@Override |
|
148 |
public boolean isIdentity() throws TransformationException { |
|
149 |
return getMathTransform().isIdentity(); |
|
150 |
} |
|
151 |
|
|
152 |
@Override |
|
153 |
protected DefaultTransformation clone() throws CloneNotSupportedException { |
|
154 |
return new DefaultTransformation(this.operation, this.definition, this.inverse); |
|
155 |
} |
|
156 |
|
|
157 |
} |
org.gvsig.geotools.proj/trunk/org.gvsig.geotools.proj/org.gvsig.geotools.proj.lib.impl/src/main/java/org/gvsig/geotools/proj/lib/DefaultCRS.java | ||
---|---|---|
1 |
package org.gvsig.geotools.proj.lib; |
|
2 |
|
|
3 |
import javax.measure.Unit; |
|
4 |
import javax.measure.quantity.Length; |
|
5 |
|
|
6 |
import org.cresques.cts.CRSAdapter; |
|
7 |
import org.cresques.cts.IProjection; |
|
8 |
import org.gvsig.geotools.proj.catalog.DefaultCRSDefinition; |
|
9 |
import org.gvsig.geotools.proj.catalog.DefaultTransformationDefinition; |
|
10 |
import org.gvsig.geotools.proj.catalog.utils.DistanceCalculator; |
|
11 |
import org.gvsig.proj.catalog.CRSDefinition; |
|
12 |
import org.gvsig.proj.catalog.exception.CoordinateReferenceSystemException; |
|
13 |
import org.gvsig.proj.catalog.exception.TransformationException; |
|
14 |
import org.opengis.referencing.crs.CoordinateReferenceSystem; |
|
15 |
import org.opengis.referencing.crs.GeneralDerivedCRS; |
|
16 |
import org.opengis.referencing.crs.GeographicCRS; |
|
17 |
import org.opengis.referencing.crs.ProjectedCRS; |
|
18 |
import org.opengis.referencing.operation.CoordinateOperation; |
|
19 |
|
|
20 |
public class DefaultCRS implements org.gvsig.proj.CoordinateReferenceSystem { |
|
21 |
final private CoordinateReferenceSystem crs; |
|
22 |
final private CRSDefinition definition; |
|
23 |
|
|
24 |
public DefaultCRS(DefaultCRSDefinition definition) { |
|
25 |
this.definition = definition; |
|
26 |
this.crs = definition.getInternalCRS(); |
|
27 |
} |
|
28 |
|
|
29 |
/* |
|
30 |
public DefaultCRS(CoordinateReferenceSystem crs) |
|
31 |
throws UnsupportedCoordinateReferenceSystemException { |
|
32 |
this.crs = crs; |
|
33 |
GtCoordinateReferenceSystemManager manager = (GtCoordinateReferenceSystemManager) CoordinateReferenceSystemLocator.getManager(); |
|
34 |
try { |
|
35 |
// FIXME: crs.toString? crs.toWKT? |
|
36 |
this.definition = manager.getCatalogManager().parseCRSDefinition(crs.toString()); |
|
37 |
} catch (ParseException e) { |
|
38 |
throw new UnsupportedCoordinateReferenceSystemException(e); |
|
39 |
} |
|
40 |
}*/ |
|
41 |
|
|
42 |
DefaultCRS(CoordinateReferenceSystem crs, CRSDefinition definition) { |
|
43 |
this.crs = crs; |
|
44 |
this.definition = definition; |
|
45 |
} |
|
46 |
|
|
47 |
CoordinateReferenceSystem getInternalCRS() { |
|
48 |
return crs; |
|
49 |
} |
|
50 |
|
|
51 |
@Override |
|
52 |
public boolean isProjected() { |
|
53 |
return (crs instanceof ProjectedCRS |
|
54 |
|| (crs instanceof GeneralDerivedCRS && |
|
55 |
((GeneralDerivedCRS)crs).getBaseCRS() instanceof ProjectedCRS)); |
|
56 |
} |
|
57 |
|
|
58 |
|
|
59 |
@Override |
|
60 |
public boolean isGeographic() { |
|
61 |
return (crs instanceof GeographicCRS |
|
62 |
|| (crs instanceof GeneralDerivedCRS && |
|
63 |
((GeneralDerivedCRS)crs).getBaseCRS() instanceof GeographicCRS)); |
|
64 |
} |
|
65 |
|
|
66 |
@Override |
|
67 |
public double[] toGeo(double[] point) throws TransformationException { |
|
68 |
if (isProjected()) { |
|
69 |
double[] transformedPoint = new double[point.length]; |
|
70 |
// FIXME: cache toGeoTransform? |
|
71 |
CoordinateOperation toGeo = ((GeneralDerivedCRS)crs).getConversionFromBase(); |
|
72 |
DefaultTransformationDefinition toGeoTransform = new DefaultTransformationDefinition(toGeo, true); |
|
73 |
toGeoTransform.apply(point, transformedPoint); |
|
74 |
return point; |
|
75 |
} |
|
76 |
if (isGeographic()) { |
|
77 |
return point; |
|
78 |
} |
|
79 |
throw new TransformationException(); |
|
80 |
} |
|
81 |
|
|
82 |
@Override |
|
83 |
public double getDistance(double[] point1, double[] point2, Unit<Length> targetUnit) throws CoordinateReferenceSystemException { |
|
84 |
return DistanceCalculator.getDistance(this.crs, point1, point2, true, targetUnit); |
|
85 |
} |
|
86 |
|
|
87 |
@Override |
|
88 |
public double getDistance(double[] point1, double[] point2, boolean useBaseCRS, Unit<Length> targetUnit) throws CoordinateReferenceSystemException { |
|
89 |
return DistanceCalculator.getDistance(this.crs, point1, point2, useBaseCRS, targetUnit); |
|
90 |
} |
|
91 |
|
|
92 |
@Override |
|
93 |
public CRSDefinition getDefinition() { |
|
94 |
return definition; |
|
95 |
} |
|
96 |
|
|
97 |
@Override |
|
98 |
public DefaultCRS clone() throws CloneNotSupportedException { |
|
99 |
return new DefaultCRS(this.crs, this.definition); |
|
100 |
} |
|
101 |
|
|
102 |
@Override |
|
103 |
public IProjection getIProjection() { |
|
104 |
return new CRSAdapter(this); |
|
105 |
} |
|
106 |
} |
org.gvsig.geotools.proj/trunk/org.gvsig.geotools.proj/org.gvsig.geotools.proj.lib.impl/src/main/java/org/gvsig/geotools/proj/lib/GtCRSManager.java | ||
---|---|---|
1 |
package org.gvsig.geotools.proj.lib; |
|
2 |
|
|
3 |
import java.text.ParseException; |
|
4 |
|
|
5 |
import org.geotools.referencing.CRS; |
|
6 |
import org.geotools.referencing.wkt.Parser; |
|
7 |
import org.gvsig.geotools.proj.catalog.DefaultCRSDefinition; |
|
8 |
import org.gvsig.geotools.proj.catalog.DefaultTransformationDefinition; |
|
9 |
import org.gvsig.proj.CoordinateReferenceSystem; |
|
10 |
import org.gvsig.proj.CoordinateReferenceSystemLocator; |
|
11 |
import org.gvsig.proj.CoordinateReferenceSystemManager; |
|
12 |
import org.gvsig.proj.CoordinateTransformation; |
|
13 |
import org.gvsig.proj.catalog.CRSCatalogLocator; |
|
14 |
import org.gvsig.proj.catalog.CRSCatalogManager; |
|
15 |
import org.gvsig.proj.catalog.CRSDefinition; |
|
16 |
import org.gvsig.proj.catalog.TextSerialization.Format; |
|
17 |
import org.gvsig.proj.catalog.TransformationDefinition; |
|
18 |
import org.gvsig.proj.catalog.exception.UnsupportedTransformationException; |
|
19 |
import org.opengis.referencing.FactoryException; |
|
20 |
import org.opengis.referencing.operation.CoordinateOperation; |
|
21 |
import org.gvsig.proj.catalog.exception.UnsupportedCoordinateReferenceSystemException; |
|
22 |
import org.gvsig.proj.catalog.exception.UnsupportedFormatException; |
|
23 |
|
|
24 |
public class GtCRSManager implements CoordinateReferenceSystemManager { |
|
25 |
private CRSCatalogManager catalogManager = null; |
|
26 |
|
|
27 |
public GtCRSManager() { |
|
28 |
} |
|
29 |
|
|
30 |
@Override |
|
31 |
public CoordinateReferenceSystem getCoordinateReferenceSystem(CRSDefinition definition) |
|
32 |
throws UnsupportedCoordinateReferenceSystemException, |
|
33 |
ParseException { |
|
34 |
if (definition instanceof DefaultCRSDefinition) { |
|
35 |
return new DefaultCRS((DefaultCRSDefinition)definition); |
|
36 |
} |
|
37 |
else { |
|
38 |
// FIXME: definition.toString? definition.toWKT? definition.export? |
|
39 |
return getCoordinateReferenceSystem(definition, definition.toWKT()); |
|
40 |
} |
|
41 |
} |
|
42 |
|
|
43 |
/** |
|
44 |
* Used for CRSDefinition that are not instanceof DefaultCRSDefinition |
|
45 |
* |
|
46 |
* @param definition |
|
47 |
* @param wktDefinition |
|
48 |
* @return |
|
49 |
* @throws UnsupportedCoordinateReferenceSystemException |
|
50 |
*/ |
|
51 |
protected CoordinateReferenceSystem getCoordinateReferenceSystem(CRSDefinition definition, String wktDefinition) throws UnsupportedCoordinateReferenceSystemException { |
|
52 |
|
|
53 |
try { |
|
54 |
org.opengis.referencing.crs.CoordinateReferenceSystem crs = CRS.parseWKT(wktDefinition); |
|
55 |
return new DefaultCRS(crs, definition); |
|
56 |
} catch (FactoryException e) { |
|
57 |
throw new UnsupportedCoordinateReferenceSystemException(e); |
|
58 |
} |
|
59 |
} |
|
60 |
|
|
61 |
@Override |
|
62 |
public CoordinateReferenceSystem parseCoordinateReferenceSystem(String def) |
|
63 |
throws UnsupportedCoordinateReferenceSystemException, ParseException { |
|
64 |
CRSDefinition definition = getCatalogManager().parseCRSDefinition(def); |
|
65 |
if (definition instanceof DefaultCRSDefinition) { |
|
66 |
return new DefaultCRS((DefaultCRSDefinition)definition); |
|
67 |
} |
|
68 |
return getCoordinateReferenceSystem(definition, def); |
|
69 |
} |
|
70 |
|
|
71 |
@Override |
|
72 |
public CoordinateReferenceSystem parseCoordinateReferenceSystem(String def, Format format) |
|
73 |
throws UnsupportedCoordinateReferenceSystemException, |
|
74 |
ParseException, UnsupportedFormatException { |
|
75 |
if (format==Format.WKT1) { |
|
76 |
parseCoordinateReferenceSystem(def); |
|
77 |
} |
|
78 |
throw new UnsupportedFormatException(format); |
|
79 |
} |
|
80 |
|
|
81 |
@Override |
|
82 |
public CoordinateTransformation parseCoordinateTransformation(String wkt) |
|
83 |
throws UnsupportedTransformationException, ParseException { |
|
84 |
TransformationDefinition definition = getCatalogManager().parseTransformationDefinition(wkt); |
|
85 |
if (definition instanceof DefaultTransformationDefinition) { |
|
86 |
// FIXME: We should some way decide whether the direct or inverse transformation has to be used. |
|
87 |
// It is a bit tricky since we don't provide different abstractions for CoordinateOperation and MathTransform |
|
88 |
return new DefaultTransformation((DefaultTransformationDefinition)definition); |
|
89 |
} |
|
90 |
return getCoordinateTransformation(definition, wkt); |
|
91 |
} |
|
92 |
|
|
93 |
|
|
94 |
@Override |
|
95 |
public CoordinateTransformation parseCoordinateTransformation(String def, Format format) |
|
96 |
throws UnsupportedTransformationException, |
|
97 |
ParseException, UnsupportedFormatException { |
|
98 |
if (format==Format.WKT1) { |
|
99 |
return parseCoordinateTransformation(def); |
|
100 |
} |
|
101 |
throw new UnsupportedFormatException(format); |
|
102 |
} |
|
103 |
|
|
104 |
/** |
|
105 |
* Used for TransformationDefinition that are not instanceof DefaultTransformationDefinition |
|
106 |
* |
|
107 |
* @param definition |
|
108 |
* @param wktDefinition |
|
109 |
* @return |
|
110 |
* @throws UnsupportedTransformationException |
|
111 |
*/ |
|
112 |
protected CoordinateTransformation getCoordinateTransformation(TransformationDefinition definition, String wktDef) |
|
113 |
throws UnsupportedTransformationException, ParseException { |
|
114 |
// FIXME: We should some way decide whether the direct or inverse transformation has to be used. |
|
115 |
// It is a bit tricky since we don't provide different abstractions for CoordinateOperation and MathTransform |
|
116 |
Parser parser = new Parser(); |
|
117 |
Object obj = parser.parseObject(wktDef); |
|
118 |
return new DefaultTransformation((CoordinateOperation) obj, definition); |
|
119 |
} |
|
120 |
|
|
121 |
@Override |
|
122 |
public CoordinateTransformation getCoordinateTransformation(TransformationDefinition definition) |
|
123 |
throws UnsupportedTransformationException, ParseException { |
|
124 |
if (definition instanceof DefaultTransformationDefinition) { |
|
125 |
// FIXME: We should some way decide whether the direct or inverse transformation has to be used. |
|
126 |
// It is a bit tricky since we don't provide different abstractions for CoordinateOperation and MathTransform |
|
127 |
return new DefaultTransformation((DefaultTransformationDefinition)definition); |
|
128 |
} |
|
129 |
return getCoordinateTransformation(definition, definition.toWKT()); |
|
130 |
} |
|
131 |
|
|
132 |
@Override |
|
133 |
public void setCatalogManager(CRSCatalogManager manager) { |
|
134 |
this.catalogManager = manager; |
|
135 |
} |
|
136 |
|
|
137 |
public CRSCatalogManager getCatalogManager() { |
|
138 |
if( this.catalogManager == null ) { |
|
139 |
this.catalogManager = CRSCatalogLocator.getManager(); |
|
140 |
} |
|
141 |
return this.catalogManager; |
|
142 |
} |
|
143 |
} |
org.gvsig.geotools.proj/trunk/org.gvsig.geotools.proj/org.gvsig.geotools.proj.catalog.impl/src/main/resources/META-INF/services/org.gvsig.tools.library.Library | ||
---|---|---|
1 |
org.gvsig.geotools.proj.catalog.GtCrsCatalogLibrary |
|
1 |
org.gvsig.geotools.proj.catalog.GtCRSCatalogLibrary |
org.gvsig.geotools.proj/trunk/org.gvsig.geotools.proj/org.gvsig.geotools.proj.catalog.impl/src/main/java/org/gvsig/geotools/proj/catalog/DefaultTransformation.java | ||
---|---|---|
1 |
package org.gvsig.geotools.proj.catalog; |
|
2 |
|
|
3 |
import java.text.ParseException; |
|
4 |
import java.util.HashSet; |
|
5 |
import java.util.Set; |
|
6 |
|
|
7 |
import org.geotools.referencing.wkt.Parser; |
|
8 |
import org.gvsig.proj.CoordinateReferenceSystem; |
|
9 |
import org.gvsig.proj.CoordinateTransformation; |
|
10 |
import org.gvsig.proj.catalog.CRSDefinition; |
|
11 |
import org.gvsig.proj.catalog.TextSerialization.Format; |
|
12 |
import org.gvsig.proj.catalog.TextSerialization.WKTConvention; |
|
13 |
import org.gvsig.proj.catalog.TransformationDefinition; |
|
14 |
import org.gvsig.proj.catalog.exception.NoninvertibleTransformException; |
|
15 |
import org.gvsig.proj.catalog.exception.TransformationException; |
|
16 |
import org.gvsig.proj.catalog.ref.Extent; |
|
17 |
import org.opengis.referencing.ReferenceIdentifier; |
|
18 |
import org.opengis.referencing.operation.CoordinateOperation; |
|
19 |
import org.opengis.referencing.operation.MathTransform; |
|
20 |
import org.opengis.referencing.operation.TransformException; |
|
21 |
import org.opengis.referencing.operation.Transformation; |
|
22 |
|
|
23 |
public class DefaultTransformation implements TransformationDefinition, |
|
24 |
CoordinateTransformation { |
|
25 |
private CoordinateOperation operation = null; |
|
26 |
private String wkt = null; |
|
27 |
private MathTransform mathTransform = null; |
|
28 |
private DefaultCRS source = null; |
|
29 |
private DefaultCRS target = null; |
|
30 |
boolean inverse = false; |
|
31 |
|
|
32 |
public DefaultTransformation(CoordinateOperation operation) { |
|
33 |
this.operation = operation; |
|
34 |
} |
|
35 |
|
|
36 |
public DefaultTransformation(CoordinateOperation operation, boolean inverse) throws NoninvertibleTransformException { |
|
37 |
this.operation = operation; |
|
38 |
try { |
|
39 |
operation.getMathTransform().inverse(); |
|
40 |
} |
|
41 |
catch (org.opengis.referencing.operation.NoninvertibleTransformException e) { |
|
42 |
throw new NoninvertibleTransformException(operation.getName().getCode()); |
|
43 |
} |
|
44 |
this.inverse = inverse; |
|
45 |
} |
|
46 |
|
|
47 |
|
|
48 |
public DefaultTransformation(String wkt) throws ParseException { |
|
49 |
this.wkt = wkt; |
|
50 |
Parser parser = new Parser(); |
|
51 |
Object obj = parser.parseObject(wkt); |
|
52 |
this.operation = (CoordinateOperation) obj; |
|
53 |
} |
|
54 |
|
|
55 |
@Override |
|
56 |
public CRSDefinition getSourceDefinition() { |
|
57 |
if (source==null) { |
|
58 |
if (inverse) { |
|
59 |
source = new DefaultCRS(operation.getTargetCRS()); |
|
60 |
} |
|
61 |
else { |
|
62 |
source = new DefaultCRS(operation.getSourceCRS()); |
|
63 |
} |
|
64 |
} |
|
65 |
return source; |
|
66 |
} |
|
67 |
|
|
68 |
@Override |
|
69 |
public CRSDefinition getTargetDefinition() { |
|
70 |
if (target==null) { |
|
71 |
if (inverse) { |
|
72 |
target = new DefaultCRS(operation.getSourceCRS()); |
|
73 |
} |
|
74 |
else { |
|
75 |
target = new DefaultCRS(operation.getTargetCRS()); |
|
76 |
} |
|
77 |
} |
|
78 |
return target; |
|
79 |
} |
|
80 |
|
|
81 |
@Override |
|
82 |
public String getName() { |
|
83 |
// FIXME: compare with identifier |
|
84 |
return operation.getName().toString(); |
|
85 |
} |
|
86 |
|
|
87 |
@Override |
|
88 |
public String getIdentifier() { |
|
89 |
// FIXME: compare with name |
|
90 |
Set<ReferenceIdentifier> ids = operation.getIdentifiers(); |
|
91 |
for (ReferenceIdentifier id: ids) { |
|
92 |
String fullCode = id.toString(); |
|
93 |
String code = id.getCode(); |
|
94 |
} |
|
95 |
return operation.getName().toString(); |
|
96 |
} |
|
97 |
|
|
98 |
@Override |
|
99 |
public Set<String> getIdentifiers() { |
|
100 |
HashSet<String> ids = new HashSet<String>(); |
|
101 |
for (ReferenceIdentifier id: operation.getIdentifiers()) { |
|
102 |
ids.add(id.toString()); |
|
103 |
} |
|
104 |
return ids; |
|
105 |
} |
|
106 |
|
|
107 |
@Override |
|
108 |
public String getAuthorityName() { |
|
109 |
return operation.getName().getAuthority().getTitle().toString(); |
|
110 |
} |
|
111 |
|
|
112 |
@Override |
|
113 |
public String getOperationVersion() { |
|
114 |
return operation.getOperationVersion(); |
|
115 |
} |
|
116 |
|
|
117 |
@Override |
|
118 |
public Extent getDomainOfValidity() { |
|
119 |
// TODO Auto-generated method stub |
|
120 |
return null; |
|
121 |
} |
|
122 |
|
|
123 |
@Override |
|
124 |
public String getDescription() { |
|
125 |
return operation.getScope() + "\nRemarks: " + operation.getRemarks(); |
|
126 |
} |
|
127 |
|
|
128 |
@Override |
|
129 |
public boolean isTransformation() { |
|
130 |
return (operation instanceof Transformation); |
|
131 |
} |
|
132 |
|
|
133 |
@Override |
|
134 |
public TransformationDefinition getInverseDefinition() throws NoninvertibleTransformException { |
|
135 |
return new DefaultTransformation(this.operation, true); |
|
136 |
} |
|
137 |
|
|
138 |
@Override |
|
139 |
public String toWKT() throws UnsupportedOperationException { |
|
140 |
// TODO Auto-generated method stub |
|
141 |
// FIXME: review inverse transformation to be correctly stored as wkt |
|
142 |
// FIXME: think if we should convert to WKT the operation or the mathTransform |
|
143 |
// MathTransforms seem to be the only option that ensures the transformation can be recreated |
|
144 |
// But... source and target crs will be lost!! |
|
145 |
if (wkt!=null) { |
|
146 |
return wkt; |
|
147 |
} |
|
148 |
return operation.toWKT(); |
|
149 |
} |
|
150 |
|
|
151 |
|
|
152 |
@Override |
|
153 |
public String toString(Format format, WKTConvention convention) throws UnsupportedOperationException { |
|
154 |
// TODO Auto-generated method stub |
|
155 |
return null; |
|
156 |
} |
|
157 |
|
|
158 |
@Override |
|
159 |
public String toString(Format format, WKTConvention convention, int indentation) |
|
160 |
throws UnsupportedOperationException { |
|
161 |
// TODO Auto-generated method stub |
|
162 |
return null; |
|
163 |
} |
|
164 |
|
|
165 |
public boolean isInverse() { |
|
166 |
return inverse; |
|
167 |
} |
|
168 |
|
|
169 |
@Override |
|
170 |
public CoordinateReferenceSystem getSourceCRS() { |
|
171 |
return (CoordinateReferenceSystem) getSourceDefinition(); |
|
172 |
} |
|
173 |
|
|
174 |
@Override |
|
175 |
public CoordinateReferenceSystem getTargetCRS() { |
|
176 |
return (CoordinateReferenceSystem) getTargetDefinition(); |
|
177 |
} |
|
178 |
|
|
179 |
@Override |
|
180 |
public void apply(double[] point) throws TransformationException { |
|
181 |
try { |
|
182 |
getMathTransform().transform(point, 0, point, 0, 1); |
|
183 |
} catch (TransformException e) { |
|
184 |
throw new TransformationException(getIdentifier(), e); |
|
185 |
|
|
186 |
} |
|
187 |
} |
|
188 |
|
|
189 |
@Override |
|
190 |
public void apply(double[] srcPoint, double[] dstPoint) throws TransformationException { |
|
191 |
try { |
|
192 |
getMathTransform().transform(srcPoint, 0, dstPoint, 0, 1); |
|
193 |
} catch (TransformException e) { |
|
194 |
throw new TransformationException(getIdentifier(), e); |
|
195 |
|
|
196 |
} |
|
197 |
} |
|
198 |
|
|
199 |
|
|
200 |
@Override |
|
201 |
public void apply(double[] srcPts, int srcOff, double[] dstPts, int dstOff, int numPts) throws TransformationException { |
|
202 |
try { |
|
203 |
getMathTransform().transform(srcPts, srcOff, dstPts, dstOff, numPts); |
|
204 |
} catch (TransformException e) { |
|
205 |
throw new TransformationException(getIdentifier(), e); |
|
206 |
} |
|
207 |
} |
|
208 |
|
|
209 |
protected MathTransform getMathTransform() throws TransformationException { |
|
210 |
try { |
|
211 |
if (mathTransform==null) { |
|
212 |
if (inverse) { |
|
213 |
mathTransform = operation.getMathTransform().inverse(); |
|
214 |
} |
|
215 |
else { |
|
216 |
mathTransform = operation.getMathTransform(); |
|
217 |
} |
|
218 |
} |
|
219 |
|
|
220 |
} catch (TransformException e) { |
|
221 |
throw new TransformationException(getIdentifier(), e); |
|
222 |
} |
|
223 |
return mathTransform; |
|
224 |
} |
|
225 |
|
|
226 |
@Override |
|
227 |
public CoordinateTransformation getInverse() throws NoninvertibleTransformException { |
|
228 |
if (inverse) { |
|
229 |
return new DefaultTransformation(this.operation); |
|
230 |
} |
|
231 |
return new DefaultTransformation(this.operation, true); |
|
232 |
} |
|
233 |
|
|
234 |
@Override |
|
235 |
public TransformationDefinition getDefinition() { |
|
236 |
return this; |
|
237 |
} |
|
238 |
|
|
239 |
@Override |
|
240 |
public boolean isIdentity() throws TransformationException { |
|
241 |
return getMathTransform().isIdentity(); |
|
242 |
} |
|
243 |
|
|
244 |
} |
org.gvsig.geotools.proj/trunk/org.gvsig.geotools.proj/org.gvsig.geotools.proj.catalog.impl/src/main/java/org/gvsig/geotools/proj/catalog/DefaultCRS.java | ||
---|---|---|
1 |
package org.gvsig.geotools.proj.catalog; |
|
2 |
|
|
3 |
import java.util.ArrayList; |
|
4 |
import java.util.HashSet; |
|
5 |
import java.util.List; |
|
6 |
import java.util.Set; |
|
7 |
|
|
8 |
import javax.measure.Unit; |
|
9 |
import javax.measure.quantity.Length; |
|
10 |
|
|
11 |
import org.geotools.metadata.iso.citation.Citations; |
|
12 |
import org.geotools.referencing.CRS; |
|
13 |
import org.geotools.referencing.ReferencingFactoryFinder; |
|
14 |
import org.geotools.referencing.wkt.Formatter; |
|
15 |
import org.geotools.referencing.wkt.Symbols; |
|
16 |
import org.gvsig.geotools.proj.catalog.datum.DefaultDatum; |
|
17 |
import org.gvsig.geotools.proj.catalog.utils.IdentifiedObjectUtils; |
|
18 |
import org.gvsig.proj.catalog.CRSCatalogLocator; |
|
19 |
import org.gvsig.proj.catalog.CRSDefinition; |
|
20 |
import org.gvsig.proj.catalog.CRSType; |
|
21 |
import org.gvsig.proj.catalog.CoordinateSystemAxis; |
|
22 |
import org.gvsig.proj.catalog.TextSerialization; |
|
23 |
import org.gvsig.proj.catalog.TextSerialization.Format; |
|
24 |
import org.gvsig.proj.catalog.TextSerialization.WKTConvention; |
|
25 |
import org.gvsig.proj.catalog.TransformationDefinition; |
|
26 |
import org.gvsig.proj.catalog.datum.Datum; |
|
27 |
import org.gvsig.proj.catalog.exception.UnsupportedCoordinateReferenceSystemException; |
|
28 |
import org.gvsig.proj.catalog.ref.Extent; |
|
29 |
import org.opengis.metadata.Identifier; |
|
30 |
import org.opengis.referencing.FactoryException; |
|
31 |
import org.opengis.referencing.ReferenceIdentifier; |
|
32 |
import org.opengis.referencing.crs.CompoundCRS; |
|
33 |
import org.opengis.referencing.crs.CoordinateReferenceSystem; |
|
34 |
import org.opengis.referencing.crs.GeneralDerivedCRS; |
|
35 |
import org.opengis.referencing.crs.GeocentricCRS; |
|
36 |
import org.opengis.referencing.crs.GeographicCRS; |
|
37 |
import org.opengis.referencing.crs.ProjectedCRS; |
|
38 |
import org.opengis.referencing.crs.SingleCRS; |
|
39 |
import org.opengis.referencing.crs.TemporalCRS; |
|
40 |
import org.opengis.referencing.crs.VerticalCRS; |
|
41 |
import org.opengis.referencing.operation.Conversion; |
|
42 |
|
|
43 |
public class DefaultCRS implements CRSDefinition, org.gvsig.proj.CoordinateReferenceSystem { |
|
44 |
private CoordinateReferenceSystem origCrs = null; |
|
45 |
private CoordinateReferenceSystem epsgCrs = null; |
|
46 |
private String wkt = null; |
|
47 |
|
|
48 |
public DefaultCRS(String wktDefinition) { |
|
49 |
this.wkt = wktDefinition; |
|
50 |
try { |
|
51 |
this.origCrs = CRS.parseWKT(wktDefinition); |
|
52 |
} catch (FactoryException e) { |
|
53 |
// TODO Auto-generated catch block |
|
54 |
e.printStackTrace(); |
|
55 |
} |
|
56 |
} |
|
57 |
|
|
58 |
public DefaultCRS(CoordinateReferenceSystem crs) { |
|
59 |
this.origCrs = crs; |
|
60 |
} |
|
61 |
|
|
62 |
CoordinateReferenceSystem getInternalCRS() { |
|
63 |
return origCrs; |
|
64 |
} |
|
65 |
|
|
66 |
@Override |
|
67 |
public String getName() { |
|
68 |
return origCrs.getName().toString(); |
|
69 |
} |
|
70 |
|
|
71 |
@Override |
|
72 |
public String getIdentifier() { |
|
73 |
String id = IdentifiedObjectUtils.getIdentifier(origCrs); |
|
74 |
if (id!=null) { |
|
75 |
return id; |
|
76 |
} |
|
77 |
// FIXME: define in API whether null is allowed |
|
78 |
return IdentifiedObjectUtils.getIdentifier(getEpsgCrs()); |
|
79 |
} |
|
80 |
|
|
81 |
/** |
|
82 |
* Gets an EPSG code which can be considered equivalent to this CRS or |
|
83 |
* null if not found |
|
84 |
* @return |
|
85 |
*/ |
|
86 |
protected CoordinateReferenceSystem getEpsgCrs() { |
|
87 |
if (epsgCrs==null) { |
|
88 |
try { |
|
89 |
String code = CRS.lookupIdentifier(Citations.EPSG, origCrs, true); |
|
90 |
if (code!=null) { |
|
91 |
epsgCrs = CRS.decode(code); |
|
92 |
} |
|
93 |
} |
|
94 |
catch (FactoryException exc) {} |
|
95 |
} |
|
96 |
return epsgCrs; |
|
97 |
} |
|
98 |
|
|
99 |
@Override |
|
100 |
public Set<String> getIdentifiers() { |
|
101 |
HashSet<String> ids = new HashSet<String>(); |
|
102 |
for (ReferenceIdentifier id: origCrs.getIdentifiers()) { |
|
103 |
ids.add(id.toString()); |
|
104 |
} |
|
105 |
return ids; |
|
106 |
} |
|
107 |
|
|
108 |
@Override |
|
109 |
public String getAuthorityName() { |
|
110 |
for (Identifier id: origCrs.getName().getAuthority().getIdentifiers()) { |
|
111 |
return id.getCode(); |
|
112 |
} |
|
113 |
return null; // FIXME: define in API whether null is allowed |
|
114 |
} |
|
115 |
|
|
116 |
@Override |
|
117 |
public Extent getDomainOfValidity() { |
|
118 |
// TODO Auto-generated method stub |
|
119 |
return null; |
|
120 |
} |
|
121 |
|
|
122 |
@Override |
|
123 |
public String getDescription() { |
|
124 |
return origCrs.getScope() + "\nRemarks: " + origCrs.getRemarks(); |
|
125 |
} |
|
126 |
|
|
127 |
@Override |
|
128 |
public boolean isProjected() { |
|
129 |
return (origCrs instanceof ProjectedCRS); |
|
130 |
} |
|
131 |
|
|
132 |
@Override |
|
133 |
public CRSType getType() { |
|
134 |
if (origCrs instanceof ProjectedCRS) { |
|
135 |
return CRSType.ProjectedCRSType; |
|
136 |
} |
|
137 |
if (origCrs instanceof GeographicCRS) { |
|
138 |
return CRSType.GeographicCRSType; |
|
139 |
} |
|
140 |
if (origCrs instanceof GeocentricCRS) { |
|
141 |
return CRSType.GeocentricCRSType; |
|
142 |
} |
|
143 |
if (origCrs instanceof GeneralDerivedCRS) { |
|
144 |
return CRSType.OtherDerivedCRSType; |
|
145 |
} |
|
146 |
if (origCrs instanceof CompoundCRS) { |
|
147 |
return CRSType.CompoundCRSType; |
|
148 |
} |
|
149 |
if (origCrs instanceof VerticalCRS) { |
|
150 |
return CRSType.VerticalCRSType; |
|
151 |
} |
|
152 |
if (origCrs instanceof TemporalCRS) { |
|
153 |
return CRSType.TemporalCRSType; |
|
154 |
} |
|
155 |
return CRSType.OtherCRSType; |
|
156 |
} |
|
157 |
|
|
158 |
@Override |
|
159 |
public String toWKT() throws UnsupportedOperationException { |
|
160 |
if (wkt!=null) { |
|
161 |
return wkt; |
|
162 |
} |
|
163 |
return origCrs.toWKT(); |
|
164 |
} |
|
165 |
|
|
166 |
|
|
167 |
@Override |
|
168 |
public String toString(Format format, WKTConvention convention) throws UnsupportedOperationException { |
|
169 |
return toString(format, convention, 0); |
|
170 |
} |
|
171 |
|
|
172 |
@Override |
|
173 |
public String toString(TextSerialization.Format format, WKTConvention convention, int indentation) throws UnsupportedOperationException { |
|
174 |
if (format==Format.WKT1) { |
|
175 |
if (convention==WKTConvention.EPSG) { |
|
176 |
Formatter formatter = new Formatter(Symbols.DEFAULT, indentation); |
|
177 |
formatter.setAuthority(Citations.EPSG); |
|
178 |
if (!this.getAuthorityName().equals("EPSG")) { |
|
179 |
String id; |
|
180 |
try { |
|
181 |
id = CRS.lookupIdentifier(Citations.EPSG, this.origCrs, true); |
|
182 |
if (id!=null) { |
|
183 |
if (!id.startsWith("EPSG:")) { |
|
184 |
id = "EPSG:" + id; |
|
185 |
} |
|
186 |
CoordinateReferenceSystem crs = CRS.decode(id); |
|
187 |
formatter.append(crs); |
|
188 |
return formatter.toString(); |
|
189 |
} |
|
190 |
} catch (FactoryException e) { |
|
191 |
} |
|
192 |
} |
|
193 |
formatter.append(this.origCrs); |
|
194 |
return formatter.toString(); |
|
195 |
} |
|
196 |
if (convention==WKTConvention.ESRI) { |
|
197 |
// FIXME: should we consider this.wkt if it is not null?? |
|
198 |
Formatter formatter = new Formatter(Symbols.DEFAULT, indentation); |
|
199 |
formatter.setAuthority(Citations.ESRI); |
|
200 |
formatter.append(this.origCrs); |
|
201 |
return formatter.toString(); |
|
202 |
} |
|
203 |
return toWKT(); |
|
204 |
} |
|
205 |
throw new UnsupportedOperationException("Format not supported"); |
|
206 |
} |
|
207 |
|
|
208 |
|
|
209 |
@Override |
|
210 |
public List<CRSDefinition> getComponents() { |
|
211 |
if (origCrs instanceof CompoundCRS) { |
|
212 |
ArrayList<CRSDefinition> list = new ArrayList<CRSDefinition>(); |
|
213 |
for (CoordinateReferenceSystem component: ((CompoundCRS) origCrs).getCoordinateReferenceSystems()) { |
|
214 |
list.add(new DefaultCRS(component)); |
|
215 |
} |
|
216 |
return list; |
|
217 |
} |
|
218 |
return null; |
|
219 |
} |
|
220 |
|
|
221 |
@Override |
|
222 |
public int getAxisCount() { |
|
223 |
return origCrs.getCoordinateSystem().getDimension(); |
|
224 |
} |
|
225 |
|
|
226 |
@Override |
|
227 |
public CoordinateSystemAxis getAxis(int dimension) throws IndexOutOfBoundsException { |
|
228 |
return new DefaultCoordinateSystemAxis(origCrs.getCoordinateSystem().getAxis(dimension)); |
|
229 |
} |
|
230 |
|
|
231 |
@Override |
|
232 |
public CoordinateSystemAxis getAxisInternal(int dimension) throws IndexOutOfBoundsException { |
|
233 |
// TODO Auto-generated method stub |
|
234 |
return null; |
|
235 |
} |
|
236 |
|
|
237 |
@Override |
|
238 |
public CRSDefinition getBaseCRS() { |
|
239 |
if (origCrs instanceof GeneralDerivedCRS) { |
|
240 |
CoordinateReferenceSystem base = ((GeneralDerivedCRS)origCrs).getBaseCRS(); |
|
241 |
return new DefaultCRS(base); |
|
242 |
} |
|
243 |
return null; |
|
244 |
} |
|
245 |
|
|
246 |
@Override |
|
247 |
public TransformationDefinition getConversionFromBase() { |
|
248 |
if (origCrs instanceof GeneralDerivedCRS) { |
|
249 |
Conversion conversion = ((GeneralDerivedCRS)origCrs).getConversionFromBase(); |
|
250 |
return new DefaultTransformation(conversion); |
|
251 |
} |
|
252 |
return null; |
|
253 |
} |
|
254 |
|
|
255 |
@Override |
|
256 |
public Datum getDatum() { |
|
257 |
if (origCrs instanceof SingleCRS) { |
|
258 |
SingleCRS singleCrs = (SingleCRS)origCrs; |
|
259 |
return new DefaultDatum(singleCrs.getDatum()); |
|
260 |
} |
|
261 |
else { |
|
262 |
SingleCRS horizontalCrs = CRS.getHorizontalCRS(origCrs); |
|
263 |
return new DefaultDatum(horizontalCrs.getDatum()); |
|
264 |
} |
|
265 |
} |
|
266 |
@Override |
|
267 |
public double getDistance(double[] point1, double[] point2, Unit<Length> unit) { |
|
268 |
// TODO Auto-generated method stub |
|
269 |
return 0; |
|
270 |
} |
|
271 |
|
|
272 |
@Override |
|
273 |
public double getDistance(double[] point1, double[] point2, boolean useBaseCRS, Unit<Length> unit) { |
|
274 |
// TODO Auto-generated method stub |
|
275 |
return 0; |
|
276 |
} |
|
277 |
|
|
278 |
@Override |
|
279 |
public CRSDefinition getDefinition() |
|
280 |
throws UnsupportedCoordinateReferenceSystemException, UnsupportedOperationException { |
|
281 |
return this; |
|
282 |
} |
|
283 |
|
|
284 |
@Override |
|
285 |
public Object clone() throws CloneNotSupportedException { |
|
286 |
return new DefaultCRS(this.origCrs); |
|
287 |
} |
|
288 |
|
|
289 |
@Override |
|
290 |
public boolean equals(CRSDefinition definition, boolean ignoreAxis, boolean ignoreMetadata) { |
|
291 |
// TODO Auto-generated method stub |
|
292 |
return this.equals(definition); |
|
293 |
} |
|
294 |
} |
org.gvsig.geotools.proj/trunk/org.gvsig.geotools.proj/org.gvsig.geotools.proj.catalog.impl/src/main/java/org/gvsig/geotools/proj/catalog/GtCrsCatalogLibrary.java | ||
---|---|---|
1 |
/** |
|
2 |
* gvSIG. Desktop Geographic Information System. |
|
3 |
* |
|
4 |
* Copyright (C) 2018gvSIG Association. |
|
5 |
* |
|
6 |
* This program is free software; you can redistribute it and/or |
|
7 |
* modify it under the terms of the GNU General Public License |
|
8 |
* as published by the Free Software Foundation; either version 2 |
|
9 |
* of the License, or (at your option) any later version. |
|
10 |
* |
|
11 |
* This program is distributed in the hope that it will be useful, |
|
12 |
* but WITHOUT ANY WARRANTY; without even the implied warranty of |
|
13 |
* MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the |
|
14 |
* GNU General Public License for more details. |
|
15 |
* |
|
16 |
* You should have received a copy of the GNU General Public License |
|
17 |
* along with this program; if not, write to the Free Software |
|
18 |
* Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, |
|
19 |
* MA 02110-1301, USA. |
|
20 |
* |
|
21 |
* For any additional information, do not hesitate to contact us |
|
22 |
* at info AT gvsig.com, or visit our website www.gvsig.com. |
|
23 |
*/ |
|
24 |
package org.gvsig.geotools.proj.catalog; |
|
25 |
|
|
26 |
import org.gvsig.proj.catalog.CRSCatalogLibrary; |
|
27 |
import org.gvsig.proj.catalog.CRSCatalogLocator; |
|
28 |
import org.gvsig.tools.library.AbstractLibrary; |
|
29 |
import org.gvsig.tools.library.LibraryException; |
|
30 |
|
|
31 |
/** |
|
32 |
* Library to register the Geottols-based implementation of the |
|
33 |
* org.gvsig.proj.catalog API. |
|
34 |
* |
|
35 |
* @author Cesar Martinez Izquierdo |
|
36 |
*/ |
|
37 |
public class GtCrsCatalogLibrary extends AbstractLibrary { |
|
38 |
|
|
39 |
public GtCrsCatalogLibrary() { |
|
40 |
registerAsImplementationOf(CRSCatalogLibrary.class); |
|
41 |
} |
|
42 |
|
|
43 |
@Override |
|
44 |
protected void doInitialize() throws LibraryException { |
|
45 |
CRSCatalogLocator.registerManager(GtCRSCatalogManager.class); |
|
46 |
|
|
47 |
} |
|
48 |
|
|
49 |
@Override |
|
50 |
protected void doPostInitialize() throws LibraryException { |
|
51 |
// TODO Auto-generated method stub |
|
52 |
|
|
53 |
} |
|
54 |
|
|
55 |
} |
org.gvsig.geotools.proj/trunk/org.gvsig.geotools.proj/org.gvsig.geotools.proj.catalog.impl/src/main/java/org/gvsig/geotools/proj/catalog/utils/DistanceCalculator.java | ||
---|---|---|
1 |
package org.gvsig.geotools.proj.catalog.utils; |
|
2 |
|
|
3 |
import javax.measure.IncommensurableException; |
|
4 |
import javax.measure.UnconvertibleException; |
|
5 |
import javax.measure.Unit; |
|
6 |
import javax.measure.quantity.Length; |
|
7 |
|
|
8 |
import org.geotools.referencing.CRS; |
|
9 |
import org.geotools.referencing.GeodeticCalculator; |
|
10 |
import org.geotools.referencing.operation.transform.ConcatenatedTransform; |
|
11 |
import org.gvsig.proj.catalog.exception.CoordinateReferenceSystemException; |
|
12 |
import org.gvsig.proj.catalog.exception.TransformationException; |
|
13 |
import org.gvsig.proj.catalog.exception.UnsupportedCoordinateReferenceSystemException; |
|
14 |
import org.gvsig.proj.exception.DistanceCalculationException; |
|
15 |
import org.opengis.referencing.crs.CompoundCRS; |
|
16 |
import org.opengis.referencing.crs.CoordinateReferenceSystem; |
|
17 |
import org.opengis.referencing.crs.GeneralDerivedCRS; |
|
18 |
import org.opengis.referencing.crs.GeocentricCRS; |
|
19 |
import org.opengis.referencing.crs.GeographicCRS; |
|
20 |
import org.opengis.referencing.crs.ProjectedCRS; |
|
21 |
import org.opengis.referencing.crs.SingleCRS; |
|
22 |
import org.opengis.referencing.datum.GeodeticDatum; |
|
23 |
import org.opengis.referencing.operation.MathTransform; |
|
24 |
import org.opengis.referencing.operation.NoninvertibleTransformException; |
|
25 |
import org.opengis.referencing.operation.TransformException; |
|
26 |
|
|
27 |
/** |
|
28 |
* Utility class to calculate distances between two points, using different |
Also available in: Unified diff