use of org.opengis.parameter.ParameterValueGroup in project sis by apache.
the class TensorParametersTest method testMatrixConversion.
/**
* Tests {@link TensorParameters#createValueGroup(Map, Matrix)} and its converse
* {@link TensorParameters#toMatrix(ParameterValueGroup)}.
*/
@Test
@DependsOnMethod("testGetAllDescriptors")
public void testMatrixConversion() {
final int size = StrictMath.min(6, TensorParameters.CACHE_SIZE);
final Random random = TestUtilities.createRandomNumberGenerator();
for (int numRow = 2; numRow <= size; numRow++) {
for (int numCol = 2; numCol <= size; numCol++) {
final Matrix matrix = Matrices.createZero(numRow, numCol);
for (int j = 0; j < numRow; j++) {
for (int i = 0; i < numCol; i++) {
matrix.setElement(j, i, 200 * random.nextDouble() - 100);
}
}
final ParameterValueGroup group = param.createValueGroup(singletonMap(ParameterDescriptor.NAME_KEY, "Test"), matrix);
assertEquals(NUM_ROW, numRow, group.parameter(NUM_ROW).intValue());
assertEquals(NUM_COL, numCol, group.parameter(NUM_COL).intValue());
assertEquals("elements", matrix, param.toMatrix(group));
assertEquals("elements", matrix, param.toMatrix(new ParameterValueGroupWrapper(group)));
}
}
}
use of org.opengis.parameter.ParameterValueGroup in project sis by apache.
the class Proj4Factory method createCRS.
/**
* Creates a coordinate reference system from the given {@literal Proj.4} wrapper.
* The given {@code pj} will be stored as the CRS identifier.
*
* @param pj the Proj.4 object to wrap.
* @param withHeight whether to include a height axis.
* @throws IllegalArgumentException if a Proj.4 parameter value can not be parsed or assigned.
* @throws ParserException if a unit symbol can not be parsed.
*/
private CoordinateReferenceSystem createCRS(final PJ pj, final boolean withHeight) throws FactoryException {
final PJ.Type type = pj.getType();
final boolean geographic = PJ.Type.GEOGRAPHIC.equals(type);
final boolean geocentric = PJ.Type.GEOCENTRIC.equals(type);
final Proj4Parser parser = new Proj4Parser(pj.getCode());
final String dir = parser.value("axis", "enu");
final CoordinateSystemAxis[] axes = new CoordinateSystemAxis[geocentric | withHeight ? dir.length() : 2];
for (int i = 0; i < axes.length; i++) {
final char d = Character.toLowerCase(dir.charAt(i));
char abbreviation = Character.toUpperCase(d);
boolean vertical = false;
final AxisDirection c;
final String name;
if (geocentric)
switch(d) {
case 'e':
c = AxisDirection.GEOCENTRIC_X;
name = "Geocentric X";
break;
case 'n':
c = AxisDirection.GEOCENTRIC_Y;
name = "Geocentric Y";
break;
case 'u':
c = AxisDirection.GEOCENTRIC_Z;
name = "Geocentric Z";
break;
default:
c = AxisDirection.OTHER;
name = "Unknown";
break;
}
else
switch(d) {
case 'e':
c = AxisDirection.EAST;
name = geographic ? "Geodetic longitude" : "Easting";
break;
case 'w':
c = AxisDirection.WEST;
name = geographic ? "Geodetic longitude" : "Westing";
break;
case 'n':
c = AxisDirection.NORTH;
name = geographic ? "Geodetic latitude" : "Northing";
break;
case 's':
c = AxisDirection.SOUTH;
name = geographic ? "Geodetic latitude" : "Southing";
break;
case 'u':
c = AxisDirection.UP;
name = "Height";
vertical = true;
abbreviation = 'h';
break;
case 'd':
c = AxisDirection.DOWN;
name = "Depth";
vertical = true;
break;
default:
c = AxisDirection.OTHER;
name = "Unknown";
break;
}
if (geographic && AxisDirections.isCardinal(c)) {
abbreviation = (d == 'e' || d == 'w') ? 'λ' : 'φ';
}
final Unit<?> unit = (vertical || !geographic) ? parser.unit(vertical) : Units.DEGREE;
axes[i] = csFactory.createCoordinateSystemAxis(identifier(name), String.valueOf(abbreviation).intern(), c, unit);
}
/*
* At this point we got the coordinate system axes. Now create the CRS. The given Proj.4 object
* will be stored as the CRS identifier for allowing OperationFactory to get it back before to
* attempt to create a new one for a given CRS.
*/
final Map<String, Object> csName = identifier(UNNAMED);
final Map<String, Object> name = new HashMap<>(identifier(parser.name(type == PJ.Type.PROJECTED)));
name.put(CoordinateReferenceSystem.IDENTIFIERS_KEY, pj);
switch(type) {
case GEOGRAPHIC:
{
return crsFactory.createGeographicCRS(name, createDatum(pj, parser), withHeight ? csFactory.createEllipsoidalCS(csName, axes[0], axes[1], axes[2]) : csFactory.createEllipsoidalCS(csName, axes[0], axes[1]));
}
case GEOCENTRIC:
{
return crsFactory.createGeocentricCRS(name, createDatum(pj, parser), csFactory.createCartesianCS(csName, axes[0], axes[1], axes[2]));
}
case PROJECTED:
{
final PJ base = unique(new PJ(pj));
final CoordinateReferenceSystem baseCRS = createCRS(base, withHeight);
final Transform tr = new Transform(pj, withHeight, base, withHeight);
/*
* Try to convert the Proj.4 parameters into OGC parameters in order to have a less opaque structure.
* Failure to perform this conversion will not cause a failure to create the ProjectedCRS. After all,
* maybe the user invokes this method for using a map projection not yet supported by Apache SIS.
* Instead, fallback on the more opaque Transform.METHOD description. Apache SIS will not be able to
* perform analysis on those parameters, but it will not prevent the Proj.4 transformation to work.
*/
OperationMethod method;
ParameterValueGroup parameters;
try {
method = parser.method(opFactory());
parameters = parser.parameters();
} catch (IllegalArgumentException | FactoryException e) {
Logging.recoverableException(Logging.getLogger(Modules.GDAL), Proj4Factory.class, "createProjectedCRS", e);
method = Transform.METHOD;
// Will let Apache SIS infers the parameters from the Transform instance.
parameters = null;
}
final Conversion fromBase = new DefaultConversion(name, method, tr, parameters);
return crsFactory.createProjectedCRS(name, (GeographicCRS) baseCRS, fromBase, withHeight ? csFactory.createCartesianCS(csName, axes[0], axes[1], axes[2]) : csFactory.createCartesianCS(csName, axes[0], axes[1]));
}
default:
{
throw new FactoryException(Errors.getResources(defaultProperties).getString(Errors.Keys.UnknownEnumValue_2, type, PJ.Type.class));
}
}
}
use of org.opengis.parameter.ParameterValueGroup in project sis by apache.
the class Proj4Parser method parameters.
/**
* Returns the parameter value group filled from the {@literal Proj.4} parameters.
*
* @throws IllegalArgumentException if a Proj.4 parameter can not be converted to the expected type.
*/
final ParameterValueGroup parameters() throws IllegalArgumentException {
final ParameterValueGroup pg = method.getParameters().createValue();
for (final Map.Entry<String, String> entry : parameters.entrySet()) {
final String keyword = entry.getKey();
if (!EXCLUDES.contains(keyword)) {
final ParameterValue<?> value = pg.parameter(keyword);
value.setValue(Double.parseDouble(entry.getValue()));
}
}
return pg;
}
use of org.opengis.parameter.ParameterValueGroup in project sis by apache.
the class Transform method getParameterValues.
/**
* Returns a copy of the parameter values for this parameterized object.
*/
@Override
public ParameterValueGroup getParameterValues() {
final ParameterValueGroup pg = getParameterDescriptors().createValue();
pg.parameter("srcdefn").setValue(source.getCode().trim());
pg.parameter("dstdefn").setValue(target.getCode().trim());
return pg;
}
use of org.opengis.parameter.ParameterValueGroup in project sis by apache.
the class Proj4FactoryTest method testParameterizedTransform.
/**
* Tests {@link Proj4Factory#createParameterizedTransform(ParameterValueGroup)}.
*
* @throws FactoryException if an error occurred while creating the CRS objects.
* @throws TransformException if an error occurred while projecting a test point.
*/
@Test
public void testParameterizedTransform() throws FactoryException, TransformException {
final Proj4Factory factory = Proj4Factory.INSTANCE;
final ParameterValueGroup pg = factory.getDefaultParameters("merc");
pg.parameter("a").setValue(6378137.0);
pg.parameter("b").setValue(6356752.314245179);
testMercatorProjection(factory.createParameterizedTransform(pg));
}
Aggregations