I have to transform GPS coordinates (latitude and longitude) to a Lambert Conformal Conic projection. The map refers to Italy. Since I'm not an expert of this subject I found (googling) that one of the best libraries for Java is GeoToolkit. Unfortunately, I found no examples nor documentation (only Javadoc). Here the projection parameters (proj=Lcc Lat_2=45 Lat_1=40 Lat_0=42.5 Lon_0=9.2 x_0=600000 y_0=2200000):
PARAM_MT["Lambert_Conformal_Conic_2SP",
PARAMETER["semi_major", 6378137.0],
PARAMETER["semi_minor", 6356752.314],
PARAMETER["central_meridian", 9.2],
PARAMETER["latitude_of_origin", 42.5],
PARAMETER["false_easting", 600000.0],
PARAMETER["false_northing", 2200000.0],
PARAMETER["standard_parallel_2", 45.0],
PARAMETER["standard_parallel_1", 40.0]]
Does anyone knows a better library than GeoToolkit?
I wrote the following code to convert coords:
// 1. Get the MathTransform Factory
MathTransformFactory factory;
FactoryRegistry registry = new FactoryRegistry(
MathTransformFactory.class);
factory = registry.getServiceProvider(MathTransformFactory.class, null,
null, Hints.MATH_TRANSFORM_FACTORY);
// 2. Define source and target coord reference systems
GeographicCRS sourceCRS = DefaultGeographicCRS.WGS84;
ParameterValueGroup parameters = factory
.getDefaultParameters("Lambert_Conformal_Conic_2SP");
parameters.parameter("semi_major").setValue(WGS84_AXIS_MAJOR);
parameters.parameter("semi_minor").setValue(WGS84_AXIS_MINOR);
parameters.parameter("central_meridian").setValue(9.2);
parameters.parameter("latitude_of_origin").setValue(42.5);
parameters.parameter("standard_parallel_1").setValue(40.0);
parameters.parameter("standard_parallel_2").setValue(45.0);
parameters.parameter("false_easting").setValue(600000);
parameters.parameter("false_northing").setValue(2200000);
// 3. Create the MathTransform with the given parameters
Conversion conversion = new DefiningConversion("GPS to Lambert",
parameters);
CRSFactory crsFactory = FactoryFinder.getCRSFactory(null);
Map<String, ?> properties = Collections.singletonMap(
ProjectedCRS.NAME_KEY, "LatLon2Lambert");
ProjectedCRS targetCRS = crsFactory.createProjectedCRS(properties,
sourceCRS, conversion, DefaultCartesianCS.GENERIC_2D);
MathTransform tr = CRS.findMathTransform(sourceCRS, targetCRS);
DirectPosition sourcePt = new DefaultDirectPosition(DefaultGeographicCRS.WGS84);
sourcePt.setOrdinate(0, 45.0);
sourcePt.setOrdinate(1, 8.0);
DirectPosition targetPt = tr.transform(p.getValue(), null);
However, it doesn't work. Where am I wrong? Thanks in advance.