org.opengis.parameter.ParameterDescriptor Java Examples

The following examples show how to use org.opengis.parameter.ParameterDescriptor. You can vote up the ones you like or vote down the ones you don't like, and go to the original project or source file by following the links above each example. You may check out the related API usage on the sidebar.
Example #1
Source File: CC_OperationParameterGroupTest.java    From sis with Apache License 2.0 6 votes vote down vote up
/**
 * Tests the substitution of unmarshalled descriptors by more complete descriptors.
 * No merging should be done in this test.
 *
 * @throws JAXBException if this method failed to create test data.
 */
@Test
public void testSubtitution() throws JAXBException {
    final ParameterDescriptor<?>[]         expected   = create(REMARK);
    final List<GeneralParameterDescriptor> fromXML    = unmarshal().descriptors();
    final List<GeneralParameterDescriptor> fromValues = UnmodifiableArrayList.wrap(expected);
    final Map<GeneralParameterDescriptor,GeneralParameterDescriptor> replacements = new IdentityHashMap<>(4);
    final GeneralParameterDescriptor[] merged = CC_OperationParameterGroup.merge(fromXML,
            fromValues.toArray(new GeneralParameterDescriptor[fromValues.size()]), replacements);

    assertTrue("Expected no replacement.", replacements.isEmpty());
    assertEquals("Number of parameters", 2, merged.length);
    assertNotSame(expected, merged);
    assertArrayEquals(expected, merged);
    for (int i=0; i<merged.length; i++) {
        assertSame(expected[i], merged[i]);     // Not just equals, but actually same instance.
    }
}
 
Example #2
Source File: ServiceParameter.java    From sis with Apache License 2.0 6 votes vote down vote up
/**
 * Gets the parameter name as a {@code MemberName}. This method first checks if the primary name is an instance of
 * {@code MemberName}. If not, this method searches for the first alias which is an instance of {@code MemberName}.
 * If none is found, then this method tries to build a member name from the primary name and value class.
 *
 * @param  parameter  the parameter from which to get the name (may be {@code null}).
 * @return the member name, or {@code null} if none.
 */
public static MemberName getMemberName(final ParameterDescriptor<?> parameter) {
    if (parameter != null) {
        final ReferenceIdentifier id = parameter.getName();
        if (id instanceof MemberName) {
            return (MemberName) id;
        }
        for (final GenericName alias : nonNull(parameter.getAlias())) {
            if (alias instanceof MemberName) {
                return (MemberName) alias;
            }
        }
        if (id != null) {
            final Class<?> valueClass = parameter.getValueClass();
            if (valueClass != null) {
                final String code = id.getCode();
                if (code != null) {
                    return Names.createMemberName(id.getCodeSpace(), null, code, valueClass);
                }
            }
        }
    }
    return null;
}
 
Example #3
Source File: DefaultServiceIdentificationTest.java    From sis with Apache License 2.0 6 votes vote down vote up
/**
     * Compare values of the given service identifications against the value expected for the
     * instance created by {@link #create()} method.
     */
    private static void verify(final DefaultServiceIdentification id) {
        assertEquals("serviceTypeVersion", "1.0",                                  getSingleton(id.getServiceTypeVersions()));
        assertEquals("serviceType",        "Web Map Server",                       String.valueOf(id.getServiceType()));
        assertEquals("abstract",           "A dummy service for testing purpose.", String.valueOf(id.getAbstract()));
        assertEquals("citation",           NilReason.MISSING,                      NilReason.forObject(id.getCitation()));
        assertEquals("couplingType",       UnsupportedCodeList.valueOf("loose"),   id.getCouplingType());

        final DefaultCoupledResource resource = getSingleton(id.getCoupledResources());
//      assertEquals("scopedName",        "mySpace:ABC-123",   …)  skipped because not present in new ISO 19115-3:2016.
//      assertEquals("resourceReference", "WMS specification", …)  skipped because not present in legacy ISO 19139:2007.

        final DefaultOperationMetadata op = resource.getOperation();
        assertNotNull("operation", op);
        assertEquals("operationName", "Get Map", op.getOperationName());
        assertEquals("distributedComputingPlatform", UnsupportedCodeList.valueOf("WEB_SERVICES"), getSingleton(op.getDistributedComputingPlatforms()));
        assertEquals("connectPoints", NilReason.MISSING, NilReason.forObject(getSingleton(op.getConnectPoints())));

        final ParameterDescriptor<?> param = getSingleton(op.getParameters());
        assertEquals("name",          "Version",             String.valueOf(param.getName()));
        assertEquals("minimumOccurs", 0,                     param.getMinimumOccurs());
        assertEquals("maximumOccurs", 1,                     param.getMaximumOccurs());
//      assertEquals("direction",     ParameterDirection.IN, param.getDirection());
    }
 
Example #4
Source File: DefaultParameterDescriptorTest.java    From sis with Apache License 2.0 6 votes vote down vote up
/**
 * Tests {@code DefaultParameterDescriptor} constructor
 * with valid and invalid minimum and maximum values.
 */
