Search in sources :

Example 51 with ParameterValueGroup

use of org.opengis.parameter.ParameterValueGroup in project OpenTripPlanner by opentripplanner.

the class RasterPopulation method writeGeotiff.

public void writeGeotiff(String fileName, ResultSet results) {
    LOG.info("writing geotiff.");
    float[][] imagePixelData = new float[rows][cols];
    for (int row = 0; row < rows; row++) {
        for (int col = 0; col < cols; col++) {
            int index = row * cols + col;
            float pixel = (float) (results.results[index]);
            if (unitySeconds > 0)
                pixel /= unitySeconds;
            imagePixelData[row][col] = pixel;
        }
    }
    GridCoverage2D coverage = new GridCoverageFactory().create("OTPAnalyst", imagePixelData, refEnvelope);
    try {
        GeoTiffWriteParams wp = new GeoTiffWriteParams();
        wp.setCompressionMode(GeoTiffWriteParams.MODE_EXPLICIT);
        wp.setCompressionType("LZW");
        ParameterValueGroup params = new GeoTiffFormat().getWriteParameters();
        params.parameter(AbstractGridFormat.GEOTOOLS_WRITE_PARAMS.getName().toString()).setValue(wp);
        GeoTiffWriter writer = new GeoTiffWriter(new File(fileName));
        writer.write(coverage, (GeneralParameterValue[]) params.values().toArray(new GeneralParameterValue[1]));
    } catch (Exception e) {
        LOG.error("exception while writing geotiff.", e);
    }
    LOG.info("done writing geotiff.");
}
Also used : GeneralParameterValue(org.opengis.parameter.GeneralParameterValue) GeoTiffFormat(org.geotools.gce.geotiff.GeoTiffFormat) ParameterValueGroup(org.opengis.parameter.ParameterValueGroup) GeoTiffWriteParams(org.geotools.gce.geotiff.GeoTiffWriteParams) GeoTiffWriter(org.geotools.gce.geotiff.GeoTiffWriter) File(java.io.File)

Example 52 with ParameterValueGroup

use of org.opengis.parameter.ParameterValueGroup in project sis by apache.

the class InterpolatedGeocentricTransformTest method createGeodeticTransformation.

/**
 * Creates the transform using the given provider.
 */
final void createGeodeticTransformation(final FranceGeocentricInterpolation provider) throws FactoryException {
    final URL file = FranceGeocentricInterpolationTest.getResourceAsConvertibleURL(FranceGeocentricInterpolationTest.TEST_FILE);
    // Clarke 1880 (IGN)
    final Ellipsoid source = HardCodedDatum.NTF.getEllipsoid();
    // GRS 1980 ellipsoid
    final Ellipsoid target = CommonCRS.ETRS89.ellipsoid();
    final ParameterValueGroup values = provider.getParameters().createValue();
    values.parameter("src_semi_major").setValue(source.getSemiMajorAxis());
    values.parameter("src_semi_minor").setValue(source.getSemiMinorAxis());
    values.parameter("tgt_semi_major").setValue(target.getSemiMajorAxis());
    values.parameter("tgt_semi_minor").setValue(target.getSemiMinorAxis());
    // Automatic conversion from URL to Path.
    values.parameter("Geocentric translation file").setValue(file);
    transform = provider.createMathTransform(DefaultFactories.forBuildin(MathTransformFactory.class), values);
    tolerance = FranceGeocentricInterpolationTest.ANGULAR_TOLERANCE;
}
Also used : ParameterValueGroup(org.opengis.parameter.ParameterValueGroup) Ellipsoid(org.opengis.referencing.datum.Ellipsoid) URL(java.net.URL)

Example 53 with ParameterValueGroup

use of org.opengis.parameter.ParameterValueGroup in project sis by apache.

the class GeodeticObjectParser method parseOperation.

