rdf4j-postgis  Version 0.1.0.0
Segmentize Class Reference

Segmentizes a LineString into segments given a segment length. More...

Inheritance diagram for Segmentize:
Collaboration diagram for Segmentize:

Public Member Functions

String getURI ()
 
List< LineString > createSegments (Geometry track, double segmentLength) throws NoSuchAuthorityCodeException, FactoryException
 
Value evaluate (ValueFactory valueFactory, Value... args) throws ValueExprEvaluationException
 

Protected Member Functions

Geometry relation (Geometry geom, Double value)
 

Detailed Description

Segmentizes a LineString into segments given a segment length.

Member Function Documentation

◆ createSegments()

List<LineString> createSegments ( Geometry  track,
double  segmentLength 
) throws NoSuchAuthorityCodeException, FactoryException
41  {
42 
43  //GeometryFactory geometryFactory = new GeometryFactory(new PrecisionModel(PrecisionModel.FLOATING));
44  List<LineString> segments = new ArrayList<>();
45  /*SRSInfo srsInfo = track.getSrsInfo();
46 
47  List<Coordinate> coordinates = new ArrayList<>(track.getCoordinates().length);
48  Collections.addAll(coordinates, track.getCoordinates());
49 
50  double accumulatedLength = 0;
51  List<Coordinate> lastSegment = new ArrayList<>();
52 
53  Iterator<Coordinate> itCoordinates = coordinates.iterator();
54 
55  for (int i = 0; itCoordinates.hasNext() && i < coordinates.size() - 1; i++) {
56  Coordinate c1 = coordinates.get(i);
57  Coordinate c2 = coordinates.get(i + 1);
58 
59  lastSegment.add(c1);
60 
61  double length;
62  //Check for geographic or planar distance.
63  //Does the rest of the calculation take into consideration geographic is non-linear in X/Y relationship?
64  if (srsInfo.isGeographic()) {
65  length = GreatCircleDistance.haversineFormula(c1, c2);
66  } else {
67  length = c1.distance(c2);
68  }
69 
70  if (length + accumulatedLength >= segmentLength) {
71  double offsetLength = segmentLength - accumulatedLength;
72  double ratio = offsetLength / length;
73  double dx = c2.x - c1.x;
74  double dy = c2.y - c1.y;
75 
76  Coordinate segmentationPoint = new Coordinate(c1.x + (dx * ratio), c1.y + (dy * ratio));
77 
78  lastSegment.add(segmentationPoint); // Last point of the segment is the segmentation point
79  segments.add(geometryFactory.createLineString(lastSegment.toArray(new Coordinate[lastSegment.size()])));
80 
81  lastSegment = new ArrayList<>(); // Resets the variable since a new segment will be built
82  accumulatedLength = 0D;
83  coordinates.add(i + 1, segmentationPoint);
84  } else {
85  accumulatedLength += length;
86  }
87  }
88 
89  lastSegment.add(coordinates.get(coordinates.size() - 1)); // Because the last one is never added in the loop above
90  segments.add(geometryFactory.createLineString(lastSegment.toArray(new Coordinate[lastSegment.size()])));
91  */
92  return segments;
93  }

Referenced by Segmentize.relation().

◆ evaluate()

Value evaluate ( ValueFactory  valueFactory,
Value...  args 
) throws ValueExprEvaluationException
inherited
16  {
17  if (args.length != 2) {
18  throw new ValueExprEvaluationException(getURI() + " requires exactly 2 arguments, got " + args.length);
19  }
20 
21  LiteralType l=LiteralRegistry.getLiteral(((Literal)args[0]).getDatatype().toString());
22  Double value=Double.valueOf(args[1].stringValue());
23  if(l instanceof VectorLiteral) {
24  Geometry geom=((VectorLiteral)l).read(args[0].stringValue());
25  Geometry result = relation(geom,value);
26  return valueFactory.createLiteral(((VectorLiteral) l).unparse(result),((Literal)args[0]).getDatatype());
27  }
28  throw new ValueExprEvaluationException("Argument given is not a geometry literal");
29  }

References LiteralRegistry.getLiteral(), and GeometricModifierDoubleFunction.relation().

Referenced by DensifyTest.testDensify(), EnsureClosedTest.testEnsureClosed(), EnsureClosedTest.testEnsureClosed2(), RemoveGeometryTest.testRemoveGeometry1(), RemoveGeometryTest.testRemoveGeometry1Z(), RemoveGeometryTest.testRemoveGeometry2(), RemoveGeometryTest.testRemoveGeometry2Z(), RemoveRepeatedPointsTest.testRemoveRepeatedPoints(), SimplifyTest.testSimplify(), and SimplifyVWTest.testSimplifyVW().

◆ getURI()

String getURI ( )
21  {
22  return POSTGIS.st_segmentize.stringValue();
23  }

References POSTGIS.st_segmentize.

◆ relation()

Geometry relation ( Geometry  geom,
Double  value 
)
protected

Reimplemented from GeometricModifierDoubleFunction.

26  {
27  double segmentLength = value;
28 
29  List<LineString> linestrings;
30  try {
31  linestrings = createSegments(geom, segmentLength);
32  GeometryFactory fac=new GeometryFactory();
33  return fac.createMultiLineString(linestrings.toArray(new LineString[0]));
34  } catch (FactoryException e) {
35  // TODO Auto-generated catch block
36  e.printStackTrace();
37  }
38  return null;
39  }
List< LineString > createSegments(Geometry track, double segmentLength)
Definition: Segmentize.java:41

References Segmentize.createSegments().