/** * Construct the appropriate geometry type from the WKT representation of a literal expression * * @param expression the expression turn into a geometry constructor. * @throws IOException Passes back exception if generated by this.out.write() */ public void visitLiteralGeometry(Literal expression) throws IOException { String wktRepresentation = wktWriter.write((Geometry) expression.getValue()); int spacePos = wktRepresentation.indexOf(" "); String geomType = wktRepresentation.substring(0, spacePos); this.out.write( "db2gse.ST_" + geomType + "('" + wktRepresentation + "', " + getSRID() + ")"); }
/** A one-line WKT may be too large, this function returns a multiline formatted one */ private static Object formattedWKT(Geometry geometry) { WKTWriter w = new WKTWriter(); w.setFormatted(true); w.setMaxCoordinatesPerLine(100); return w.write(geometry); }
final WKTWriter geometryWriter = new WKTWriter();
public Object getTransferData(DataFlavor flavor) throws UnsupportedFlavorException, IOException { if (flavor.equals(GEOMETRY_FLAVOR)) { return geom; } if (flavor.equals(DataFlavor.stringFlavor)) { if (isFormatted) { WKTWriter writer = new WKTWriter(); writer.setFormatted(true); writer.setMaxCoordinatesPerLine(5); String wkt = writer.writeFormatted(geom); return wkt; } return geom.toString(); } throw new UnsupportedFlavorException(flavor); } }
public String toFormattedString() { WKTWriter writer = new WKTWriter(); return writer.writeFormatted(geometry); }
public void testProperties() { assertEquals(Ordinate.createXY(), writer.getOutputOrdinates()); assertEquals(Ordinate.createXYZ(), writer3D.getOutputOrdinates()); assertEquals(Ordinate.createXYM(), writer2DM.getOutputOrdinates()); GeometryFactory gf = new GeometryFactory( PackedCoordinateSequenceFactory.DOUBLE_FACTORY); WKTWriter writer3DM = new WKTWriter(4); assertEquals(Ordinate.createXYZM(), writer3DM.getOutputOrdinates()); writer3DM.setOutputOrdinates(Ordinate.createXY()); assertEquals(Ordinate.createXY(), writer3DM.getOutputOrdinates()); writer3DM.setOutputOrdinates(Ordinate.createXYZ()); assertEquals(Ordinate.createXYZ(), writer3DM.getOutputOrdinates()); writer3DM.setOutputOrdinates(Ordinate.createXYM()); assertEquals(Ordinate.createXYM(), writer2DM.getOutputOrdinates()); writer3DM.setOutputOrdinates(Ordinate.createXYZM()); assertEquals(Ordinate.createXYZM(), writer3DM.getOutputOrdinates()); }
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); }
/** * 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, precisionModel); } /**
private static String msgWithCoord(String msg, Coordinate pt) { if (pt != null) return msg + " [ " + WKTWriter.toPoint(pt) + " ]"; return msg; }
public void write(int position, Object attribute) throws IOException { if (writer == null) { throw new IOException("Writer has been closed"); } writer.write(position == 0 ? "=" : "|"); if (attribute == null) { writer.write("<null>"); // nothing! } else if (attribute instanceof String) { // encode newlines String txt = (String) attribute; txt = txt.replace("\n", "\\n"); txt = txt.replace("\r", "\\r"); writer.write(txt); } else if (attribute instanceof Geometry) { Geometry geometry = (Geometry) attribute; wktWriter.write(geometry, writer); } else { String txt = Converters.convert(attribute, String.class); if (txt == null) { // could not convert? txt = attribute.toString(); } writer.write(txt); } } // writeImplementation end
private String convertToWKT(Geometry g, boolean isFormatted) { if (g == null) return ""; if (! isFormatted) return g.toString(); WKTWriter writer = new WKTWriter(); writer.setFormatted(isFormatted); writer.setMaxCoordinatesPerLine(5); return writer.write(g); }
static final WKTWriter wktwriter() { return new WKTWriter(); }
void printFormatted(Geometry geom) { WKTWriter writer = new WKTWriter(); System.out.println(writer.writeFormatted(geom)); }
private void checkPointOnSeg(Coordinate p1, Coordinate p2, Coordinate q) { System.out.println(" Pt: " + WKTWriter.toPoint(q) + " seg: " + WKTWriter.toLineString(p1, p2) + " --- DDstd = " + orientationDet(p1, p2, q, DD_STD) + " --- DDdec = " + orientationDet(p1, p2, q, DD_DEC) ); }
public static String getText(Geometry geom, int textType) { switch (textType) { case GeometryType.WELLKNOWNTEXT: String wkt = wktWriter.writeFormatted(geom); return wkt; } Assert.shouldNeverReachHere(); return ""; }
private void reportError(String msg, Coordinate loc) { String locStr = ""; if (loc != null) { locStr = " at " + WKTWriter.toPoint(loc); } // System.out.println(msg); throw new RuntimeException(msg + locStr); }
public void geomfromwkt(String pckg) throws SQLException { WKTWriter writer = new WKTWriter(); String wkt = writer.write( expectationsFactory.getTestPolygon() ); Map<Integer, Geometry> dbexpected = hanaExpectationsFactory.getGeomFromWKT( wkt ); String hql = format( "SELECT 1, cast(geomfromwkt(:param) as %s) FROM org.hibernate.spatial.integration.%s.GeomEntity g", getGeometryTypeFromPackage( pckg ), pckg ); Map<String, Object> params = createQueryParams( "param", wkt ); retrieveHQLResultsAndCompare( dbexpected, hql, params, pckg ); }
final Geometry polygon = (Geometry) footprintGeometryMap.get(locationKey); if (polygon != null) { final String s = writer.write(polygon); String id = featureID; id = id.substring(id.lastIndexOf(".") + 1, id.length());
static final WKTWriter wktwriter() { return new WKTWriter(); }