EnviCrsFactory { public static CoordinateReferenceSystem createCrs(int enviProjectionNumber, double[] parameter, String datumString, String unitString) { if (projectionMethodMap.containsKey(enviProjectionNumber)) { String method = projectionMethodMap.get(enviProjectionNumber); try { final MathTransformFactory transformFactory = ReferencingFactoryFinder.getMathTransformFactory(null); final ParameterValueGroup parameters = transformFactory.getDefaultParameters(method); final Map<String, Integer> map = projectionParameterMaps.get(enviProjectionNumber); final List<GeneralParameterDescriptor> parameterDescriptors = parameters.getDescriptor().descriptors(); for (GeneralParameterDescriptor parameterDescriptor : parameterDescriptors) { final String paramName = parameterDescriptor.getName().getCode(); if (map.containsKey(paramName)) { final Integer index = map.get(paramName); parameters.parameter(paramName).setValue(parameter[index]); } } MathTransform mathTransform = transformFactory.createParameterizedTransform(parameters); DefaultGeographicCRS base; if (EnviConstants.DATUM_NAME_WGS84.equals(datumString)) { base = DefaultGeographicCRS.WGS84; } else { int[] indices = axisMap.get(enviProjectionNumber); if (indices != null) { double semiMajorAxis = parameter[indices[0]]; double semiMinorAxis = parameter[indices[1]]; DefaultEllipsoid ellipsoid = DefaultEllipsoid.createEllipsoid("SPHERE", semiMajorAxis, semiMinorAxis, SI.METER); DefaultGeodeticDatum datum = new DefaultGeodeticDatum(datumString, ellipsoid, DefaultPrimeMeridian.GREENWICH); base = new DefaultGeographicCRS(datum, DefaultEllipsoidalCS.GEODETIC_2D); } else { base = DefaultGeographicCRS.WGS84; } } return new DefaultProjectedCRS(parameters.getDescriptor().getName().getCode() + " / " + datumString, base, mathTransform, DefaultCartesianCS.PROJECTED); } catch (FactoryException fe) { Debug.trace(fe); } } throw new IllegalArgumentException(String.format("Unknown ENVI projection number: %d", enviProjectionNumber)); } private  EnviCrsFactory(); static CoordinateReferenceSystem createCrs(int enviProjectionNumber, double[] parameter, String datumString, String unitString);  }
@Test(expected = IllegalArgumentException.class) public void testThrowsIllegalArgumentExceptionOnUnregisteredProjection() { EnviCrsFactory.createCrs(-11, new double[0], EnviConstants.DATUM_NAME_WGS84, "Meters"); }
@Test public void testCreateAlbersEqualAreaConic() { final double[] parameter = new double[]{ 1.0, 2.0, 3.0, 4.0, 5.0, 6.0, 7.0, 8.0, }; final CoordinateReferenceSystem crs = EnviCrsFactory.createCrs(9, parameter, EnviConstants.DATUM_NAME_WGS84, "Meters"); final ParameterValueGroup parameterValues = CRS.getMapProjection(crs).getParameterValues(); final List<GeneralParameterValue> valueList = parameterValues.values(); double[] actualValues = new double[8]; for (int i = 0;i < valueList.size(); i++) { GeneralParameterValue gPValue = valueList.get(i); final ParameterValue<?> param = parameterValues.parameter(gPValue.getDescriptor().getName().getCode()); actualValues[i] = param.doubleValue(); } ParameterValue<?> param; param = parameterValues.parameter("semi_major"); assertEquals(1.0, param.doubleValue(), 1.0e-6); param = parameterValues.parameter("semi_minor"); assertEquals(2.0, param.doubleValue(), 1.0e-6); param = parameterValues.parameter("latitude_of_origin"); assertEquals(3.0, param.doubleValue(), 1.0e-6); param = parameterValues.parameter("central_meridian"); assertEquals(4.0, param.doubleValue(), 1.0e-6); param = parameterValues.parameter("false_easting"); assertEquals(5.0, param.doubleValue(), 1.0e-6); param = parameterValues.parameter("false_northing"); assertEquals(6.0, param.doubleValue(), 1.0e-6); param = parameterValues.parameter("standard_parallel_1"); assertEquals(7.0, param.doubleValue(), 1.0e-6); param = parameterValues.parameter("standard_parallel_2"); assertEquals(8.0, param.doubleValue(), 1.0e-6); }