@Test
@DependsOnMethod("testOptionalInteger")
@SuppressWarnings("UnnecessaryBoxing")
public void testRangeValidation() {
    try {
        create("Test range", 20, 4, 12);
        fail("minimum > maximum");
    } catch (IllegalArgumentException exception) {
        assertEquals("Range [20 … 4] is not valid.", exception.getMessage());
    }
    final ParameterDescriptor<Integer> descriptor = create("Test range", 4, 20, 12);
    assertEquals("name",          "Test range",        descriptor.getName().getCode());
    assertEquals("valueClass",    Integer.class,       descriptor.getValueClass());
    assertNull  ("validValues",                        descriptor.getValidValues());
    assertEquals("defaultValue",  Integer.valueOf(12), descriptor.getDefaultValue());
    assertEquals("minimumValue",  Integer.valueOf( 4), descriptor.getMinimumValue());
    assertEquals("maximumValue",  Integer.valueOf(20), descriptor.getMaximumValue());
    assertEquals("minimumOccurs", 1, descriptor.getMinimumOccurs());
    assertEquals("maximumOccurs", 1, descriptor.getMaximumOccurs());
}
 
Example #5
Source File: CC_OperationParameterGroupTest.java    From sis with Apache License 2.0 6 votes vote down vote up
/**
 * Tests {@link CC_OperationMethod#group(Identifier, GeneralParameterDescriptor[])}.
 *
 * @throws JAXBException if this method failed to create test data.
 */
@Test
@DependsOnMethod("testMerge")
public void testGroup() throws JAXBException {
    // From XML
    ParameterDescriptorGroup group = unmarshal();
    List<GeneralParameterDescriptor> descriptors = group.descriptors();

    // Merge with the parameters defined in Mercator1SP class
    group = CC_OperationMethod.group(group.getName(), descriptors.toArray(new GeneralParameterDescriptor[descriptors.size()]));
    descriptors = group.descriptors();

    assertSame("name", group.getName(), group.getName());
    assertEquals("descriptors.size", 2, descriptors.size());
    verifyMethodParameter(Mercator1SP.LATITUDE_OF_ORIGIN, REMARK, (ParameterDescriptor<?>) descriptors.get(0));
    verifyMethodParameter(Mercator1SP.LONGITUDE_OF_ORIGIN,  null, (ParameterDescriptor<?>) descriptors.get(1));
}
 
Example #6
Source File: CC_GeneralOperationParameterTest.java    From sis with Apache License 2.0 6 votes vote down vote up
/**
 * Tests cases where the unmarshalled parameter can be substituted by the complete parameter.
 * The cases tested in this method should not create any new {@code ParameterDescriptor} instance.
 *
 * @throws JAXBException if this method failed to create test data.
 */
@Test
public void testParameterSubstitution() throws JAXBException {
    ParameterDescriptor<?> provided = unmarshal("Optional parameter", null);
    ParameterDescriptor<?> complete = create("Optional parameter", null, false, null);
    assertSame("Trivial case.",    complete, CC_GeneralOperationParameter.merge(complete, complete));
    assertSame("Same properties.", complete, CC_GeneralOperationParameter.merge(provided, complete));

    complete = create("OptionalParameter", null, false, null);
    assertSame("Slightly different name.", complete, CC_GeneralOperationParameter.merge(provided, complete));

    complete = create("Optional parameter", null, false, 3);
    assertSame("With default value.", complete, CC_GeneralOperationParameter.merge(provided, complete));

    complete = create("Optional parameter", "More details here.", false, null);
    assertSame("With additional property.", complete, CC_GeneralOperationParameter.merge(provided, complete));

    provided = unmarshal("Optional parameter", "More details here.");
    assertSame("With same remark.", complete, CC_GeneralOperationParameter.merge(provided, complete));
}
 
Example #7
Source File: DefaultParameterValueGroup.java    From sis with Apache License 2.0 6 votes vote down vote up
/**
 * Appends all parameter values. In this process, we may need to update the descriptor of some values
 * if those descriptors changed as a result of the above merge process.
 *
 * @param parameters   The parameters to add, or {@code null} for {@link #values}.
 * @param replacements The replacements to apply in the {@code GeneralParameterValue} instances.
 * @param addTo        Where to store the new values.
 */
@SuppressWarnings({"unchecked", "AssignmentToCollectionOrArrayFieldFromParameter"})
private void setValues(GeneralParameterValue[] parameters,
        final Map<GeneralParameterDescriptor,GeneralParameterDescriptor> replacements,
        final ParameterValueList addTo)
{
    if (parameters == null) {
        parameters = values.toArray();
    }
    for (final GeneralParameterValue p : parameters) {
        final GeneralParameterDescriptor replacement = replacements.get(p.getDescriptor());
        if (replacement != null) {
            if (p instanceof DefaultParameterValue<?>) {
                ((DefaultParameterValue<?>) p).setDescriptor((ParameterDescriptor) replacement);
            } else if (p instanceof DefaultParameterValueGroup) {
                ((DefaultParameterValueGroup) p).setValues(null, replacements,
                        new ParameterValueList((ParameterDescriptorGroup) replacement));
            }
        }
        addTo.add(p);
    }
    values = addTo;
}
 
Example #8
Source File: DefaultOperationMethodTest.java    From sis with Apache License 2.0 6 votes vote down vote up
/**
 * Creates a new two-dimensional operation method for an operation of the given name and identifier.
 *
 * @param  method      the operation name (example: "Mercator (variant A)").
 * @param  identifier  the EPSG numeric identifier (example: "9804").
 * @param  formula     formula citation (example: "EPSG guidance note #7-2").
 * @param  dimension   the number of input and output dimension, or {@code null}.
 * @param  parameters  the parameters (can be empty).
 * @return the operation method.
 */
