kiwi-postgis  Version 0.1.0.0
PolyshapeWriter Class Reference

Wrap the 'Encoded Polyline Algorithm Format' defined in: Google Maps API with flags to encode various Shapes: Point, Line, Polygon, etc. More...

Inheritance diagram for PolyshapeWriter:
Collaboration diagram for PolyshapeWriter:

Classes

class  Encoder
 Encodes a sequence of LatLngs into an encoded path string. More...
 

Public Member Functions

String getFormatName ()
 
void write (Writer output, Geometry shape) throws IOException
 
void write (Encoder enc, Geometry shape) throws IOException
 
String toString (Geometry shape)
 

Static Public Attributes

static final char KEY_POINT = '0'
 
static final char KEY_LINE = '1'
 
static final char KEY_POLYGON = '2'
 
static final char KEY_MULTIPOINT = '3'
 
static final char KEY_CIRCLE = '4'
 
static final char KEY_BOX = '5'
 
static final char KEY_ARG_START = '('
 
static final char KEY_ARG_END = ')'
 
static final char KEY_SEPERATOR = ' '
 

Detailed Description

Wrap the 'Encoded Polyline Algorithm Format' defined in: Google Maps API with flags to encode various Shapes: Point, Line, Polygon, etc.

For more details, see FORMATS.md

This format works well for geographic shapes (-180...+180 / -90...+90), but is not appropriate for other coordinate systems

See also
Google Maps API
PolyshapeReader

Member Function Documentation

◆ getFormatName()

String getFormatName ( )
50  {
51  return "PolyShape";
52  }

◆ toString()

String toString ( Geometry  shape)

References PolyshapeWriter.write().

Referenced by PolyshapeDatatype.unparse().

131  {
132  try {
133  StringWriter buffer = new StringWriter();
134  write(buffer, shape);
135  return buffer.toString();
136  } catch (IOException ex) {
137  throw new RuntimeException(ex);
138  }
139  }
void write(Writer output, Geometry shape)
Definition: PolyshapeWriter.java:56

◆ write() [1/2]

void write ( Writer  output,
Geometry  shape 
) throws IOException

Referenced by PolyshapeWriter.toString().

56  {
57  if (shape == null) {
58  throw new NullPointerException("Shape can not be null");
59  }
60  write(new Encoder(output), shape);
61  }
void write(Writer output, Geometry shape)
Definition: PolyshapeWriter.java:56

◆ write() [2/2]

void write ( Encoder  enc,
Geometry  shape 
) throws IOException
63  {
64  /*if (shape instanceof Point) {
65  Point v = (Point) shape;
66  enc.write(KEY_POINT);
67  enc.write(v.getX(), v.getY());
68  return;
69  }
70  if (shape instanceof Rectangle2D) {
71  Rectangle v = (Rectangle) shape;
72  enc.write(KEY_BOX);
73  enc.write(v.getMinX(), v.getMinY());
74  enc.write(v.getMaxX(), v.getMaxY());
75  return;
76  }
77  if (shape instanceof BufferedLine) {
78  BufferedLine v = (BufferedLine) shape;
79  enc.write(KEY_LINE);
80  if(v.getBuf()>0) {
81  enc.writeArg(v.getBuf());
82  }
83  enc.write(v.getA().getX(), v.getA().getY());
84  enc.write(v.getB().getX(), v.getB().getY());
85  return;
86  }
87  if (shape instanceof LineString) {
88  LineString v = (LineString) shape;
89  enc.write(KEY_LINE);
90  if(v.getBuf()>0) {
91  enc.writeArg(v.getBuf());
92  }
93  LineString last = null;
94  Iterator<LineString> iter = v.getSegments().iterator();
95  while (iter.hasNext()) {
96  LineString seg = iter.next();
97  enc.write(seg.getA().getX(), seg.getA().getY());
98  last = seg;
99  }
100  if (last != null) {
101  enc.write(last.getB().getX(), last.getB().getY());
102  }
103  return;
104  }
105  if (shape instanceof Circle) {
106  // See: https://github.com/geojson/geojson-spec/wiki/Proposal---Circles-and-Ellipses-Geoms
107  Circle v = (Circle) shape;
108  Point center = GeometryFactory. createPointFromInternalCoord(v.getCenter().getCoordinate(), new GeometryFactory());
109  double radius = v.getRadius();
110  enc.write(KEY_CIRCLE);
111  enc.writeArg(radius);
112  enc.write(center.getX(), center.getY());
113  return;
114  }
115  if (shape instanceof GeometryCollection) {
116  GeometryCollection v = (GeometryCollection) shape;
117 
118  //Iterator<Geometry> iter = v.geomeiterator();
119  for(int i=0;i<v.getLength();i++) {
120  write(enc, v.getGeometryN(i));
121  if(i<v.getLength()) {
122  enc.seperator();
123  }
124  }
125  return;
126  }*/
127  return;
128 
129  }

Member Data Documentation

◆ KEY_ARG_END

final char KEY_ARG_END = ')'
static

Referenced by PolyshapeReader.read().

◆ KEY_ARG_START

final char KEY_ARG_START = '('
static

Referenced by PolyshapeReader.read().

◆ KEY_BOX

final char KEY_BOX = '5'
static

◆ KEY_CIRCLE

final char KEY_CIRCLE = '4'
static

Referenced by PolyshapeReader.read().

◆ KEY_LINE

final char KEY_LINE = '1'
static

◆ KEY_MULTIPOINT

final char KEY_MULTIPOINT = '3'
static

◆ KEY_POINT

final char KEY_POINT = '0'
static

◆ KEY_POLYGON

final char KEY_POLYGON = '2'
static

◆ KEY_SEPERATOR

final char KEY_SEPERATOR = ' '
static

Referenced by PolyshapeReader.read().