@Override public Object asJSON(Object value, MaxwellOutputConfig config) { Geometry geometry = null; if ( value instanceof Geometry ) { geometry = (Geometry) value; } else if ( value instanceof byte[] ) { byte []bytes = (byte[]) value; // mysql sprinkles 4 mystery bytes on top of the GIS data. bytes = Arrays.copyOfRange(bytes, 4, bytes.length); final WKBReader reader = new WKBReader(); try { geometry = reader.read(bytes); } catch ( ParseException e ) { throw new RuntimeException("Could not parse geometry: " + e); } } else { throw new RuntimeException("Could not parse geometry column value: " + value); } return geometry.toText(); }
/** * Returns the Well-known Text representation of this <code>Geometry</code>. * For a definition of the Well-known Text format, see the OpenGIS Simple * Features Specification. * *@return the Well-known Text representation of this <code>Geometry</code> */ public String toText() { WKTWriter writer = new WKTWriter(); return writer.write(this); }
private MultiLineString readMultiLineString() throws IOException, ParseException { int numGeom = dis.readInt(); LineString[] geoms = new LineString[numGeom]; for (int i = 0; i < numGeom; i++) { Geometry g = readGeometry(); if (! (g instanceof LineString)) throw new ParseException(INVALID_GEOM_TYPE_MSG + "MultiLineString"); geoms[i] = (LineString) g; } return factory.createMultiLineString(geoms); }
/** * Converts a <code>Geometry</code> to its Well-known Text representation. * *@param geometry a <code>Geometry</code> to process */ public void write(Geometry geometry, Writer writer) throws IOException { writeFormatted(geometry, false, writer); }
/** * Converts a byte array to a hexadecimal string. * * @param bytes * @return a string of hexadecimal digits * * @deprecated */ public static String bytesToHex(byte[] bytes) { return toHex(bytes); }
private void checkTriangleSize(Coordinate[] pts) { String loc = ""; if (pts.length >= 2) loc = WKTWriter.toLineString(pts[0], pts[1]); else { if (pts.length >= 1) loc = WKTWriter.toPoint(pts[0]); } // Assert.isTrue(pts.length == 4, "Too few points for visited triangle at " + loc); //com.vividsolutions.jts.util.Debug.println("too few points for triangle at " + loc); }
private void writeByteOrder(OutStream os) throws IOException { if (byteOrder == ByteOrderValues.LITTLE_ENDIAN) buf[0] = WKBConstants.wkbNDR; else buf[0] = WKBConstants.wkbXDR; os.write(buf, 1); }
/** * Creates a new stream based on the given buffer. * * @param buffer the bytes to read */ public ByteArrayInStream(final byte[] buffer) { setBytes(buffer); }
private void indentCoords(int coordIndex, int level, Writer writer) throws IOException { if (coordsPerLine <= 0 || coordIndex % coordsPerLine != 0) return; indent(level, writer); }
public String toString() { return WKTWriter.toLineString(pt[0], pt[1]); } }
/** * Reads a byte value * * @return the byte read */ public byte readByte() throws IOException { stream.read(buf1); return buf1[0]; }
private static String msgWithCoord(String msg, Coordinate pt) { if (pt != null) return msg + " [ " + WKTWriter.toPoint(pt) + " ]"; return msg; }
private MultiPoint readMultiPoint() throws IOException, ParseException { int numGeom = dis.readInt(); Point[] geoms = new Point[numGeom]; for (int i = 0; i < numGeom; i++) { Geometry g = readGeometry(); if (! (g instanceof Point)) throw new ParseException(INVALID_GEOM_TYPE_MSG + "MultiPoint"); geoms[i] = (Point) g; } return factory.createMultiPoint(geoms); }
/** * Same as <code>write</code>, but with newlines and spaces to make the * well-known text more readable. * *@param geometry a <code>Geometry</code> to process */ public void writeFormatted(Geometry geometry, Writer writer) throws IOException { writeFormatted(geometry, true, writer); } /**
private MultiPolygon readMultiPolygon() throws IOException, ParseException { int numGeom = dis.readInt(); Polygon[] geoms = new Polygon[numGeom]; for (int i = 0; i < numGeom; i++) { Geometry g = readGeometry(); if (! (g instanceof Polygon)) throw new ParseException(INVALID_GEOM_TYPE_MSG + "MultiPolygon"); geoms[i] = (Polygon) g; } return factory.createMultiPolygon(geoms); }