rdf4j-postgis  Version 0.1.0.0
EncodedPolylineDatatype Class Reference

WKTDatatype class allows the URI "geo:wktLiteral" to be used as a datatype and it will parse that datatype to a JTS Geometry. More...

Inheritance diagram for EncodedPolylineDatatype:
Collaboration diagram for EncodedPolylineDatatype:

Public Member Functions

String unparse (Geometry geometry)
 This method Un-parses the JTS Geometry to the WKT literal. More...
 
Geometry read (String geometryLiteral)
 
String toString ()
 

Static Public Member Functions

static String encodePolyline (final LineString linestring)
 Encodes a sequence of LatLngs into an encoded path string. More...
 
static List< Coordinate > decodePolyline (String polyline, int precision)
 

Static Public Attributes

static final String URI = POSTGIS.EncodedPolyline
 The default WKT type URI. More...
 
static final EncodedPolylineDatatype INSTANCE = new EncodedPolylineDatatype()
 A static instance of WKTDatatype. More...
 

Static Private Member Functions

static void encode (long v, StringBuffer result)
 

Detailed Description

WKTDatatype class allows the URI "geo:wktLiteral" to be used as a datatype and it will parse that datatype to a JTS Geometry.

Req 10 All RDFS Literals of type geo:wktLiteral shall consist of an optional URI identifying the coordinate reference system followed by Simple Features Well Known Text (WKT) describing a geometric value. Valid geo:wktLiterals are formed by concatenating a valid, absolute URI as defined in [RFC 2396], one or more spaces (Unicode U+0020 character) as a separator, and a WKT string as defined in Simple Features [ISO 19125-1].

Req 11 The URI

<http://www.opengis.net/def/crs/OGC/1.3/CRS84>

shall be assumed as the spatial reference system for geo:wktLiterals that do not * specify an explicit spatial reference system URI.

Member Function Documentation

◆ decodePolyline()

static List<Coordinate> decodePolyline ( String  polyline,
int  precision 
)
static
102  {
103  List<Coordinate> coordinates = new ArrayList<Coordinate>();
104  int index = 0, shift, result;
105  int byte_;
106  int lat = 0, lng = 0, latitude_change, longitude_change,
107  factor = (int) Math.pow(10, precision);
108 
109  while (index < polyline.length()) {
110  byte_ = 0;
111  shift = 0;
112  result = 0;
113 
114  do {
115  byte_ = polyline.charAt(index++) - 63;
116  result |= (byte_ & 0x1f) << shift;
117  shift += 5;
118  } while (byte_ >= 0x20);
119 
120  latitude_change = ((result % 2 == 1) ? ~(result >> 1) : (result >> 1));
121 
122  shift = result = 0;
123 
124  do {
125  byte_ = polyline.charAt(index++) - 63;
126  result |= (byte_ & 0x1f) << shift;
127  shift += 5;
128  } while (byte_ >= 0x20);
129 
130  longitude_change = ((result % 2 == 1) ? ~(result >> 1) : (result >> 1));
131 
132  lat += latitude_change;
133  lng += longitude_change;
134 
135  coordinates.add(new Coordinate((double)lat / factor,(double)lng / factor));
136  }
137 
138  return coordinates;
139  }

Referenced by EncodedPolylineDatatype.read().

◆ encode()

static void encode ( long  v,
StringBuffer  result 
)
staticprivate
91  {
92  v = v < 0 ? ~(v << 1) : v << 1;
93  while (v >= 0x20) {
94  result.append(Character.toChars((int) ((0x20 | (v & 0x1f)) + 63)));
95  v >>= 5;
96  }
97  result.append(Character.toChars((int) (v + 63)));
98  }

Referenced by EncodedPolylineDatatype.encodePolyline().

◆ encodePolyline()

static String encodePolyline ( final LineString  linestring)
static

Encodes a sequence of LatLngs into an encoded path string.

Modified from https://gitlab.com/aceperry/androidmapsutil Apache License 2.0

69  {
70  long lastLat = 0;
71  long lastLng = 0;
72 
73  final StringBuffer result = new StringBuffer();
74 
75  for (final Coordinate point : linestring.getCoordinates()) {
76  long lat = Math.round(point.x * 1e5);
77  long lng = Math.round(point.y * 1e5);
78 
79  long dLat = lat - lastLat;
80  long dLng = lng - lastLng;
81 
82  encode(dLat, result);
83  encode(dLng, result);
84 
85  lastLat = lat;
86  lastLng = lng;
87  }
88  return result.toString();
89  }
static void encode(long v, StringBuffer result)
Definition: EncodedPolylineDatatype.java:91

References EncodedPolylineDatatype.encode().

Referenced by EncodedPolylineDatatype.unparse().

◆ read()

Geometry read ( String  geometryLiteral)

Reimplemented from VectorLiteral.

59  {
60  GeometryFactory fac=new GeometryFactory();
61  return fac.createLineString(decodePolyline(geometryLiteral, 5).toArray(new Coordinate[0]));
62  }
static List< Coordinate > decodePolyline(String polyline, int precision)
Definition: EncodedPolylineDatatype.java:101

References EncodedPolylineDatatype.decodePolyline().

◆ toString()

String toString ( )
142  {
143  return "EncodedPolylineDatatype{" + URI + '}';
144  }
static final String URI
The default WKT type URI.
Definition: EncodedPolylineDatatype.java:33

References EncodedPolylineDatatype.URI.

◆ unparse()

String unparse ( Geometry  geometry)

This method Un-parses the JTS Geometry to the WKT literal.

Parameters
geometry- the JTS Geometry to be un-parsed
Returns
WKT - the returned WKT Literal.
Notice that the Spatial Reference System is not specified in returned WKT literal.

Reimplemented from VectorLiteral.

50  {
51  if(geometry.getGeometryType().equals("LineString")){
52  return encodePolyline((LineString)geometry);
53  }else {
54  throw new AssertionError("Object passed to EncodedPolylineDatatype is not a LineString: " + geometry);
55  }
56  }
static String encodePolyline(final LineString linestring)
Encodes a sequence of LatLngs into an encoded path string.
Definition: EncodedPolylineDatatype.java:69

References EncodedPolylineDatatype.encodePolyline().

Member Data Documentation

◆ INSTANCE

final EncodedPolylineDatatype INSTANCE = new EncodedPolylineDatatype()
static

A static instance of WKTDatatype.

Referenced by LiteralRegistry.LiteralRegistry().

◆ URI

final String URI = POSTGIS.EncodedPolyline
static

The default WKT type URI.

Referenced by LiteralRegistry.LiteralRegistry(), and EncodedPolylineDatatype.toString().