use of com.vividsolutions.jts.io.WKTWriter in project teiid by teiid.
the class GeometryUtils method snapToGrid.
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);
}
use of com.vividsolutions.jts.io.WKTWriter in project hibernate-orm by hibernate.
the class TestHANASpatialFunctions method geomfromwkt.
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);
}
use of com.vividsolutions.jts.io.WKTWriter in project osm4j-geometry by topobyte.
the class TestBuildPolygon method main.
public static void main(String[] args) throws MalformedURLException, IOException, ParserConfigurationException, SAXException, EntityNotFoundException {
String query = "http://overpass-api.de/api/interpreter?data=(rel(8638);>;);out;";
// Open a stream
InputStream input = new URL(query).openStream();
OsmIterator iterator = new OsmXmlIterator(input, false);
InMemoryMapDataSet data = MapDataSetLoader.read(iterator, false, false, true);
TLongObjectMap<OsmRelation> relations = data.getRelations();
if (relations.isEmpty()) {
System.out.println("No relation found");
return;
}
TLongObjectIterator<OsmRelation> ri = relations.iterator();
ri.advance();
OsmRelation relation = ri.value();
File outputDir = new File("/tmp");
String filename = String.format("relation-%d.wkt", relation.getId());
File file = new File(outputDir, filename);
GeometryBuilder geometryBuilder = new GeometryBuilder();
geometryBuilder.setMissingEntitiesStrategy(MissingEntitiesStrategy.BUILD_PARTIAL);
geometryBuilder.setMissingWayNodeStrategy(MissingWayNodeStrategy.OMIT_VERTEX_FROM_POLYLINE);
Geometry polygon = geometryBuilder.build(relation, data);
WKTWriter writer = new WKTWriter();
FileWriter fileWriter = new FileWriter(file);
writer.write(polygon, fileWriter);
fileWriter.close();
System.out.println("Successfully created WKT representation");
}
Aggregations