static DefaultOperationMethod create(final String method, final String identifier, final String formula,
        final Integer dimension, final ParameterDescriptor<?>... parameters)
{
    final Map<String,Object> properties = new HashMap<>(8);
    assertNull(properties.put(OperationMethod.NAME_KEY, method));
    assertNull(properties.put(ReferenceIdentifier.CODESPACE_KEY, "EPSG"));
    assertNull(properties.put(Identifier.AUTHORITY_KEY, Citations.EPSG));
    /*
     * The parameter group for a Mercator projection is actually not empty, but it is not the purpose of
     * this class to test DefaultParameterDescriptorGroup. So we use an empty group of parameters here.
     */
    final ParameterDescriptorGroup pg = new DefaultParameterDescriptorGroup(properties, 1, 1, parameters);
    /*
     * NAME_KEY share the same Identifier instance for saving a little bit of memory.
     * Then define the other properties to be given to OperationMethod.
     */
    assertNotNull(properties.put(OperationMethod.NAME_KEY, pg.getName()));
    assertNull(properties.put(OperationMethod.IDENTIFIERS_KEY, new ImmutableIdentifier(Citations.EPSG, "EPSG", identifier)));
    assertNull(properties.put(OperationMethod.FORMULA_KEY, new DefaultCitation(formula)));
    return new DefaultOperationMethod(properties, dimension, dimension, pg);
}
 
Example #9
Source File: MapProjectionTest.java    From sis with Apache License 2.0 6 votes vote down vote up
/**
 * Verifies some {@link Mercator2SP} parameter descriptors.
 */
@Test
@DependsOnMethod("testMercator1SP")
public void testMercator2SP() {
    final Iterator<GeneralParameterDescriptor> it = Mercator2SP.PARAMETERS.descriptors().iterator();
    assertParamEquals("Mercator (variant B)",             "Mercator_2SP",        true,  Mercator2SP.PARAMETERS);
    assertParamEquals(null,                                SEMI_MAJOR,           true,  it.next());
    assertParamEquals(null,                                SEMI_MINOR,           true,  it.next());
    assertParamEquals("Latitude of 1st standard parallel", STANDARD_PARALLEL_1,  true,  it.next());
    assertParamEquals("Latitude of natural origin",        LATITUDE_OF_ORIGIN,   false, it.next());
    assertParamEquals("Longitude of natural origin",       CENTRAL_MERIDIAN,     true,  it.next());
    assertParamEquals(null,                                SCALE_FACTOR,         false, it.next());
    assertParamEquals("False easting",                     FALSE_EASTING,        true,  it.next());
    assertParamEquals("False northing",                    FALSE_NORTHING,       true,  it.next());
    assertFalse(it.hasNext());
    assertIsForcedToZero((ParameterDescriptor<?>) Mercator1SP.PARAMETERS.descriptor(LATITUDE_OF_ORIGIN));
}
 
Example #10
Source File: TensorParametersTest.java    From sis with Apache License 2.0 6 votes vote down vote up
/**
 * Asserts that the given descriptor has the given name, alias, identifier and default value.
 *
 * @param  defaultValue  the expected parameter default value.
 * @param  actual        the actual parameter to verify.
 * @param  row           row index of the matrix element to test.
 * @param  column        column index of the matrix element to test.
 */
private void verifyDescriptor(final Number defaultValue, final ParameterDescriptor<?> actual,
        final int row, final int column)
{
    assertEquals("name", names[row][column], actual.getName().getCode());
    assertAliasTipEquals((aliases != null) ? aliases[row][column] : null, actual);
    assertEquals("defaultValue", defaultValue, actual.getDefaultValue());
    if (identifiers != null) {
        final short expected = identifiers[row][column];
        if (expected != 0) {
            assertEpsgIdentifierEquals(String.valueOf(expected), TestUtilities.getSingleton(actual.getIdentifiers()));
            return;
        }
    }
    assertTrue(actual.getIdentifiers().isEmpty());
}
 
Example #11
Source File: TensorParametersTest.java    From sis with Apache License 2.0 6 votes vote down vote up
/**
 * Tests {@link TensorParameters#getElementDescriptor(int[])}.
 */
@Test
@DependsOnMethod("testIndicesToName")
public void testGetElementDescriptor() {
    final Double N0 = 0.0;
    final Double N1 = 1.0;
    final ParameterDescriptor<Double> e00 = param.getElementDescriptor(0, 0);
    final ParameterDescriptor<Double> e01 = param.getElementDescriptor(0, 1);
    final ParameterDescriptor<Double> e10 = param.getElementDescriptor(1, 0);
    final ParameterDescriptor<Double> e11 = param.getElementDescriptor(1, 1);
    verifyDescriptor(N1, e00, 0, 0);
    verifyDescriptor(N0, e01, 0, 1);
    verifyDescriptor(N0, e10, 1, 0);
    verifyDescriptor(N1, e11, 1, 1);
    assertSame(e00, param.getElementDescriptor(0, 0));      // Test caching.
    assertSame(e01, param.getElementDescriptor(0, 1));
    assertSame(e10, param.getElementDescriptor(1, 0));
    assertSame(e11, param.getElementDescriptor(1, 1));
}
 
