Search in sources :

Example 96 with ProcessDescriptor

use of org.geotoolkit.process.ProcessDescriptor in project geotoolkit by Geomatys.

the class ClipGeometryTest method testClipGeometry.

@Test
public void testClipGeometry() throws ProcessException, NoSuchIdentifierException, FactoryException {
    // Inputs
    final FeatureCollection featureList = buildFeatureList();
    final Geometry geometryClip = buildGeometryClip();
    // Process
    ProcessDescriptor desc = ProcessFinder.getProcessDescriptor(GeotkProcessingRegistry.NAME, "vector:clipGeometry");
    ParameterValueGroup in = desc.getInputDescriptor().createValue();
    in.parameter("feature_in").setValue(featureList);
    in.parameter("clip_geometry_in").setValue(geometryClip);
    org.geotoolkit.process.Process proc = desc.createProcess(in);
    // Features out
    final FeatureCollection featureListOut = (FeatureCollection) proc.call().parameter("feature_out").getValue();
    // Expected Features out
    final FeatureCollection featureListResult = buildResultList();
    compare(featureListResult, featureListOut);
}
Also used : Geometry(org.locationtech.jts.geom.Geometry) FeatureCollection(org.geotoolkit.storage.feature.FeatureCollection) ParameterValueGroup(org.opengis.parameter.ParameterValueGroup) ProcessDescriptor(org.geotoolkit.process.ProcessDescriptor) AbstractProcessTest(org.geotoolkit.processing.vector.AbstractProcessTest) Test(org.junit.Test)

Example 97 with ProcessDescriptor

use of org.geotoolkit.process.ProcessDescriptor in project geotoolkit by Geomatys.

the class DifferenceTest method testDifference.

@Test
public void testDifference() throws ProcessException, NoSuchIdentifierException, FactoryException {
    // Inputs
    final FeatureCollection featureList = buildFeatureList();
    final FeatureCollection featuresClip = buildFeatureClip();
    // Process
    ProcessDescriptor desc = ProcessFinder.getProcessDescriptor(GeotkProcessingRegistry.NAME, "vector:difference");
    ParameterValueGroup in = desc.getInputDescriptor().createValue();
    in.parameter("feature_in").setValue(featureList);
    in.parameter("feature_diff").setValue(featuresClip);
    org.geotoolkit.process.Process proc = desc.createProcess(in);
    // Features out
    final FeatureCollection featureListOut = (FeatureCollection) proc.call().parameter("feature_out").getValue();
    // Expected Features out
    final FeatureCollection featureListResult = buildResultList();
    compare(featureListResult, featureListOut);
}
Also used : FeatureCollection(org.geotoolkit.storage.feature.FeatureCollection) ParameterValueGroup(org.opengis.parameter.ParameterValueGroup) ProcessDescriptor(org.geotoolkit.process.ProcessDescriptor) AbstractProcessTest(org.geotoolkit.processing.vector.AbstractProcessTest) Test(org.junit.Test)

Example 98 with ProcessDescriptor

use of org.geotoolkit.process.ProcessDescriptor in project geotoolkit by Geomatys.

the class DifferenceGeometryTest method testDiffGeometry.

@Test
public void testDiffGeometry() throws ProcessException, NoSuchIdentifierException, FactoryException {
    // Inputs
    final FeatureCollection featureList = buildFeatureList();
    final Geometry geometryClip = buildGeometryClip();
    // Process
    ProcessDescriptor desc = ProcessFinder.getProcessDescriptor(GeotkProcessingRegistry.NAME, "vector:diffGeometry");
    ParameterValueGroup in = desc.getInputDescriptor().createValue();
    in.parameter(DifferenceGeometryDescriptor.FEATURE_IN.getName().getCode()).setValue(featureList);
    in.parameter(DifferenceGeometryDescriptor.DIFF_GEOMETRY_IN.getName().getCode()).setValue(geometryClip);
    org.geotoolkit.process.Process proc = desc.createProcess(in);
    // Features out
    final FeatureCollection featureListOut = (FeatureCollection) proc.call().parameter("feature_out").getValue();
    // Expected Features out
    final FeatureCollection featureListResult = buildResultList();
    compare(featureListResult, featureListOut);
}
Also used : Geometry(org.locationtech.jts.geom.Geometry) FeatureCollection(org.geotoolkit.storage.feature.FeatureCollection) ParameterValueGroup(org.opengis.parameter.ParameterValueGroup) ProcessDescriptor(org.geotoolkit.process.ProcessDescriptor) AbstractProcessTest(org.geotoolkit.processing.vector.AbstractProcessTest) Test(org.junit.Test)

