kiwi-postgis  Version 0.1.0.0
AsEncodedPolyline Class Reference
Inheritance diagram for AsEncodedPolyline:
Collaboration diagram for AsEncodedPolyline:

Public Member Functions

String operation (Geometry geom)
 
String getURI ()
 
Value evaluate (ValueFactory valueFactory, Value... args) throws ValueExprEvaluationException
 

Static Public Member Functions

static String encodePolyline (final LineString linestring)
 

Static Private Member Functions

static void encode (long v, StringBuffer result)
 

Member Function Documentation

◆ encode()

static void encode ( long  v,
StringBuffer  result 
)
staticprivate

Referenced by AsEncodedPolyline.encodePolyline().

43  {
44  v = v < 0 ? ~(v << 1) : v << 1;
45  while (v >= 0x20) {
46  result.append(Character.toChars((int) ((0x20 | (v & 0x1f)) + 63)));
47  v >>= 5;
48  }
49  result.append(Character.toChars((int) (v + 63)));
50  }

◆ encodePolyline()

static String encodePolyline ( final LineString  linestring)
static

References AsEncodedPolyline.encode().

Referenced by AsEncodedPolyline.operation().

21  {
22  long lastLat = 0;
23  long lastLng = 0;
24 
25  final StringBuffer result = new StringBuffer();
26 
27  for (final Coordinate point : linestring.getCoordinates()) {
28  long lat = Math.round(point.x * 1e5);
29  long lng = Math.round(point.y * 1e5);
30 
31  long dLat = lat - lastLat;
32  long dLng = lng - lastLng;
33 
34  encode(dLat, result);
35  encode(dLng, result);
36 
37  lastLat = lat;
38  lastLng = lng;
39  }
40  return result.toString();
41  }
static void encode(long v, StringBuffer result)
Definition: openrdf/query/algebra/evaluation/function/postgis/linestring/exporter/AsEncodedPolyline.java:43

◆ evaluate()

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

References LiteralRegistry.getLiteral(), and GeometricStringExportFunction.operation().

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

◆ getURI()

String getURI ( )

References POSTGIS.ST_ASENCODEDPOLYLINE.

53  {
54  return POSTGIS.ST_ASENCODEDPOLYLINE.stringValue();
55  }

◆ operation()

String operation ( Geometry  geom)

References AsEncodedPolyline.encodePolyline().

13  {
14  if (geom instanceof LineString) {
15  String result=encodePolyline((LineString)geom);
16  return result;
17  }
18  return null;
19  }
static String encodePolyline(final LineString linestring)
Definition: openrdf/query/algebra/evaluation/function/postgis/linestring/exporter/AsEncodedPolyline.java:21