Example #12
Source File: SingleOperationMarshallingTest.java    From sis with Apache License 2.0 6 votes vote down vote up
/**
 * Creates the test operation method.
 */
private static DefaultOperationMethod createMercatorMethod() {
    final ParameterBuilder builder = new ParameterBuilder();
    builder.setCodeSpace(EPSG, "EPSG").setRequired(true);
    ParameterDescriptor<?>[] parameters = {
        builder.addIdentifier("8801").addName("Latitude of natural origin" ).create(0, Units.DEGREE),
        builder.addIdentifier("8802").addName("Longitude of natural origin").create(0, Units.DEGREE)
        // There is more parameters for a Mercator projection, but 2 is enough for this test.
    };
    builder.addName(null, "Mercator (1SP)");
    final ParameterDescriptorGroup descriptor = builder.createGroup(parameters);
    final Map<String,Object> properties = new HashMap<>(4);
    properties.put(DefaultOperationMethod.NAME_KEY, descriptor.getName());
    properties.put(DefaultOperationMethod.FORMULA_KEY, new DefaultFormula("See EPSG guide."));
    return new DefaultOperationMethod(properties, 2, 2, descriptor);
}
 
Example #13
Source File: ParameterBuilderTest.java    From sis with Apache License 2.0 6 votes vote down vote up
/**
 * Tests various {@code create(…)} methods.
 */
@Test
public void testCreate() {
    final ParameterBuilder builder = new ParameterBuilder();
    ParameterDescriptor<Double> p = builder.addName("Test 1").create(0, Units.METRE);
    assertEquals("name", "Test 1",    p.getName().getCode());
    assertEquals("defaultValue", 0.0, p.getDefaultValue(), 0);
    assertNull  ("minimumValue",      p.getMinimumValue());
    assertNull  ("maximumValue",      p.getMaximumValue());
    assertEquals("unit", Units.METRE, p.getUnit());

    p = builder.addName("Test 2").create(Double.NaN, Units.METRE);
    assertEquals("name", "Test 2",    p.getName().getCode());
    assertNull  ("defaultValue",      p.getDefaultValue());
    assertNull  ("minimumValue",      p.getMinimumValue());
    assertNull  ("maximumValue",      p.getMaximumValue());
    assertEquals("unit", Units.METRE, p.getUnit());

    p = builder.addName("Test 3").createBounded(1, 4, 3, Units.METRE);
    assertEquals("name", "Test 3",    p.getName().getCode());
    assertEquals("defaultValue", 3.0, p.getDefaultValue(), 0);
    assertEquals("minimumValue", 1.0, p.getMinimumValue());
    assertEquals("maximumValue", 4.0, p.getMaximumValue());
    assertEquals("unit", Units.METRE, p.getUnit());
}
 
Example #14
Source File: TransverseMercator.java    From sis with Apache License 2.0 6 votes vote down vote up
/**
 * Work around for RFE #4093999 in Sun's bug database
 * ("Relax constraint on placement of this()/super() call in constructors").
 */
@Workaround(library="JDK", version="1.7")
private static Initializer initializer(final OperationMethod method, final Parameters parameters) {
    final boolean isSouth = identMatch(method, "(?i).*\\bSouth\\b.*", TransverseMercatorSouth.IDENTIFIER);
    final EnumMap<ParameterRole, ParameterDescriptor<Double>> roles = new EnumMap<>(ParameterRole.class);
    ParameterRole xOffset = ParameterRole.FALSE_EASTING;
    ParameterRole yOffset = ParameterRole.FALSE_NORTHING;
    if (isSouth) {
        xOffset = ParameterRole.FALSE_WESTING;
        yOffset = ParameterRole.FALSE_SOUTHING;
    }
    roles.put(ParameterRole.CENTRAL_MERIDIAN, LONGITUDE_OF_ORIGIN);
    roles.put(ParameterRole.SCALE_FACTOR, SCALE_FACTOR);
    roles.put(xOffset, FALSE_EASTING);
    roles.put(yOffset, FALSE_NORTHING);
    return new Initializer(method, parameters, roles, isSouth ? (byte) 1 : (byte) 0);
}
 
Example #15
Source File: InterpolatedMolodenskyTransform.java    From sis with Apache License 2.0 6 votes vote down vote up
/**
 * Returns a description of the internal parameters of this {@code InterpolatedMolodenskyTransform} transform.
 * The returned group contains parameters for the source ellipsoid semi-axis lengths and the differences between
 * source and target ellipsoid parameters.
 *
 * <div class="note"><b>Note:</b>
 * this method is mostly for {@linkplain org.apache.sis.io.wkt.Convention#INTERNAL debugging purposes}
 * since the isolation of non-linear parameters in this class is highly implementation dependent.
 * Most GIS applications will instead be interested in the {@linkplain #getContextualParameters()
 * contextual parameters}.</div>
 *
 * @return a description of the internal parameters.
 */