Example 99 with ProcessDescriptor

use of org.geotoolkit.process.ProcessDescriptor in project geotoolkit by Geomatys.

the class CachedPatternSymbolizer method getMasks.

public Map.Entry<FeatureSet, MutableStyle> getMasks(final GridCoverage coverage) throws IOException, TransformException {
    final List<Feature> features = new ArrayList<>();
    final Map<NumberRange, List<Symbolizer>> styles = new LinkedHashMap<>();
    final Map<NumberRange, Integer> stylesIndexes = new LinkedHashMap<>();
    final Map<Expression, List<Symbolizer>> categorizes = styleElement.getRanges();
    final Expression[] steps = categorizes.keySet().toArray(new Expression[categorizes.size()]);
    Arrays.sort(steps, new Comparator<Expression>() {

        @Override
        public int compare(Expression t1, Expression t2) {
            if (t1 == null) {
                return -1;
            } else if (t2 == null) {
                return +1;
            }
            double d1 = ((Number) t1.apply(null)).doubleValue();
            double d2 = ((Number) t2.apply(null)).doubleValue();
            double res = d1 - d2;
            if (res < 0) {
                return -1;
            } else if (res > 0) {
                return +1;
            } else {
                return 0;
            }
        }
    });
    // fill the numberranges ------------------------------------------------
    double last = Double.NEGATIVE_INFINITY;
    double end = Double.POSITIVE_INFINITY;
    NumberRange interval;
    int i = 0;
    int index = 0;
    for (; i < steps.length - 1; i++) {
        end = ((Number) steps[i + 1].apply(null)).doubleValue();
        interval = NumberRange.create(last, true, end, false);
        styles.put(interval, categorizes.get(steps[i]));
        stylesIndexes.put(interval, index++);
        last = end;
    }
    // last element
    end = Double.POSITIVE_INFINITY;
    NumberRange<Double> lastRange = NumberRange.create(last, true, end, true);
    styles.put(lastRange, categorizes.get(steps[i]));
    stylesIndexes.put(lastRange, index++);
    // calculate the polygons -----------------------------------------------
    final ProcessDescriptor descriptor = CoverageToVectorDescriptor.INSTANCE;
    final Integer band = ((Number) styleElement.getChannel().apply(null)).intValue();
    final ParameterValueGroup input = descriptor.getInputDescriptor().createValue();
    input.parameter(CoverageToVectorDescriptor.COVERAGE.getName().getCode()).setValue(coverage);
    final Set<NumberRange> nrs = styles.keySet();
    input.parameter(CoverageToVectorDescriptor.RANGES.getName().getCode()).setValue(nrs.toArray(new NumberRange[nrs.size()]));
    input.parameter(CoverageToVectorDescriptor.BAND.getName().getCode()).setValue(band);
    final Process process = descriptor.createProcess(input);
    final Geometry[] polygons;
    try {
        polygons = (Geometry[]) process.call().parameter(CoverageToVectorDescriptor.GEOMETRIES.getName().getCode()).getValue();
    } catch (ProcessException ex) {
        Logger.getLogger("org.geotoolkit.display2d.ext.pattern").log(Level.WARNING, null, ex);
        throw new IOException(ex.getMessage(), ex);
    }
    // build the global style -----------------------------------------------
    final MutableStyle style = GO2Utilities.STYLE_FACTORY.style();
    final MutableFeatureTypeStyle fts = GO2Utilities.STYLE_FACTORY.featureTypeStyle();
    style.featureTypeStyles().add(fts);
    int idx = 0;
    for (List<Symbolizer> lst : styles.values()) {
        MutableRule rule = GO2Utilities.STYLE_FACTORY.rule();
        rule.symbolizers().addAll(lst);
        rule.setFilter(GO2Utilities.FILTER_FACTORY.equal(GO2Utilities.FILTER_FACTORY.property("category"), GO2Utilities.FILTER_FACTORY.literal(idx), true, MatchAction.ANY));
        fts.rules().add(rule);
        idx++;
    }
    // build the features ---------------------------------------------------
    final CoordinateReferenceSystem crs = coverage.getCoordinateReferenceSystem();
    final FeatureTypeBuilder sftBuilder = new FeatureTypeBuilder();
    final String geometryField = "geometry";
    sftBuilder.setName("DynamicFeature");
    sftBuilder.addAttribute(Integer.class).setName("id").addRole(AttributeRole.IDENTIFIER_COMPONENT);
    sftBuilder.addAttribute(Geometry.class).setName(geometryField).setCRS(crs).addRole(AttributeRole.DEFAULT_GEOMETRY);
    sftBuilder.addAttribute(Integer.class).setName("category");
    final FeatureType sft = sftBuilder.build();
    int id = 0;
    for (Geometry entry : polygons) {
        if (entry == null)
            continue;
        NumberRange numberRange = (NumberRange) entry.getUserData();
        idx = stylesIndexes.get(numberRange);
        entry.setUserData(crs);
        final Feature feature = sft.newInstance();
        feature.setPropertyValue(geometryField, entry);
        feature.setPropertyValue("id", id++);
        feature.setPropertyValue("category", idx);
        features.add(feature);
    }
    return new AbstractMap.SimpleEntry<>(new InMemoryFeatureSet(sft, features), style);
}
Also used : FeatureType(org.opengis.feature.FeatureType) InMemoryFeatureSet(org.geotoolkit.storage.memory.InMemoryFeatureSet) ParameterValueGroup(org.opengis.parameter.ParameterValueGroup) ArrayList(java.util.ArrayList) Process(org.geotoolkit.process.Process) Feature(org.opengis.feature.Feature) LinkedHashMap(java.util.LinkedHashMap) MutableStyle(org.geotoolkit.style.MutableStyle) List(java.util.List) ArrayList(java.util.ArrayList) CoordinateReferenceSystem(org.opengis.referencing.crs.CoordinateReferenceSystem) FeatureTypeBuilder(org.apache.sis.feature.builder.FeatureTypeBuilder) IOException(java.io.IOException) CachedSymbolizer(org.geotoolkit.display2d.style.CachedSymbolizer) Symbolizer(org.opengis.style.Symbolizer) NumberRange(org.apache.sis.measure.NumberRange) Geometry(org.locationtech.jts.geom.Geometry) MutableRule(org.geotoolkit.style.MutableRule) ProcessException(org.geotoolkit.process.ProcessException) Expression(org.opengis.filter.Expression) MutableFeatureTypeStyle(org.geotoolkit.style.MutableFeatureTypeStyle) ProcessDescriptor(org.geotoolkit.process.ProcessDescriptor)

