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);
}
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);
}
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);
}
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);
}
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());
}
Aggregations