[GIS] How to transform data from a custom projection in JTS

coordinate systemcoordinatesjavajts-topology-suite

I have some data in NAD_1983_StatePlane_Texas_Central_FIPS_4203_Feet

I wish to programmatically transform the coordinates to Lat long in WGS84 datum using JTS.

I know that JTS can transform the coordinates using the following code:

import org.geotools.geometry.jts.JTS;
import org.geotools.referencing.CRS;

CoordinateReferenceSystem sourceCRS = CRS.decode("EPSG:4326");
CoordinateReferenceSystem targetCRS = CRS.decode("EPSG:23032");

MathTransform transform = CRS.findMathTransform(sourceCRS, targetCRS);
Geometry targetGeometry = JTS.transform( sourceGeometry, transform);

But my projection does not have an EPSG code.

How do I define the coordinate system in this case? How do I transform my data into EPSG:3857?

Best Answer

Have a look at this documentation of CRS http://docs.geotools.org/latest/userguide/library/referencing/crs.html#well-known-text

It is possible to set the CRS from WKT. The documentation says:

CoordinateReferenceSystem can also be defined by a text format ((called “Well Known Text” or WKT). This is a standard provided by the OGC and shows up in inside a shapefile “prj” file, or in a databases such as PostGIS and Oracle.

To parse WKT please use the CRS.parseWKT( txt ) method.

It is possible to get the WKT from the PRJ file or even from http://spatialreference.org/ref/sr-org/nad_1983_stateplane_texas_central_fips_4203_feet/ogcwkt/

Once the CRS is set from the WKT, the rest of the process is as it was.