Example 100 with ProcessDescriptor

use of org.geotoolkit.process.ProcessDescriptor in project geotoolkit by Geomatys.

the class ChainProcessDemo method main.

public static void main(String[] args) throws ProcessException {
    // produce a chain equivalent to :  ($a + 10) / $b
    final Chain chain = new Chain("myChain");
    // input/out/constants parameters
    final Parameter a = chain.addInputParameter("a", Double.class, "title", "desc", 1, 1, null);
    final Parameter b = chain.addInputParameter("b", Double.class, "title", "desc", 1, 1, null);
    final Parameter r = chain.addOutputParameter("r", Double.class, "title", "desc", 1, 1, null);
    final Constant c = chain.addConstant(1, Double.class, 10d);
    // chain blocks
    final ElementProcess add = chain.addProcessElement(2, "math", "add");
    final ElementProcess divide = chain.addProcessElement(3, "math", "divide");
    // execution flow links
    chain.addFlowLink(Element.BEGIN.getId(), add.getId());
    chain.addFlowLink(add.getId(), divide.getId());
    chain.addFlowLink(divide.getId(), Element.END.getId());
    // data flow links
    chain.addDataLink(Element.BEGIN.getId(), a.getCode(), add.getId(), "first");
    chain.addDataLink(c.getId(), "", add.getId(), "second");
    chain.addDataLink(add.getId(), "result", divide.getId(), "first");
    chain.addDataLink(Element.BEGIN.getId(), b.getCode(), divide.getId(), "second");
    chain.addDataLink(divide.getId(), "result", Element.END.getId(), r.getCode());
    // ////////////////// execute the chain /////////////////////////////////
    // create a process descriptor to use it like any process.
    final ProcessDescriptor desc = new ChainProcessDescriptor(chain, new DefaultDataIdentification());
    // input params
    final ParameterValueGroup input = desc.getInputDescriptor().createValue();
    input.parameter("a").setValue(15d);
    input.parameter("b").setValue(2d);
    final org.geotoolkit.process.Process process = desc.createProcess(input);
    final ParameterValueGroup result = process.call();
    System.out.println(result.parameter("r").getValue());
}
Also used : ElementProcess(org.geotoolkit.processing.chain.model.ElementProcess) Chain(org.geotoolkit.processing.chain.model.Chain) ParameterValueGroup(org.opengis.parameter.ParameterValueGroup) Constant(org.geotoolkit.processing.chain.model.Constant) ChainProcessDescriptor(org.geotoolkit.processing.chain.ChainProcessDescriptor) Parameter(org.geotoolkit.processing.chain.model.Parameter) DefaultDataIdentification(org.apache.sis.metadata.iso.identification.DefaultDataIdentification) ChainProcessDescriptor(org.geotoolkit.processing.chain.ChainProcessDescriptor) ProcessDescriptor(org.geotoolkit.process.ProcessDescriptor)

