Search in sources :

Example 6 with PixelInCell

use of org.opengis.referencing.datum.PixelInCell in project geotoolkit by Geomatys.

the class CoverageToFeatureTest method coverageToFeatureTestPixelCenter.

/**
 * Test coverageToFeature process with a PixelInCell.CELL_CENTER coverage
 * @throws NoSuchAuthorityCodeException
 * @throws FactoryException
 */
@Test
public void coverageToFeatureTestPixelCenter() throws NoSuchAuthorityCodeException, FactoryException, ProcessException {
    final PixelInCell pixPos = PixelInCell.CELL_CENTER;
    final GridCoverageResource reader = buildResource(pixPos);
    // Process
    final ProcessDescriptor desc = ProcessFinder.getProcessDescriptor(GeotkProcessingRegistry.NAME, CoverageToFeaturesDescriptor.NAME);
    final ParameterValueGroup in = desc.getInputDescriptor().createValue();
    in.parameter("reader_in").setValue(reader);
    final Process proc = desc.createProcess(in);
    // Features out
    final Collection<Feature> featureListOut = (Collection<Feature>) proc.call().parameter("feature_out").getValue();
    final List<Feature> featureListResult = (List<Feature>) buildFCResultPixelCenter();
    assertEquals(featureListResult.get(0).getType(), featureListOut.iterator().next().getType());
    assertEquals(featureListOut.size(), featureListResult.size());
    final Iterator<Feature> iteratorOut = featureListOut.iterator();
    final Iterator<Feature> iteratorResult = featureListResult.iterator();
    final ArrayList<Geometry> geomsOut = new ArrayList<>();
    int itOut = 0;
    while (iteratorOut.hasNext()) {
        Feature featureOut = iteratorOut.next();
        geomsOut.add((Geometry) featureOut.getPropertyValue("cellgeom"));
        geomsOut.add((Geometry) featureOut.getPropertyValue("position"));
    }
    final ArrayList<Geometry> geomsResult = new ArrayList<>();
    int itResult = 0;
    while (iteratorResult.hasNext()) {
        Feature featureResult = iteratorResult.next();
        geomsResult.add((Geometry) featureResult.getPropertyValue("cellgeom"));
        geomsResult.add((Geometry) featureResult.getPropertyValue("position"));
    }
    assertEquals(geomsResult.size(), geomsOut.size());
    for (int i = 0; i < geomsResult.size(); i++) {
        Geometry gOut = geomsOut.get(i);
        Geometry gResult = geomsResult.get(i);
        assertArrayEquals(gResult.getCoordinates(), gOut.getCoordinates());
    }
}
Also used : ParameterValueGroup(org.opengis.parameter.ParameterValueGroup) ArrayList(java.util.ArrayList) Process(org.geotoolkit.process.Process) Feature(org.opengis.feature.Feature) Point(org.locationtech.jts.geom.Point) PixelInCell(org.opengis.referencing.datum.PixelInCell) Geometry(org.locationtech.jts.geom.Geometry) GridGeometry(org.apache.sis.coverage.grid.GridGeometry) CellGeometry(org.opengis.metadata.spatial.CellGeometry) AbstractGridCoverageResource(org.apache.sis.storage.AbstractGridCoverageResource) GridCoverageResource(org.apache.sis.storage.GridCoverageResource) Collection(java.util.Collection) ProcessDescriptor(org.geotoolkit.process.ProcessDescriptor) List(java.util.List) ArrayList(java.util.ArrayList) AbstractProcessTest(org.geotoolkit.processing.AbstractProcessTest) Test(org.junit.Test)

Aggregations

PixelInCell (org.opengis.referencing.datum.PixelInCell)6 GridExtent (org.apache.sis.coverage.grid.GridExtent)3 GridGeometry (org.apache.sis.coverage.grid.GridGeometry)3 MathTransform (org.opengis.referencing.operation.MathTransform)3 SampleDimension (org.apache.sis.coverage.SampleDimension)2 Point (org.locationtech.jts.geom.Point)2 Feature (org.opengis.feature.Feature)2 Envelope (org.opengis.geometry.Envelope)2 PixelOrientation (org.opengis.metadata.spatial.PixelOrientation)2 CoordinateReferenceSystem (org.opengis.referencing.crs.CoordinateReferenceSystem)2 Matrix (org.opengis.referencing.operation.Matrix)2 IOException (java.io.IOException)1 ArrayList (java.util.ArrayList)1 Collection (java.util.Collection)1 HashMap (java.util.HashMap)1 List (java.util.List)1 Map (java.util.Map)1 ImageReader (javax.imageio.ImageReader)1 GridCoverage (org.apache.sis.coverage.grid.GridCoverage)1 GridCoverageBuilder (org.apache.sis.coverage.grid.GridCoverageBuilder)1