LRSGeocodeProcess implements VectorProcess { @DescribeResult(name = "result", description = "Output feature collection") public FeatureCollection execute( @DescribeParameter(name = "features", description = "Input feature collection") FeatureCollection featureCollection, @DescribeParameter(name = "from_measure_attb", description = "Attribute providing start measure of feature") String fromMeasureAttb, @DescribeParameter(name = "to_measure_attb", description = "Attribute providing end measure of feature") String toMeasureAttb, @DescribeParameter(name = "measure", description = "Measure of the point along the feature to be computed") Double measure) throws ProcessException { DefaultFeatureCollection results = new DefaultFeatureCollection(); try { if (featureCollection == null || featureCollection.size() == 0) { LOGGER.info("No features provided in request"); return results; } if (fromMeasureAttb == null || featureCollection.getSchema().getDescriptor(fromMeasureAttb) == null) { throw new ProcessException( "The from_measure_attb parameter was not provided or not defined in schema"); } if (toMeasureAttb == null || featureCollection.getSchema().getDescriptor(toMeasureAttb) == null) { throw new ProcessException("The to_measure_attb parameter was not provided"); } if (measure == null) { throw new ProcessException("The measure parameter was not provided"); } SimpleFeatureType targetFeatureType = createTargetFeatureType(featureCollection .getSchema()); FeatureIterator<Feature> featureIterator = null; try { featureIterator = featureCollection.features(); Feature feature = featureIterator.next(); Double featureFromMeasure = (Double) feature.getProperty(fromMeasureAttb) .getValue(); Double featureToMeasure = (Double) feature.getProperty(toMeasureAttb).getValue(); LengthIndexedLine lengthIndexedLine = new LengthIndexedLine((Geometry) feature .getDefaultGeometryProperty().getValue()); double featureLength = featureToMeasure - featureFromMeasure; double startOffset = measure - featureFromMeasure; double calcLength = ((Geometry) feature.getDefaultGeometryProperty().getValue()) .getLength(); if (calcLength == 0) { LOGGER.info("Edge feature has zero length"); return results; } if (featureLength == 0) { LOGGER.info("Requested feature has zero length"); return results; } Coordinate point = lengthIndexedLine.extractPoint(startOffset * calcLength / featureLength); results.add(createTargetFeature(feature, targetFeatureType, point)); } finally { if (featureIterator != null) featureIterator.close(); } return results; } catch (ProcessException e) { throw e; } catch (Throwable e) { LOGGER.warning("Error executing method: " + e); throw new ProcessException("Error executing method: " + e, e); } }  @DescribeResult(name = "result", description = "Output feature collection") FeatureCollection execute(
            @DescribeParameter(name = "features", description = "Input feature collection") FeatureCollection featureCollection,
            @DescribeParameter(name = "from_measure_attb", description = "Attribute providing start measure of feature") String fromMeasureAttb,
            @DescribeParameter(name = "to_measure_attb", description = "Attribute providing end measure of feature") String toMeasureAttb,
            @DescribeParameter(name = "measure", description = "Measure of the point along the feature to be computed") Double measure);  }
@Test public void testBadParamFromLrs() throws Exception { SimpleFeatureSource source = featureSource.getFeatureSource("lrssimple"); LRSGeocodeProcess process = new LRSGeocodeProcess(); SimpleFeatureCollection origional = source.getFeatures(); try { FeatureCollection result = process.execute(origional, "from_lrs_bad", "to_lrs", 1.0); Assert.fail("Expected error from bad from_lrs name"); } catch (ProcessException e) { } }
@Test public void testBadParamToLrs() throws Exception { SimpleFeatureSource source = featureSource.getFeatureSource("lrssimple"); LRSGeocodeProcess process = new LRSGeocodeProcess(); SimpleFeatureCollection origional = source.getFeatures(); try { FeatureCollection result = process.execute(origional, "from_lrs", "to_lrs_bad", 1.0); Assert.fail("Expected error from bad to_lrs name"); } catch (ProcessException e) { } }
@Test public void testnullParamFromLrs() throws Exception { SimpleFeatureSource source = featureSource.getFeatureSource("lrssimple"); LRSGeocodeProcess process = new LRSGeocodeProcess(); SimpleFeatureCollection origional = source.getFeatures(); try { FeatureCollection result = process.execute(origional, null, "to_lrs", 1.0); Assert.fail("Expected error from bad from_lrs name"); } catch (ProcessException e) { } }
@Test public void testNullParamToLrs() throws Exception { SimpleFeatureSource source = featureSource.getFeatureSource("lrssimple"); LRSGeocodeProcess process = new LRSGeocodeProcess(); SimpleFeatureCollection origional = source.getFeatures(); try { FeatureCollection result = process.execute(origional, "from_lrs", null, 1.0); Assert.fail("Expected error from bad to_lrs name"); } catch (ProcessException e) { } }
@Test public void testBadMeasure() throws Exception { SimpleFeatureSource source = featureSource.getFeatureSource("lrssimple"); LRSGeocodeProcess process = new LRSGeocodeProcess(); SimpleFeatureCollection origional = source.getFeatures(); try { FeatureCollection result = process.execute(origional, "from_lrs", "to_lrs_bad", null); Assert.fail("Expected error from bad measure value"); } catch (ProcessException e) { } }
@Test public void testNoFeaturesGiven() throws Exception { LRSGeocodeProcess process = new LRSGeocodeProcess(); FeatureCollection origional = FeatureCollections.newCollection(); FeatureCollection result = process.execute(origional, "from_lrs", "to_lrs", 1.0); Assert.assertEquals(0, result.size()); }
@Test public void testGoodGeocode() throws Exception { SimpleFeatureSource source = featureSource.getFeatureSource("lrssimple"); LRSGeocodeProcess process = new LRSGeocodeProcess(); SimpleFeatureCollection origional = source.getFeatures(); FeatureCollection result = process.execute(origional, "from_lrs", "to_lrs", 1.0); Assert.assertEquals(1, result.size()); Feature feature = result.features().next(); Point point = (Point) feature.getDefaultGeometryProperty().getValue(); Assert.assertEquals(1.0, point.getX(), 0.0); Assert.assertEquals(0.0, point.getY(), 0.0); }