Aggregations

ProcessDescriptor (org.geotoolkit.process.ProcessDescriptor)136 ParameterValueGroup (org.opengis.parameter.ParameterValueGroup)121 Test (org.junit.Test)108 AbstractProcessTest (org.geotoolkit.processing.AbstractProcessTest)62 Geometry (org.locationtech.jts.geom.Geometry)43 GeometryFactory (org.locationtech.jts.geom.GeometryFactory)33 Coordinate (org.locationtech.jts.geom.Coordinate)32 LinearRing (org.locationtech.jts.geom.LinearRing)31 Process (org.geotoolkit.process.Process)30 CoordinateReferenceSystem (org.opengis.referencing.crs.CoordinateReferenceSystem)20 AbstractProcessTest (org.geotoolkit.processing.vector.AbstractProcessTest)18 GridCoverage (org.apache.sis.coverage.grid.GridCoverage)17 FeatureCollection (org.geotoolkit.storage.feature.FeatureCollection)15 GridCoverageBuilder (org.apache.sis.coverage.grid.GridCoverageBuilder)14 GridGeometry (org.apache.sis.coverage.grid.GridGeometry)14 FeatureSet (org.apache.sis.storage.FeatureSet)14 BufferedImage (java.awt.image.BufferedImage)13 RenderedImage (java.awt.image.RenderedImage)13 SampleDimension (org.apache.sis.coverage.SampleDimension)13 MathTransform (org.opengis.referencing.operation.MathTransform)13