@Debug
@Override
public ParameterDescriptorGroup getParameterDescriptors() {
    final ParameterDescriptor<?>[] param = new ParameterDescriptor<?>[] {
            Molodensky.DIMENSION,
            Molodensky.SRC_SEMI_MAJOR,
            Molodensky.SRC_SEMI_MINOR,
            Molodensky.AXIS_LENGTH_DIFFERENCE,
            Molodensky.FLATTENING_DIFFERENCE,
            FranceGeocentricInterpolation.FILE
    };
    return new ParameterBuilder().setRequired(true)
            .setCodeSpace(Citations.SIS, Constants.SIS)
            .addName(context.getDescriptor().getName().getCode() + " (radians domain)").createGroup(param);
}
 
Example #16
Source File: ParameterFormatTest.java    From sis with Apache License 2.0 6 votes vote down vote up
/**
 * Creates the test parameters for the Mercator projection, to be shared by {@link ParameterMarshallingTest}.
 *
 * <div class="note"><b>Note:</b>
 * the default values are not part of EPSG definitions. They are added here only for testing purpose.</div>
 */
static ParameterDescriptorGroup createMercatorParameters() {
    ParameterBuilder builder = new ParameterBuilder();
    builder.setCodeSpace(EPSG, "EPSG").setRequired(true);
    ParameterDescriptor<?>[] parameters = {
        builder.addIdentifier("8801").addName("Latitude of natural origin").addName(OGC, "latitude_of_origin")
                .setRemarks("This parameter is shown for completeness, but should never have a value different than 0 for this projection.")
                .createBounded( -80,  +84,  40, Units.DEGREE),
        builder.addIdentifier("8802").addName("Longitude of natural origin")     .addName(OGC, "central_meridian")  .createBounded(-180, +180, -60, Units.DEGREE),
        builder.addIdentifier("8805").addName("Scale factor at natural origin")  .addName(OGC, "scale_factor")      .createStrictlyPositive(1, Units.UNITY),
        builder.addIdentifier("8806").addName("False easting").setRequired(false).addName(OGC, "false_easting")     .create( 5000, Units.METRE),
        builder.addIdentifier("8807").addName("False northing")                  .addName(OGC, "false_northing")    .create(10000, Units.METRE)
    };
    builder.addIdentifier("9804")
           .addName("Mercator (variant A)")
           .addName("Mercator (1SP)")
           .addName(OGC, "Mercator_1SP");
    return builder.createGroup(parameters);
}
 
Example #17
Source File: ParameterBuilder.java    From sis with Apache License 2.0 6 votes vote down vote up
/**
 * Creates a descriptor for values of the given type restricted to the given domain.
 *
 * @param  <T>           the compile-time type of the {@code valueClass} argument.
 * @param  valueClass    the class that describe the type of the parameter values.
 * @param  minimumValue  the minimum parameter value (inclusive), or {@code null} if none.
 * @param  maximumValue  the maximum parameter value (inclusive), or {@code null} if none.
 * @param  defaultValue  the default value for the parameter, or {@code null} if none.
 * @return the parameter descriptor for the given domain of values.
 */
@SuppressWarnings({"unchecked", "rawtypes"})
public <T extends Comparable<? super T>> ParameterDescriptor<T> createBounded(final Class<T> valueClass,
        final T minimumValue, final T maximumValue, final T defaultValue)
{
    ensureNonNull("valueClass", valueClass);
    final Range<T> valueDomain;
    if (minimumValue == null && maximumValue == null) {
        valueDomain = null;
    } else if (Number.class.isAssignableFrom(valueClass)) {
        valueDomain = new NumberRange((Class) valueClass, (Number) minimumValue, true, (Number) maximumValue, true);
    } else {
        valueDomain = new Range<>(valueClass, minimumValue, true, maximumValue, true);
    }
    return create(valueClass, valueDomain, null, defaultValue);
}
 
Example #18
Source File: ZonedGridSystem.java    From sis with Apache License 2.0 6 votes vote down vote up
/**
 * Creates a Zoned Grid System from the given parameters.
 * The {@code method} argument can be the description of one of the following:
 *
 * <ul>
 *   <li><cite>"Transverse Mercator Zoned Grid System"</cite>.</li>
 * </ul>
 *
 * Contrarily to other map projections in this package, there is no {@code createMapProjection(MathTransformFactory)}
 * method in this class. Instead, the factory must be specified at this {@code ZonedGridSystem} construction time.
 *
 * @param  method      description of the projection parameters.
 * @param  parameters  the parameter values of the projection to create.
 * @param  factory     the factory to use for creating the transform.
 * @throws FactoryException if an error occurred while creating a transform.
 */
public ZonedGridSystem(final OperationMethod method, final Parameters parameters, final MathTransformFactory factory)
        throws FactoryException
{
    final EnumMap<NormalizedProjection.ParameterRole, ParameterDescriptor<Double>> roles =
            new EnumMap<>(NormalizedProjection.ParameterRole.class);
    roles.put(NormalizedProjection.ParameterRole.SCALE_FACTOR,   SCALE_FACTOR);
    roles.put(NormalizedProjection.ParameterRole.FALSE_EASTING,  FALSE_EASTING);
    roles.put(NormalizedProjection.ParameterRole.FALSE_NORTHING, FALSE_NORTHING);
    final Initializer initializer = new Initializer(method, parameters, roles, (byte) 0);
    initialLongitude = initializer.getAndStore(INITIAL_LONGITUDE);
    zoneWidth        = initializer.getAndStore(ZONE_WIDTH);
    final MatrixSIS normalize = initializer.context.getMatrix(ContextualParameters.MatrixRole.NORMALIZATION);
    normalize.convertBefore(0, null, zoneWidth / -2);
    projection = (AbstractMathTransform) new TransverseMercator(initializer).createMapProjection(factory);
    inverse    = new Inverse(this);
}
 
