kiwi-postgis  Version 0.1.0.0
Segmentize Class Reference
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)
 

Member Function Documentation

◆ createSegments()

List<LineString> createSegments ( Geometry  track,
double  segmentLength 
) throws NoSuchAuthorityCodeException, FactoryException

Referenced by Segmentize.relation().

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

◆ evaluate()

Value evaluate ( ValueFactory  valueFactory,
Value...  args 
) throws ValueExprEvaluationException
inherited

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

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  }

◆ getURI()

String getURI ( )

References POSTGIS.st_segmentize.

18  {
19  return POSTGIS.st_segmentize.stringValue();
20  }

◆ relation()

Geometry relation ( Geometry  geom,
Double  value 
)
protected

References Segmentize.createSegments().

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