rdf4j-postgis  Version 0.1.0.0
GPXDatatype Class Reference
Inheritance diagram for GPXDatatype:
Collaboration diagram for GPXDatatype:

Public Member Functions

Geometry read (String geometryLiteral)
 
String unparse (Geometry geom)
 

Static Public Attributes

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

Package Attributes

String out
 
String out2
 
String out3 =" </trkseg></trk></gpx>"
 

Member Function Documentation

◆ read()

Geometry read ( String  geometryLiteral)

Reimplemented from VectorLiteral.

42  {
43 
44  try {
45  SAXParser parser=SAXParserFactory.newInstance().newSAXParser();
46  InputStream stream = new ByteArrayInputStream(geometryLiteral.getBytes(StandardCharsets.UTF_8));
47  GPXHandler handler=new GPXHandler();
48  parser.parse(stream, handler);
49  GeometryFactory fac=new GeometryFactory();
50  if(handler.coordinates.size()==1 && handler.coordinates.get(0).size()==1) {
51  return fac.createPoint(handler.coordinates.get(0).get(0));
52  }
53  if(handler.coordinates.size()==1 && handler.coordinates.get(0).size()>1) {
54  return fac.createLineString(handler.coordinates.get(0).toArray(new Coordinate[0]));
55  }
56  /*if(handler.coordinates.size()>1 && handler.coordinates.get(0).size()>1) {
57  return GeometryWrapperFactory.createMultiLineString(lineStrings, URI);
58  }*/
59  } catch (SAXException | IOException | ParserConfigurationException e) {
60  throw new AssertionError("There was an error parsing GPXLiteral: " + geometryLiteral);
61  }
62  throw new AssertionError("Error parsing GPXLiteral: " + geometryLiteral);
63  }

References GPXHandler.coordinates.

◆ unparse()

String unparse ( Geometry  geom)

Reimplemented from VectorLiteral.

68  {
69  StringBuilder trackpoints=new StringBuilder();
70  for(Coordinate coord:geom.getCoordinates()) {
71  trackpoints.append("<trkpt lat='"+coord.x+"' lon='"+coord.y+"'>");
72  if(!Double.isNaN(coord.getZ()))
73  trackpoints.append("<ele>"+coord.getZ()+"</ele>");
74  trackpoints.append("</trkpt>");
75  }
76  return out+out2+trackpoints+out3;
77  }

References GPXDatatype.out, GPXDatatype.out2, and GPXDatatype.out3.

Member Data Documentation

◆ INSTANCE

final GPXDatatype INSTANCE = new GPXDatatype()
static

A static instance of WKTDatatype.

Referenced by LiteralRegistry.LiteralRegistry().

◆ out

String out
package
Initial value:
= "<?xml version='1.0' encoding='UTF-8' standalone='no' ?>" +
"<gpx version='1.0'>"+
"<name>Example gpx</name>"

Referenced by GPXDatatype.unparse().

◆ out2

String out2
package
Initial value:
=
" <trk>" +
" <name>Example gpx</name>" +
" <trkseg>"

Referenced by GPXDatatype.unparse().

◆ out3

String out3 =" </trkseg></trk></gpx>"
package

Referenced by GPXDatatype.unparse().

◆ URI

final String URI = POSTGIS.HEXWKB
static

The default WKT type URI.

Referenced by LiteralRegistry.LiteralRegistry().