Example #19
Source File: Molodensky.java    From sis with Apache License 2.0 6 votes vote down vote up
/**
 * Creates a descriptor for the internal parameters of {@link MolodenskyTransform}.
 * This is similar to the standard parameters except that the redundant target axes
 * lengths are omitted.
 *
 * @return internal parameter descriptor.
 */
@Debug
public static ParameterDescriptorGroup internal() {
    final ParameterBuilder builder = builder().setCodeSpace(Citations.SIS, Constants.SIS);
    ParameterDescriptor<Boolean> abridged = builder.addName("abridged").create(Boolean.class, null);
    return builder.addName("Molodensky (radians domain)")
            .createGroup(DIMENSION,
                         SRC_SEMI_MAJOR,
                         SRC_SEMI_MINOR,
                         AXIS_LENGTH_DIFFERENCE,
                         FLATTENING_DIFFERENCE,
                         TX,
                         TY,
                         TZ,
                         abridged);
}
 
Example #20
Source File: MapProjectionTest.java    From sis with Apache License 2.0 6 votes vote down vote up
/**
 * Verifies some {@link Mercator1SP} parameter descriptors.
 */
@Test
@DependsOnMethod("testEquirectangular")
public void testMercator1SP() {
    final Iterator<GeneralParameterDescriptor> it = Mercator1SP.PARAMETERS.descriptors().iterator();
    assertParamEquals("Mercator (variant A)",          "Mercator_1SP",       true, Mercator1SP.PARAMETERS);
    assertParamEquals(null,                             SEMI_MAJOR,          true, it.next());
    assertParamEquals(null,                             SEMI_MINOR,          true, it.next());
    assertParamEquals("Latitude of natural origin",     LATITUDE_OF_ORIGIN,  true, it.next());
    assertParamEquals("Longitude of natural origin",    CENTRAL_MERIDIAN,    true, it.next());
    assertParamEquals("Scale factor at natural origin", SCALE_FACTOR,        true, it.next());
    assertParamEquals("False easting",                  FALSE_EASTING,       true, it.next());
    assertParamEquals("False northing",                 FALSE_NORTHING,      true, it.next());
    assertFalse(it.hasNext());
    assertIsForcedToZero((ParameterDescriptor<?>) Mercator1SP.PARAMETERS.descriptor(LATITUDE_OF_ORIGIN));
}
 
Example #21
Source File: ParameterBuilder.java    From sis with Apache License 2.0 5 votes vote down vote up
/**
 * Invoked by all {@code createXXX(…)} methods for creating the descriptor from the properties
 * currently set in this builder. Identification information are cleared after this method call.
 */
private <T> ParameterDescriptor<T> create(final Class<T> valueClass, final Range<?> valueDomain,
        final T[] validValues, final T defaultValue)
{
    final ParameterDescriptor<T> descriptor;
    onCreate(false);
    try {
        descriptor = new DefaultParameterDescriptor<>(properties, required ? 1 : 0, 1,
                valueClass, valueDomain, validValues, defaultValue);
    } finally {
        onCreate(true);
    }
    return descriptor;
}
 
Example #22
Source File: CC_OperationParameterGroupTest.java    From sis with Apache License 2.0 5 votes vote down vote up
/**
 * Verifies the properties of an operation method parameter.
 *
 * @param  expected  a parameter descriptor containing the expected properties (except remarks).
 * @param  actual    the parameter descriptor to verify.
 */
public static void verifyMethodParameter(final ParameterDescriptor<?> expected,
                                         final ParameterDescriptor<?> actual)
{
    assertEquals("name",          expected.getName(),         actual.getName());
    assertEquals("valueClass",    expected.getValueClass(),   actual.getValueClass());
    assertEquals("validValues",   expected.getValidValues(),  actual.getValidValues());
    assertEquals("unit",          expected.getUnit(),         actual.getUnit());
    assertEquals("minimumOccurs", DEFAULT_OCCURRENCE,         actual.getMinimumOccurs());
    assertEquals("maximumOccurs", DEFAULT_OCCURRENCE,         actual.getMaximumOccurs());
}
 
Example #23
Source File: ParameterBuilder.java    From sis with Apache License 2.0 5 votes vote down vote up
/**
 * Creates a descriptor for floating point values restricted to the given domain.
 *
 * @param  minimumValue  the minimum parameter value (inclusive), or {@link Double#NEGATIVE_INFINITY} if none.
 * @param  maximumValue  the maximum parameter value (inclusive), or {@link Double#POSITIVE_INFINITY} if none.
 * @param  defaultValue  the default value for the parameter, or {@link Double#NaN} if none.
 * @param  unit          the unit for default, minimum and maximum values, or {@code null} if none.
 * @return the parameter descriptor for the given domain of values.
 */
public ParameterDescriptor<Double> createBounded(final double minimumValue, final double maximumValue,
        final double defaultValue, final Unit<?> unit)
{
    final Range<Double> valueDomain;
    if (unit != null) {
        valueDomain = MeasurementRange.create(minimumValue, true, maximumValue, true, unit);
    } else if (minimumValue != Double.NEGATIVE_INFINITY || maximumValue != Double.POSITIVE_INFINITY) {
        valueDomain = NumberRange.create(minimumValue, true, maximumValue, true);
    } else {
        valueDomain = null;
    }
    return create(Double.class, valueDomain, null, valueOf(defaultValue));
}
 