/**
 * Parses a {@code "CoordinateOperation"} element. The syntax is given by
 * <a href="http://docs.opengeospatial.org/is/12-063r5/12-063r5.html#113">WKT 2 specification §17</a>.
 *
 * @param  mode    {@link #FIRST}, {@link #OPTIONAL} or {@link #MANDATORY}.
 * @param  parent  the parent element.
 * @return the {@code "CoordinateOperation"} element as a {@link CoordinateOperation} object.
 * @throws ParseException if the {@code "CoordinateOperation"} element can not be parsed.
 */
private CoordinateOperation parseOperation(final int mode, final Element parent) throws ParseException {
    final Element element = parent.pullElement(mode, WKTKeywords.CoordinateOperation);
    if (element == null) {
        return null;
    }
    final String name = element.pullString("name");
    final CoordinateReferenceSystem sourceCRS = parseCoordinateReferenceSystem(element, MANDATORY, WKTKeywords.SourceCRS);
    final CoordinateReferenceSystem targetCRS = parseCoordinateReferenceSystem(element, MANDATORY, WKTKeywords.TargetCRS);
    final CoordinateReferenceSystem interpolationCRS = parseCoordinateReferenceSystem(element, OPTIONAL, WKTKeywords.InterpolationCRS);
    final OperationMethod method = parseMethod(element, WKTKeywords.Method);
    final Element accuracy = element.pullElement(OPTIONAL, WKTKeywords.OperationAccuracy);
    final Map<String, Object> properties = parseMetadataAndClose(element, name, method);
    final ParameterValueGroup parameters = method.getParameters().createValue();
    parseParameters(element, parameters, null, null);
    properties.put(ReferencingServices.PARAMETERS_KEY, parameters);
    if (accuracy != null) {
        properties.put(CoordinateOperation.COORDINATE_OPERATION_ACCURACY_KEY, TransformationAccuracy.create(accuracy.pullDouble("accuracy")));
        accuracy.close(ignoredElements);
    }
    try {
        return referencing.createSingleOperation(properties, sourceCRS, targetCRS, interpolationCRS, method, opFactory);
    } catch (FactoryException e) {
        throw element.parseFailed(e);
    }
}
Also used : ParameterValueGroup(org.opengis.parameter.ParameterValueGroup) FactoryException(org.opengis.util.FactoryException) IdentifiedObject(org.opengis.referencing.IdentifiedObject)

Example 54 with ParameterValueGroup

use of org.opengis.parameter.ParameterValueGroup in project sis by apache.

the class UnmodifiableParameterValueGroup method groups.

/**
 * Returns all subgroups with the specified name.
 */
@Override
public List<ParameterValueGroup> groups(final String name) throws ParameterNotFoundException {
    ArgumentChecks.ensureNonNull("name", name);
    final List<ParameterValueGroup> groups = new ArrayList<>(4);
    for (final GeneralParameterValue value : values) {
        if (value instanceof ParameterValueGroup) {
            if (IdentifiedObjects.isHeuristicMatchForName(value.getDescriptor(), name)) {
                groups.add((ParameterValueGroup) value);
            }
        }
    }
    if (groups.isEmpty()) {
        if (!(descriptor.descriptor(name) instanceof ParameterDescriptorGroup)) {
            throw new ParameterNotFoundException(Resources.format(Resources.Keys.ParameterNotFound_2, Verifier.getDisplayName(descriptor), name), name);
        }
    }
    return groups;
}
Also used : GeneralParameterValue(org.opengis.parameter.GeneralParameterValue) ParameterValueGroup(org.opengis.parameter.ParameterValueGroup) ParameterDescriptorGroup(org.opengis.parameter.ParameterDescriptorGroup) ArrayList(java.util.ArrayList) UnmodifiableArrayList(org.apache.sis.internal.util.UnmodifiableArrayList) ParameterNotFoundException(org.opengis.parameter.ParameterNotFoundException)

Example 55 with ParameterValueGroup

use of org.opengis.parameter.ParameterValueGroup in project sis by apache.

