/** * 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); }
/** * 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); }
@Override public void writeFormatted(Geometry geometry, Writer writer) throws IOException { writer.write(getSRID(geometry)); super.writeFormatted(geometry, writer); } }
/** * Checks to see if the literal is a geometry, and encodes it if it is, if * not just sends to the parent class. * * @param expression * the expression to visit and encode. * * @throws IOException * for IO exception (need a better error) */ public void visitLiteralGeometry(LiteralExpression expression) throws IOException { Geometry bbox = (Geometry) expression.evaluate( null, Geometry.class ); String geomText = null; if ( bbox instanceof LinearRing ) { //postgis does not handle linear rings, convert to just a line string LineString lineString = new LineString( ((LinearRing)bbox).getCoordinateSequence(), bbox.getFactory() ); geomText = wkt.write( lineString ); } else { geomText = wkt.write(bbox); } out.write("GeometryFromText('" + geomText + "', " + srid + ")"); }
/** * Converts a JTS <code>Geometry</code> to a native geometry object. * * @param jtsGeom * JTS Geometry to convert * @param connection * the current database connection * @return native database geometry object corresponding to jtsGeom. */ public Object conv2DBGeometry(Geometry jtsGeom, Connection connection) { int srid = jtsGeom.getSRID(); WKTWriter writer = new WKTWriter(); String wkt = writer.write(jtsGeom); return srid + "|" + wkt; }
public static String polygonToBBox( String wkt ) throws ParseException { LOGGER.trace( "Trying to convert the wkt [{}] into a bounding box", wkt ); WKTReader reader = new WKTReader(); Geometry geo = reader.read( wkt ); if ( !geo.isRectangle() ) { geo = geo.getEnvelope(); WKTWriter writer = new WKTWriter(); String bbox = writer.write( geo ); LOGGER.debug( "Convert the following wkt [{}] into a bounding box wkt [{}]", wkt, bbox ); wkt = bbox; } return wkt; }
meta.getLong("id"), validationError.getMessage(), new WKTWriter().write(p) }); Point centroid = p.getEnvelope().getCentroid(); String n = getFilePrefix(centroid.getX(), centroid.getY()); featureWithoutGeometry.put(GeoJsonWriter.GEOMETRY, GeoJsonWriter.geometryToJSON(p));
@Override public String write(Geometry geometry) { return getSRID(geometry).concat(super.write(geometry)); }
/** * @see org.geotools.data.jdbc.attributeio.AttributeIO#write(java.sql.ResultSet, * int, java.lang.Object) */ public void write(PreparedStatement ps, int position, Object value) throws IOException { try { if (value == null) { ps.setNull(position, Types.VARCHAR); } else { Geometry g = (Geometry) value; String wkt = getWKTWriter().write(g); String ewkt = "SRID="+g.getSRID()+";"+wkt; ps.setString(position, ewkt); } } catch (Exception e) { throw new DataSourceException("Sql writing problem", e); } } }
public static GeometryType snapToGrid(GeometryType geom, double size) throws FunctionExecutionException { if (size == 0) { return geom; } Geometry g1 = getGeometry(geom); PrecisionModel precisionModel = new PrecisionModel(1/size); GeometryPrecisionReducer reducer = new GeometryPrecisionReducer(precisionModel); reducer.setPointwise(true); reducer.setChangePrecisionModel(true); Geometry result = reducer.reduce(g1); //since the wkb writer doesn't consider precision, we have to first write/read through wkt WKTWriter writer = new WKTWriter(); String val = writer.write(result); WKTReader reader = new WKTReader(GEOMETRY_FACTORY); try { result = reader.read(new StringReader(val)); } catch (ParseException e) { throw new FunctionExecutionException(e); } result.setSRID(geom.getSrid()); return getGeometryType(result); }
private void testParsing(Geometry expectedGeometry) throws ConversionException { final WKTWriter wktWriter = new WKTWriter(); final String geometryWkt = wktWriter.write(expectedGeometry); final Geometry geometry = converter.parse(geometryWkt); assertTrue(expectedGeometry.equalsExact(geometry)); assertEquals(null, converter.parse("")); } }
public VocabWriterGeosparql() { this.wktWriter = new WKTWriter(); this.property = GEOSPARQL.asWKT;//.getURI(); this.datatype = GEOSPARQL.Geometry;//.getURI(); }
WKTWriter wktWriter = new WKTWriter(); wktWriter.setFormatted(true); wktWriter.setMaxCoordinatesPerLine(2); wktWriter.setTab(3); String wkt = wktWriter.writeFormatted(targetGeom);
/** * 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() + ")"); }
@Override 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"); } }
private void writeCountryBoundaries(final BufferedWriter output) throws IOException { logger.info("Writing country boundaries to output"); this.countryNameToBoundaryMap.forEach((country, polygons) -> polygons.forEach(polygon -> { try { output.write(country); output.write(COUNTRY_BOUNDARY_DELIMITER); output.write(WKT_WRITER.write(polygon)); output.write(LIST_SEPARATOR); output.write(System.lineSeparator()); } catch (final IOException e) { throw new CoreException("Failed to write country boundaries.", e); } })); }
/** * @see org.geotools.data.jdbc.attributeio.AttributeIO#write(java.sql.ResultSet, * int, java.lang.Object) */ public void write(ResultSet rs, int position, Object value) throws IOException { try { if (value == null) { rs.updateNull(position); } else { Geometry g = (Geometry) value; String wkt = getWKTWriter().write(g); String ewkt = "SRID="+g.getSRID()+";"+wkt; rs.updateString(position, ewkt); } } catch (Exception e) { throw new DataSourceException("Sql writing problem", e); } }