/** * Get the value in Well-Known-Text format. * * @return the well-known-text */ public String getWKT() { return new WKTWriter(3).write(getGeometryNoCopy()); }
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 ); }
public void geomfromewkt(String pckg) throws SQLException { WKTWriter writer = new WKTWriter(); String ewkt = "SRID=" + expectationsFactory.getTestSrid() + ";" + writer.write( expectationsFactory.getTestPolygon() ); Map<Integer, Geometry> dbexpected = hanaExpectationsFactory.getGeomFromEWKT( ewkt ); String hql = format( "SELECT 1, cast(geomfromewkt(:param) as %s) FROM org.hibernate.spatial.integration.%s.GeomEntity g", getGeometryTypeFromPackage( pckg ), pckg ); Map<String, Object> params = createQueryParams( "param", ewkt ); retrieveHQLResultsAndCompare( dbexpected, hql, params, pckg ); }
@Override public void encodeGeometryValue(Geometry value, int dimension, int srid, StringBuffer sql) throws IOException { if (value != null) { if (delegate.usePreciseSpatialOps) { sql.append("ST_GeomFromText('"); } else { sql.append("GeomFromText('"); } sql.append(new WKTWriter().write(value)); sql.append("', ").append(srid).append(")"); } else { sql.append("NULL"); } }
public void encodeGeometryValue(Geometry value, int srid, StringBuffer sql) throws IOException { if (value == null || value.isEmpty()) { sql.append("ST_GeomFromText ('"); sql.append(new WKTWriter().write(value)); sql.append("',"); sql.append(srid); sql.append(")"); } else { sql.append("NULL"); } }
@Override public void encodeGeometryValue(Geometry value, int dimension, int srid, StringBuffer sql) throws IOException { if (value != null && !value.isEmpty()) { sql.append("ST_GeomFromText ('"); sql.append(new WKTWriter().write(value)); sql.append("',"); sql.append(srid); sql.append(")"); } else { sql.append("NULL"); } }
/** * 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() + ")"); }
public static void encodeGeometryValue(Geometry value, int srid, StringBuffer sql) throws IOException { if (value == null || value.isEmpty()) { sql.append("null"); return; } String pattern = PARAMETER_LITERALS.get(value.getClass()); if (pattern == null) { // should not happen sql.append("null"); return; } sql.append( MessageFormat.format( pattern, new Object[] {new WKTWriter().write(value), Integer.toString(srid)})); } }
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
public void setValue(Object value) { Geometry geom = (Geometry) value; WKTWriter writer = new WKTWriter(getD()); String wkt = writer.write(geom); text.setText(wkt); }
@Override public void encodeGeometryValue(Geometry value, int dimension, int srid, StringBuffer sql) throws IOException { if (value == null) { sql.append("NULL"); return; } GeometryDimensionFinder finder = new GeometryDimensionFinder(); value.apply(finder); WKTWriter writer = new WKTWriter(finder.hasZ() ? 3 : 2); String wkt = writer.write(value); sql.append("geometry::STGeomFromText('").append(wkt).append("',").append(srid).append(")"); }
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());
@Override public void setGeometryValue( Geometry g, int dimension, int srid, Class binding, PreparedStatement ps, int column) throws SQLException { if (g != null) { if (g instanceof LinearRing) { // teradata does not handle linear rings, convert to just a line string g = g.getFactory().createLineString(((LinearRing) g).getCoordinateSequence()); } // TODO: use WKB instead of WKT String wkt = new WKTWriter().write(g); if (wkt.length() > 64000) { ByteArrayInputStream bin = new ByteArrayInputStream(wkt.getBytes()); ps.setAsciiStream(column, bin, bin.available()); } else { ps.setString(column, wkt); } } else { ps.setNull(column, Types.OTHER, "Geometry"); } }
@Override public void encodeGeometryValue(Geometry value, int dimension, int srid, StringBuffer sql) throws IOException { if (value == null || value.isEmpty()) { sql.append("NULL"); } else { if (value instanceof LinearRing && !(value instanceof CurvedRing)) { // postgis does not handle linear rings, convert to just a line string value = value.getFactory() .createLineString(((LinearRing) value).getCoordinateSequence()); } WKTWriter writer = new WKTWriter2(dimension); String wkt = writer.write(value); sql.append("ST_GeomFromText('" + wkt + "', " + srid + ")"); } }
String wkt = writer.write(geometry); output.append(wkt); } else if (literal instanceof Number) {
@Test public void testUncachedBarb() { // 500 KNOTS --> Not in cache being greater than max speed. Make sure I'm getting that // anyway this.exp = ff.literal(WindBarbsFactory.WINDBARBS_PREFIX + "default(500)[kts]?vectorLength=80"); Shape shp = (Shape) wbf.getShape(null, this.exp, this.feature); assertNotNull(shp); assertTrue(shp instanceof Path2D); String shpString = WindBarbsFactoryTest.WKT_WRITER.write(JTS.toGeometry(shp)).toString(); assertEquals( shpString, "MULTILINESTRING ((0 -0, 0 80), (0 80, 20 77, 0 74, 0 80), " + "(0 74, 20 71, 0 68, 0 74), (0 68, 20 65, 0 62, 0 68), (0 62, 20 59, 0 56, 0 62), " + "(0 56, 20 53, 0 50, 0 56), (0 50, 20 47, 0 44, 0 50), (0 44, 20 41, 0 38, 0 44), " + "(0 38, 20 35, 0 32, 0 38), (0 32, 20 29, 0 26, 0 32), (0 26, 20 23, 0 20, 0 26))"); }
assertTrue(shp instanceof Path2D); assertEquals( WindBarbsFactoryTest.WKT_WRITER.write(JTS.toGeometry(shp)).toString(), "MULTILINESTRING ((0 -0, 0 40), (5 45, -5 35), (-5 45, 5 35))"); assertNotNull(shp); assertTrue(shp instanceof Path2D); String shpString = WindBarbsFactoryTest.WKT_WRITER.write(JTS.toGeometry(shp)).toString(); assertEquals( WindBarbsFactoryTest.WKT_WRITER.write(JTS.toGeometry(shp)).toString(), "MULTILINESTRING ((0 -0, 0 40), (0 35, 10 36.25))"); WindBarbsFactoryTest.WKT_WRITER.write(JTS.toGeometry(shpS)).toString(), shpString); assertNotNull(shp); assertTrue(shp instanceof Path2D); shpString = WindBarbsFactoryTest.WKT_WRITER.write(JTS.toGeometry(shp)).toString(); assertEquals(shpString, "MULTILINESTRING ((0 -0, 0 40), (0 35, 10 36.25))"); WindBarbsFactoryTest.WKT_WRITER.write(JTS.toGeometry(shpS)).toString(), shpString); assertTrue(shp instanceof Path2D); assertEquals( WindBarbsFactoryTest.WKT_WRITER.write(JTS.toGeometry(shp)).toString(), "MULTILINESTRING ((0 -0, 0 40), (0 40, 20 42.5), (0 35, 10 36.25))"); assertTrue(shp instanceof Path2D); assertEquals( WindBarbsFactoryTest.WKT_WRITER.write(JTS.toGeometry(shp)).toString(),
@Test public void testInvalidAndRare() { // INF and -INF are rejected this.exp = ff.literal(WindBarbsFactory.WINDBARBS_PREFIX + "default(Infinity)[kts]"); Shape shp = (Shape) wbf.getShape(null, this.exp, this.feature); assertNull(shp); this.exp = ff.literal(WindBarbsFactory.WINDBARBS_PREFIX + "default(-Infinity)[kts]"); shp = (Shape) wbf.getShape(null, this.exp, this.feature); assertNull(shp); // NaN is x----- this.exp = ff.literal(WindBarbsFactory.WINDBARBS_PREFIX + "default(NaN)[kts]"); shp = (Shape) wbf.getShape(null, this.exp, this.feature); assertNotNull(shp); assertEquals( WindBarbsFactoryTest.WKT_WRITER.write(JTS.toGeometry(shp)).toString(), "MULTILINESTRING ((0 -0, 0 40), (5 45, -5 35), (-5 45, 5 35))"); // missing ? before KVP this.exp = ff.literal(WindBarbsFactory.WINDBARBS_PREFIX + "default(110)[kts]emisphere=N"); shp = (Shape) wbf.getShape(null, this.exp, this.feature); assertNull(shp); // wrong separator before KVP this.exp = ff.literal(WindBarbsFactory.WINDBARBS_PREFIX + "default(110)[kts]&emisphere=N"); shp = (Shape) wbf.getShape(null, this.exp, this.feature); assertNull(shp); }
assertEquals("POLYGON ((-2 2, 0 2, 0 -2, -2 -2, -2 2))", writer.write(poly));
assertEquals("POINT (-1 1)", writer.write(point));