the class StandardDefinitions method createUniversal.

/**
 * Creates a Universal Transverse Mercator (UTM) or a Universal Polar Stereographic (UPS) projected CRS
 * using the Apache SIS factory implementation. This method restricts the factory to SIS implementation
 * instead than arbitrary factory in order to meet the contract saying that {@link CommonCRS} methods
 * should never fail.
 *
 * @param code       the EPSG code, or 0 if none.
 * @param baseCRS    the geographic CRS on which the projected CRS is based.
 * @param isUTM      {@code true} for UTM or {@code false} for UPS. Note: redundant with the given latitude.
 * @param latitude   a latitude in the zone of the desired projection, to be snapped to 0°, 90°S or 90°N.
 * @param longitude  a longitude in the zone of the desired projection, to be snapped to UTM central meridian.
 * @param derivedCS  the projected coordinate system.
 */
static ProjectedCRS createUniversal(final int code, final GeographicCRS baseCRS, final boolean isUTM, final double latitude, final double longitude, final CartesianCS derivedCS) {
    final OperationMethod method;
    try {
        method = DefaultFactories.forBuildin(MathTransformFactory.class, DefaultMathTransformFactory.class).getOperationMethod(isUTM ? TransverseMercator.NAME : PolarStereographicA.NAME);
    } catch (NoSuchIdentifierException e) {
        // Should not happen with SIS implementation.
        throw new IllegalStateException(e);
    }
    final ParameterValueGroup parameters = method.getParameters().createValue();
    String name = isUTM ? TransverseMercator.Zoner.UTM.setParameters(parameters, latitude, longitude) : PolarStereographicA.setParameters(parameters, latitude >= 0);
    final DefaultConversion conversion = new DefaultConversion(properties(0, name, null, false), method, null, parameters);
    name = baseCRS.getName().getCode() + " / " + name;
    return new DefaultProjectedCRS(properties(code, name, null, false), baseCRS, conversion, derivedCS);
}
Also used : ParameterValueGroup(org.opengis.parameter.ParameterValueGroup) DefaultConversion(org.apache.sis.referencing.operation.DefaultConversion) NoSuchIdentifierException(org.opengis.util.NoSuchIdentifierException) DefaultProjectedCRS(org.apache.sis.referencing.crs.DefaultProjectedCRS) OperationMethod(org.opengis.referencing.operation.OperationMethod)

Aggregations

ParameterValueGroup (org.opengis.parameter.ParameterValueGroup)98 Test (org.junit.Test)54 DependsOnMethod (org.apache.sis.test.DependsOnMethod)27 GeneralParameterValue (org.opengis.parameter.GeneralParameterValue)12 ProjectedCRS (org.opengis.referencing.crs.ProjectedCRS)11 OperationMethod (org.opengis.referencing.operation.OperationMethod)11 ParameterValue (org.opengis.parameter.ParameterValue)8 GeneralParameterDescriptor (org.opengis.parameter.GeneralParameterDescriptor)7 ParameterNotFoundException (org.opengis.parameter.ParameterNotFoundException)7 SingleOperation (org.opengis.referencing.operation.SingleOperation)6 FactoryException (org.opengis.util.FactoryException)6 DefaultGeodeticDatum (org.apache.sis.referencing.datum.DefaultGeodeticDatum)5 IdentifiedObject (org.opengis.referencing.IdentifiedObject)5 Matrix (org.opengis.referencing.operation.Matrix)5 ArrayList (java.util.ArrayList)4 DefaultConversion (org.apache.sis.referencing.operation.DefaultConversion)4 ParameterDescriptorGroup (org.opengis.parameter.ParameterDescriptorGroup)4 CoordinateReferenceSystem (org.opengis.referencing.crs.CoordinateReferenceSystem)4 CoordinateOperation (org.opengis.referencing.operation.CoordinateOperation)4 URL (java.net.URL)3