rdf4j-postgis  Version 0.1.0.0
LineFromEncodedPolyline Class Reference

Creates a LineString from the encoded polyline format. More...

Inheritance diagram for LineFromEncodedPolyline:
Collaboration diagram for LineFromEncodedPolyline:

Public Member Functions

Geometry construct (String input)
 
String getURI ()
 
Value evaluate (ValueFactory valueFactory, Value... args) throws ValueExprEvaluationException
 

Static Public Member Functions

static List< Coordinate > decodePolyline (String polyline, int precision)
 Decodes a polyline with a given precision. More...
 

Detailed Description

Creates a LineString from the encoded polyline format.

Member Function Documentation

◆ construct()

Geometry construct ( String  input)

Reimplemented from GeometricConstructor.

20  {
21  GeometryFactory fac=new GeometryFactory();
22  LineString ls=fac.createLineString(decodePolyline(input, 1).toArray(new Coordinate[0]));
23  return ls;
24  }
static List< Coordinate > decodePolyline(String polyline, int precision)
Decodes a polyline with a given precision.
Definition: LineFromEncodedPolyline.java:32

References LineFromEncodedPolyline.decodePolyline().

◆ decodePolyline()

static List<Coordinate> decodePolyline ( String  polyline,
int  precision 
)
static

Decodes a polyline with a given precision.

Parameters
polylinethe polyline String to decode
precisionthe precision used for decoding
Returns
the list of coordinates which have been decoded
33  {
34  List<Coordinate> coordinates = new ArrayList<Coordinate>();
35  int index = 0, shift, result;
36  int byte_;
37  int lat = 0, lng = 0, latitude_change, longitude_change,
38  factor = (int) Math.pow(10, precision);
39 
40  while (index < polyline.length()) {
41  byte_ = 0;
42  shift = 0;
43  result = 0;
44 
45  do {
46  byte_ = polyline.charAt(index++) - 63;
47  result |= (byte_ & 0x1f) << shift;
48  shift += 5;
49  } while (byte_ >= 0x20);
50 
51  latitude_change = ((result % 2 == 1) ? ~(result >> 1) : (result >> 1));
52 
53  shift = result = 0;
54 
55  do {
56  byte_ = polyline.charAt(index++) - 63;
57  result |= (byte_ & 0x1f) << shift;
58  shift += 5;
59  } while (byte_ >= 0x20);
60 
61  longitude_change = ((result % 2 == 1) ? ~(result >> 1) : (result >> 1));
62 
63  lat += latitude_change;
64  lng += longitude_change;
65 
66  coordinates.add(new Coordinate((double)lat / factor,(double)lng / factor));
67  }
68 
69  return coordinates;
70  }

Referenced by LineFromEncodedPolyline.construct().

◆ evaluate()

Value evaluate ( ValueFactory  valueFactory,
Value...  args 
) throws ValueExprEvaluationException
inherited
17  {
18  if (args.length != 1) {
19  throw new ValueExprEvaluationException(getURI() + " requires exactly 1 arguments, got " + args.length);
20  }
21  String geomString = args[0].stringValue();
22  Geometry result = construct(geomString);
23  return valueFactory.createLiteral(WKTDatatype.INSTANCE.unparse(result), WKTDatatype.LiteralIRI);
24  }

References GeometricConstructor.construct(), WKTDatatype.INSTANCE, WKTDatatype.LiteralIRI, and WKTDatatype.unparse().

Referenced by GeomFromGeoJSONTest.testGeomFromGeoJSON(), GeomFromTextTest.testGeomFromText(), GeomFromWKBTest.testGeomFromWKB(), MakeLineTest.testMakeLine1(), MakePointTest.testMakePoint1(), MakePointTest.testMakePointXYZ(), PointFromTextTest.testPointFromText(), and PolygonFromTextTest.testPolygonFromText().

◆ getURI()

String getURI ( )
73  {
74  return POSTGIS.st_lineFromEncodedPolyline.stringValue();
75  }

References POSTGIS.st_lineFromEncodedPolyline.