Example #24
Source File: ContextualParameters.java    From sis with Apache License 2.0 5 votes vote down vote up
/**
 * Returns the parameter value of the given name.
 * Before the call to {@link #completeTransform completeTransform(…)},
 * this method can be used for setting parameter values like below:
 *
 * {@preformat java
 *   parameter("Scale factor").setValue(0.9996);   // Scale factor of Universal Transverse Mercator (UTM) projections.
 * }
 *
 * After the call to {@code completeTransform(…)}, the returned parameters are read-only.
 *
 * @param  name  the name of the parameter to search.
 * @return the parameter value for the given name.
 * @throws ParameterNotFoundException if there is no parameter of the given name.
 */
@Override
public synchronized ParameterValue<?> parameter(final String name) throws ParameterNotFoundException {
    final GeneralParameterDescriptor desc = descriptor.descriptor(name);
    if (!(desc instanceof ParameterDescriptor<?>)) {
        throw parameterNotFound(name);
    }
    /*
     * Search for existing parameter instance. This implementation does not scale, but should be okay since
     * the amount of parameters is typically very small (rarely more than 6 parameters in map projections).
     */
    for (int i=0; i < values.length; i++) {
        ParameterValue<?> p = values[i];
        if (p == null) {
            values[i] = p = new ContextualParameter<>((ParameterDescriptor<?>) desc);
            return p;
        }
        if (p.getDescriptor() == desc) {                    // Identity comparison should be okay here.
            return p;
        }
    }
    /*
     * We may reach this point if map projection construction is completed (i.e. 'completeTransform(…)' has
     * been invoked) and the user asks for a parameter which is not one of the parameters that we retained.
     * Returns a parameter initialized to the default value, which is the actual value (otherwise we would
     * have stored that parameter).  Note: we do not bother making the parameter immutable for performance
     * reason. If the user invokes a setter method on the returned parameter, he may get a false impression
     * that this ContextualParameters is still modifiable. We presume that such scenario would be rare.
     */
    if (isFrozen) {
        return ((ParameterDescriptor<?>) desc).createValue();
    }
    /*
     * Should never reach this point. If it happen anyway, this means that the descriptor now accepts
     * more parameters than what it declared at ContextualParameteres construction time, or that some
     * ParameterDescriptor instances changed.
     */
    throw new ParameterNotFoundException(Errors.format(Errors.Keys.UnexpectedChange_1, descriptor.getName()), name);
}
 
Example #25
Source File: CC_OperationParameterGroupTest.java    From sis with Apache License 2.0 5 votes vote down vote up
/**
 * Creates the parameter descriptors equivalent to the result of {@link #unmarshal()}
 * but with value class, units and default values.
 *
 * @param remarks Remarks to associate to the latitude parameter, or {@code null} if none.
 */
private static ParameterDescriptor<?>[] create(final String remarks) {
    final ParameterBuilder builder = new ParameterBuilder();
    builder.setCodeSpace(EPSG, "EPSG").setRequired(true);
    return new ParameterDescriptor<?>[] {
        builder.addIdentifier("8801").addName("Latitude of natural origin") .setRemarks(remarks).create(0, Units.DEGREE),
        builder.addIdentifier("8802").addName("Longitude of natural origin").create(0, Units.DEGREE),
    };
}
 
Example #26
Source File: TensorValues.java    From sis with Apache License 2.0 5 votes vote down vote up
/**
 * Sets all parameter values to the element value in the specified matrix.
 * After this method call, {@link #values} will returns only the elements
 * different from the default value.
 *
 * @param  matrix  the matrix to copy in this group of parameters.
 */
final void setMatrix(final Matrix matrix) {
    final int numRow = matrix.getNumRow();
    final int numCol = matrix.getNumCol();
    dimensions[0].setValue(numRow);
    dimensions[1].setValue(numCol);
    values = null;
    final int[] indices = new int[2];
    for (int j=0; j<numRow; j++) {
        indices[0] = j;
        ParameterValue<?>[] row = null;
        for (int i=0; i<numCol; i++) {
            indices[1] = i;
            ParameterDescriptor<E> descriptor = descriptors.getElementDescriptor(indices);
            final E def = descriptor.getDefaultValue();
            final double element = matrix.getElement(j,i);
            if (!(def instanceof Number) || !Numerics.equalsIgnoreZeroSign(element, ((Number) def).doubleValue())) {
                final ParameterValue<?> value = descriptor.createValue();
                value.setValue(element);
                if (row == null) {
                    row = new ParameterValue<?>[numCol];
                    if (values == null) {
                        values = new ParameterValue<?>[numRow][];
                    }
                    values[j] = row;
                }
                row[i] = value;
            }
        }
    }
}
 
Example #27
Source File: ParameterBuilderTest.java    From sis with Apache License 2.0 5 votes vote down vote up
/**
 * Tests the <cite>"Mercator (variant A)"</cite> example given in Javadoc.
 */
