I get my position in EPSG: 4326 by my Android GPS, now i would convert it coordinates to EPSG: 32632. Someone have an idea?
Asked
Active
Viewed 1,798 times
1 Answers
0
Use geotools. http://www.geotools.org/
Here is an transformation example.
http://docs.geotools.org/stable/userguide/library/api/jts.html
First, you have to remove 3 jar files from the download directory as follows:
For example geotools version 18.0,
gt-epsg-hsql-18.0.jar gt-epsg-oracle-18.0.jar gt-epsg-postgresql-18.0.jar
There are almost two cases existing. 1. using decode method of a CRS class:
CRSFactory crsFactory = ReferencingFactoryFinder.getCRSFactory(null);
CoordinateReferenceSystem targetCRS = null;
CoordinateReferenceSystem sourceCRS = null;
Geometry transCoordGeometry = null;
try {
targetCRS = CRS.decode("EPSG:32632");
sourceCRS = CRS.decode("EPSG:4326");
} catch (FactoryException e1) {
// TODO Auto-generated catch block
e1.printStackTrace();
}
MathTransform transform = null;
try {
transform = CRS.findMathTransform(sourceCRS, targetCRS);
transCoordGeometry = JTS.transform(orgGeometry, transform);
} catch (FactoryException | MismatchedDimensionException | TransformException e) {
// TODO Auto-generated catch block
e.printStackTrace();
}
- Using a wkt string.
the string variable of the targetWKT from
http://spatialreference.org/ref/epsg/wgs-84-utm-zone-32n/prettywkt/
PROJCS["WGS 84 / UTM zone 32N",
GEOGCS["WGS 84",
DATUM["WGS_1984",
SPHEROID["WGS 84",6378137,298.257223563,
AUTHORITY["EPSG","7030"]],
AUTHORITY["EPSG","6326"]],
PRIMEM["Greenwich",0,
AUTHORITY["EPSG","8901"]],
UNIT["degree",0.01745329251994328,
AUTHORITY["EPSG","9122"]],
AUTHORITY["EPSG","4326"]],
UNIT["metre",1,
AUTHORITY["EPSG","9001"]],
PROJECTION["Transverse_Mercator"],
PARAMETER["latitude_of_origin",0],
PARAMETER["central_meridian",9],
PARAMETER["scale_factor",0.9996],
PARAMETER["false_easting",500000],
PARAMETER["false_northing",0],
AUTHORITY["EPSG","32632"],
AXIS["Easting",EAST],
AXIS["Northing",NORTH]]
Then, the code is:
CRSFactory crsFactory = ReferencingFactoryFinder.getCRSFactory(null);
CoordinateReferenceSystem targetCRS = null;
CoordinateReferenceSystem sourceCRS = null;
Geometry transCoordGeometry = null;
try {
targetCRS = crsFactory.createFromWKT(targetWKT);
sourceCRS = CRS.decode("EPSG:4326");
} catch (FactoryException e1) {
e1.printStackTrace();
}
MathTransform transform = null;
try {
transform = CRS.findMathTransform(sourceCRS, targetCRS);
transCoordGeometry = JTS.transform(orgGeometry, transform);
} catch (FactoryException | MismatchedDimensionException | TransformException e) {
// TODO Auto-generated catch block
e.printStackTrace();
}

tommybee
- 2,409
- 1
- 20
- 23