Search in sources :

Example 21 with WKTWriter

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);
}
Also used : WKTWriter(com.vividsolutions.jts.io.WKTWriter) FunctionExecutionException(org.teiid.api.exception.query.FunctionExecutionException) GeometryPrecisionReducer(com.vividsolutions.jts.precision.GeometryPrecisionReducer) StringReader(java.io.StringReader) ParseException(com.vividsolutions.jts.io.ParseException) WKTReader(com.vividsolutions.jts.io.WKTReader)

Example 22 with WKTWriter

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);
}
Also used : Geometry(com.vividsolutions.jts.geom.Geometry) WKTWriter(com.vividsolutions.jts.io.WKTWriter)

Example 23 with WKTWriter

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");
}
Also used : WKTWriter(com.vividsolutions.jts.io.WKTWriter) InMemoryMapDataSet(de.topobyte.osm4j.core.dataset.InMemoryMapDataSet) InputStream(java.io.InputStream) OsmRelation(de.topobyte.osm4j.core.model.iface.OsmRelation) FileWriter(java.io.FileWriter) URL(java.net.URL) Geometry(com.vividsolutions.jts.geom.Geometry) OsmXmlIterator(de.topobyte.osm4j.xml.dynsax.OsmXmlIterator) OsmIterator(de.topobyte.osm4j.core.access.OsmIterator) File(java.io.File) GeometryBuilder(de.topobyte.osm4j.geometry.GeometryBuilder)

Aggregations

WKTWriter (com.vividsolutions.jts.io.WKTWriter)23 Geometry (com.vividsolutions.jts.geom.Geometry)11 WKTReader (com.vividsolutions.jts.io.WKTReader)7 ParseException (com.vividsolutions.jts.io.ParseException)5 AttributeImpl (ddf.catalog.data.impl.AttributeImpl)4 ValueFactory (org.openrdf.model.ValueFactory)4 ValueFactoryImpl (org.openrdf.model.impl.ValueFactoryImpl)4 Metacard (ddf.catalog.data.Metacard)2 File (java.io.File)2 Optional (java.util.Optional)2 Before (org.junit.Before)2 Test (org.junit.Test)2 Resource (org.openrdf.model.Resource)2 URI (org.openrdf.model.URI)2 Value (org.openrdf.model.Value)2 StatementImpl (org.openrdf.model.impl.StatementImpl)2 Coordinate (com.vividsolutions.jts.geom.Coordinate)1 LineString (com.vividsolutions.jts.geom.LineString)1 LinearRing (com.vividsolutions.jts.geom.LinearRing)1 MultiLineString (com.vividsolutions.jts.geom.MultiLineString)1