@Test
@DependsOnMethod("testCreate")
@SuppressWarnings("UnnecessaryBoxing")
public void testMercatorProjection() {
    final ParameterBuilder builder = new ParameterBuilder();
    builder.setCodeSpace(Citations.EPSG, "EPSG").setRequired(true);
    final ParameterDescriptor<?>[] parameters = {
        builder.addName("Longitude of natural origin")
               .addName(Citations.OGC, "central_meridian")
               .addName(Citations.GEOTIFF, "NatOriginLong")
               .setRemarks("Some remarks.")               .createBounded(-180, +180, 0, Units.DEGREE),
        builder.addName("Latitude of natural origin")     .createBounded( -80,  +84, 0, Units.DEGREE),
        builder.addName("Scale factor at natural origin") .createStrictlyPositive(1, Units.UNITY),
        builder.addName("False easting")                  .create(0, Units.METRE),
        builder.addName("False northing")                 .create(0, Units.METRE)
    };
    // Tests random properties.
    assertEquals("EPSG",             parameters[1].getName().getCodeSpace());
    assertEquals("False easting",    parameters[3].getName().getCode());
    assertEquals("Some remarks.",    parameters[0].getRemarks().toString());
    assertEquals(Double.valueOf(84), parameters[1].getMaximumValue());
    assertEquals(Units.METRE,        parameters[4].getUnit());
    assertTrue  (                    parameters[1].getAlias().isEmpty());

    final GenericName alias = parameters[0].getAlias().iterator().next();
    assertEquals("central_meridian",     alias.tip().toString());
    assertEquals("OGC",                  alias.head().toString());
    assertEquals("OGC:central_meridian", alias.toString());
}
 
Example #28
Source File: CassiniSoldner.java    From sis with Apache License 2.0 5 votes vote down vote up
/**
 * Work around for RFE #4093999 in Sun's bug database
 * ("Relax constraint on placement of this()/super() call in constructors").
 */
@Workaround(library="JDK", version="1.7")
private static Initializer initializer(final OperationMethod method, final Parameters parameters) {
    final EnumMap<ParameterRole, ParameterDescriptor<Double>> roles = new EnumMap<>(ParameterRole.class);
    roles.put(ParameterRole.CENTRAL_MERIDIAN, LONGITUDE_OF_ORIGIN);
    roles.put(ParameterRole.SCALE_FACTOR,     SCALE_FACTOR);
    roles.put(ParameterRole.FALSE_EASTING,    FALSE_EASTING);
    roles.put(ParameterRole.FALSE_NORTHING,   FALSE_NORTHING);
    return new Initializer(method, parameters, roles, (byte) 0);
}
 
Example #29
Source File: ParameterMarshallingTest.java    From sis with Apache License 2.0 5 votes vote down vote up
/**
 * Marshals the given object, then unmarshals it and compare with the original value.
 *
 * @param  parameter  the parameter to marshal.
 * @param  expected   the expected XML (ignoring {@code xmlns}).
 */
private static void testMarshallAndUnmarshall(final DefaultParameterValue<?> parameter, final String expected)
        throws JAXBException
{
    final String xml = XML.marshal(parameter);
    assertXmlEquals(expected, xml, "xmlns:*");
    final DefaultParameterValue<?> r = (DefaultParameterValue<?>) XML.unmarshal(xml);
    if (!Objects.deepEquals(parameter.getValue(), r.getValue())) {
        // If we enter in this block, then the line below should always fail.
        // But we use this assertion for getting a better error message.
        assertEquals("value", parameter.getValue(), r.getValue());
    }
    assertEquals("unit", parameter.getUnit(), r.getUnit());
    /*
     * Verify the descriptor, especially the 'valueClass' property. That property is not part of GML,
     * so Apache SIS has to rely on some tricks for finding this information (see CC_OperationParameter).
     */
    final ParameterDescriptor<?> reference = parameter.getDescriptor();
    final ParameterDescriptor<?> descriptor = r.getDescriptor();
    assertNotNull("descriptor",                                             descriptor);
    assertEquals ("descriptor.name",          reference.getName(),          descriptor.getName());
    assertEquals ("descriptor.unit",          reference.getUnit(),          descriptor.getUnit());
    assertEquals ("descriptor.valueClass",    reference.getValueClass(),    descriptor.getValueClass());
    assertEquals ("descriptor.minimumOccurs", reference.getMinimumOccurs(), descriptor.getMinimumOccurs());
    assertEquals ("descriptor.maximumOccurs", reference.getMaximumOccurs(), descriptor.getMaximumOccurs());
    Validators.validate(r);
}
 
Example #30
Source File: Polyconic.java    From sis with Apache License 2.0 5 votes vote down vote up
/**
 * Work around for RFE #4093999 in Sun's bug database
 * ("Relax constraint on placement of this()/super() call in constructors").
 */
@Workaround(library="JDK", version="1.8")
private static Initializer initializer(final OperationMethod method, final Parameters parameters) {
    final EnumMap<ParameterRole, ParameterDescriptor<Double>> roles = new EnumMap<>(ParameterRole.class);
    roles.put(ParameterRole.CENTRAL_MERIDIAN, LONGITUDE_OF_ORIGIN);
    roles.put(ParameterRole.FALSE_EASTING,    FALSE_EASTING);
    roles.put(ParameterRole.FALSE_NORTHING,   FALSE_NORTHING);
    return new Initializer(method, parameters, roles, (byte) 0);
}