Java Code Examples for com.vividsolutions.jts.io.WKTReader
The following examples show how to use
com.vividsolutions.jts.io.WKTReader.
These examples are extracted from open source projects.
You can vote up the ones you like or vote down the ones you don't like,
and go to the original project or source file by following the links above each example. You may check out the related API usage on the sidebar.
Example #1
Source Project: DataHubSystem Author: SentinelDataHub File: ProcessingUtils.java License: GNU Affero General Public License v3.0 | 6 votes |
/** * Check JTS Footprint validity */ public static boolean checkJTSFootprint (String footprint) { try { WKTReader wkt = new WKTReader(); Geometry geom = wkt.read(footprint); IsValidOp vaildOp = new IsValidOp(geom); TopologyValidationError err = vaildOp.getValidationError(); if (err != null) { throw new IllegalParameterException(err.getMessage()); } return true; } catch (Exception e) { LOGGER.error("JTS Footprint error : " + e.getMessage()); return false; } }
Example #2
Source Project: rya Author: apache File: GeoTemporalMongoDBStorageStrategy.java License: Apache License 2.0 | 6 votes |
private Document[] getGeoObjs(final Collection<IndexingExpr> geoFilters) { final List<Document> objs = new ArrayList<>(); geoFilters.forEach(filter -> { final GeoPolicy policy = GeoPolicy.fromURI(filter.getFunction()); final WKTReader reader = new WKTReader(); final String geoStr = ((Value) filter.getArguments()[0]).stringValue(); try { //This method is what is used in the GeoIndexer. final Geometry geo = reader.read(geoStr); objs.add(getGeoObject(geo, policy)); } catch (final GeoTemporalIndexException | UnsupportedOperationException | ParseException e) { LOG.error("Unable to parse '" + geoStr + "'.", e); } }); return objs.toArray(new Document[]{}); }
Example #3
Source Project: rya Author: apache File: GeoParseUtils.java License: Apache License 2.0 | 6 votes |
/** * Parse GML/wkt literal to Geometry * * @param statement * @return * @throws ParseException * @throws ParserConfigurationException * @throws SAXException * @throws IOException */ public static Geometry getGeometry(final Statement statement, GmlToGeometryParser gmlToGeometryParser) throws ParseException { // handle GML or WKT final Literal lit = getLiteral(statement); if (GeoConstants.XMLSCHEMA_OGC_WKT.equals(lit.getDatatype())) { final String wkt = lit.getLabel().toString(); return (new WKTReader()).read(wkt); } else if (GeoConstants.XMLSCHEMA_OGC_GML.equals(lit.getDatatype())) { final String gml = lit.getLabel().toString(); try { return getGeometryGml(gml, gmlToGeometryParser); } catch (IOException | SAXException | ParserConfigurationException e) { throw new ParseException(e); } } else { throw new ParseException("Literal is unknown geo type, expecting WKT or GML: " + statement.toString()); } }
Example #4
Source Project: jts Author: metteo File: GeometryInputDialog.java License: GNU Lesser General Public License v2.1 | 6 votes |
Geometry parseGeometry(JTextComponent txt, Color clr) { try { WKTReader rdr = new WKTReader( new GeometryFactory(JTSTestBuilder.model().getPrecisionModel(), 0)); Geometry g = rdr.read(txt.getText()); txtError.setText(""); return g; } catch (Exception ex) { txtError.setText(ex.getMessage()); txtError.setForeground(clr); parseError = true; // TODO: display this exception } return null; }
Example #5
Source Project: jts Author: metteo File: PolygonizeExample.java License: GNU Lesser General Public License v2.1 | 6 votes |
void run() throws Exception { WKTReader rdr = new WKTReader(); Collection lines = new ArrayList(); lines.add(rdr.read("LINESTRING (0 0 , 10 10)")); // isolated edge lines.add(rdr.read("LINESTRING (185 221, 100 100)")); //dangling edge lines.add(rdr.read("LINESTRING (185 221, 88 275, 180 316)")); lines.add(rdr.read("LINESTRING (185 221, 292 281, 180 316)")); lines.add(rdr.read("LINESTRING (189 98, 83 187, 185 221)")); lines.add(rdr.read("LINESTRING (189 98, 325 168, 185 221)")); Polygonizer polygonizer = new Polygonizer(); polygonizer.add(lines); Collection polys = polygonizer.getPolygons(); System.out.println("Polygons formed (" + polys.size() + "):"); System.out.println(polys); }
Example #6
Source Project: jts Author: metteo File: BasicExample.java License: GNU Lesser General Public License v2.1 | 6 votes |
public static void main(String[] args) throws Exception { // read a geometry from a WKT string (using the default geometry factory) Geometry g1 = new WKTReader().read("LINESTRING (0 0, 10 10, 20 20)"); System.out.println("Geometry 1: " + g1); // create a geometry by specifying the coordinates directly Coordinate[] coordinates = new Coordinate[]{new Coordinate(0, 0), new Coordinate(10, 10), new Coordinate(20, 20)}; // use the default factory, which gives full double-precision Geometry g2 = new GeometryFactory().createLineString(coordinates); System.out.println("Geometry 2: " + g2); // compute the intersection of the two geometries Geometry g3 = g1.intersection(g2); System.out.println("G1 intersection G2: " + g3); }
Example #7
Source Project: jts Author: metteo File: SimpleDemo.java License: GNU Lesser General Public License v2.1 | 6 votes |
private void showPoland() { WKTReader r = new WKTReader(); try { Geometry g = r.read(s); g.setSRID(4326); Geometry g2 = g.buffer(1); Geometry g3 = g2.difference(g); JavaScriptObject f1 = parseWKT(g.toString()); JavaScriptObject f2 = parseWKT(g3.toString()); JsArray<JavaScriptObject> fs = JsArray.createArray().cast(); fs.push(f1); fs.push(f2); addFeatures(mMap, fs); } catch (ParseException e) { sLogger.log(Level.WARNING, "Unable to parse wkb", e); } }
Example #8
Source Project: liquibase-spatial Author: lonnyj File: GeometryType.java License: Apache License 2.0 | 6 votes |
/** * @see liquibase.datatype.LiquibaseDataType#sqlToObject(java.lang.String, * liquibase.database.Database) */ @Override public Object sqlToObject(final String value, final Database database) { final Geometry returnValue; if (value == null || value.equalsIgnoreCase("null")) { returnValue = null; } else { final WKTReader reader = new WKTReader(); try { // TODO: Check for SRID. returnValue = reader.read(value); } catch (final ParseException e) { throw new UnexpectedLiquibaseException("Cannot parse " + value + " to a Geometry", e); } } return returnValue; }
Example #9
Source Project: geomajas-project-server Author: geomajas File: TransformGeometryCommandTest.java License: GNU Affero General Public License v3.0 | 6 votes |
@Test public void testTransformGeometry() throws Exception { TransformGeometryRequest request = new TransformGeometryRequest(); WKTReader reader = new WKTReader(); Geometry origin = converterService.toDto(reader.read("POLYGON((10 30, 20 30,20 40,10 40,10 30))")); request.setGeometry(origin); request.setSourceCrs(MERCATOR); request.setTargetCrs(LONLAT); // execute TransformGeometryResponse response = (TransformGeometryResponse) dispatcher.execute( TransformGeometryRequest.COMMAND, request, null, "en"); Geometry transformed = response.getGeometry(); Envelope bounds = converterService.toInternal(transformed).getEnvelopeInternal(); Assert.assertEquals(8.983152841195215E-5, bounds.getMinX(), DELTA); Assert.assertEquals(2.6949458522981454E-4, bounds.getMinY(), DELTA); Assert.assertEquals(1.796630568239043E-4, bounds.getMaxX(), DELTA); Assert.assertEquals(3.593261136397527E-4, bounds.getMaxY(), DELTA); }
Example #10
Source Project: geomajas-project-server Author: geomajas File: BeanFeatureModel.java License: GNU Affero General Public License v3.0 | 6 votes |
public Geometry getGeometry(Object feature) throws LayerException { Entity entity = entityMapper.asEntity(feature); Object geometry = entity.getAttribute(getGeometryAttributeName()); if (!wkt || null == geometry) { log.debug("bean.getGeometry {}", geometry); return (Geometry) geometry; } else { try { WKTReader reader = new WKTReader(new GeometryFactory(new PrecisionModel(), srid)); Geometry geom = reader.read((String) geometry); log.debug("bean.getGeometry {}", geom); return geom; } catch (Throwable t) { throw new LayerException(t, ExceptionCode.FEATURE_MODEL_PROBLEM, geometry); } } }
Example #11
Source Project: C4SG-Obsolete Author: Code4SocialGood File: UserMapper.java License: MIT License | 5 votes |
/** * Map user entity into data transfer object * * @param user User Entity * @return UserDTO */ public UserDTO getUserDtoFromEntity(User user){ //convert geometry object to a point Geometry g = null; com.vividsolutions.jts.geom.Point point = null; WKTReader reader = new WKTReader(); try { g = reader.read(user.getLocation().toText()); point = (com.vividsolutions.jts.geom.Point) g; } catch (Exception e) { //do nothing } //start mapping data into the dto if (user == null) return null; UserDTO userDTO = map(user, UserDTO.class); //add mapping for location if point object is not null if (point != null) { org.springframework.data.geo.Point gp = new Point(point.getX(), point.getY()); userDTO.setLongitude(Double.toString(point.getX())); userDTO.setLatitude(Double.toString(point.getY())); } userDTO.setDisplayFlag((user.getDisplayFlag() != null && user.getDisplayFlag().booleanValue()) ? "Y" : "N"); return userDTO; }
Example #12
Source Project: TomboloDigitalConnector Author: FutureCitiesCatapult File: OpenMappingImporter.java License: MIT License | 5 votes |
public Geometry getShape(String wtk) throws FactoryException, TransformException { GeometryFactory geometryFactory = new GeometryFactory(new PrecisionModel(), Subject.SRID); WKTReader reader = new WKTReader(geometryFactory); MathTransform crsTransform = GeotoolsDataStoreUtils.makeCrsTransform("EPSG:27700"); try { LineString line = (LineString) reader.read(wtk); Geometry transformedGeom = JTS.transform(line, crsTransform); return transformedGeom; } catch (ParseException e) { e.printStackTrace(); log.error("Not a valid geometry"); return null; } }
Example #13
Source Project: dhis2-core Author: dhis2 File: XmlGenericGeometryParser.java License: BSD 3-Clause "New" or "Revised" License | 5 votes |
public Geometry geometryFromJson( JsonNode node ) { WKTReader wktR = new WKTReader(); try { return wktR.read( node.asText() ); } catch ( ParseException e ) { log.error( "Error reading WKT of geometry", e ); return null; } }
Example #14
Source Project: sql-layer Author: jaytaylor File: GeoWKT.java License: GNU Affero General Public License v3.0 | 5 votes |
@Override protected void doEvaluate(TExecutionContext context, LazyList<? extends ValueSource> inputs, ValueTarget output) { String wkt = inputs.get(0).getString(); WKTReader reader = (WKTReader)context.preptimeObjectAt(READER_CONTEXT_POS); try { Geometry geometry = reader.read(wkt); output.putObject(geometry); } catch(ParseException e) { throw new InvalidSpatialObjectException(e.getMessage()); } }
Example #15
Source Project: DataHubSystem Author: SentinelDataHub File: NominatimGeocoderTest.java License: GNU Affero General Public License v3.0 | 5 votes |
/** * Test the getBoundariesWKT() operation of the NominatimGeocoder. * The test consists in a call with "france" as search query that shall * contains paris, noumea, and shall not contains berlin. * @throws ParseException */ @Test public void getBoundariesWKTFrance() throws ParseException { XmlDocument document = getDocument ("france.xml"); String wkt_france = this.geocoder.computeWKT (document); Assert.assertNotNull (wkt_france, "France geometry not found."); document = getDocument ("paris.xml"); String wkt_paris = this.geocoder.computeWKT (document); Assert.assertNotNull (wkt_paris, "Paris geometry not found."); WKTReader reader = new WKTReader (); Geometry france = reader.read (wkt_france); Geometry paris = reader.read (wkt_paris); // Test paris place is inside "France" Assert.assertTrue (france.contains (paris), "Paris geometry is not inside france"); // Check Noumea france territory in also inside france document = getDocument ("noumea.xml"); String wkt_noumea = this.geocoder.computeWKT (document); Assert.assertNotNull (wkt_noumea, "Noum�a geometry not found."); Geometry noumea = reader.read (wkt_noumea); Assert.assertTrue (france.contains (noumea), "Noum�a geometry is not inside france"); // Check berlin is outside france document = getDocument ("berlin.xml"); String wkt_berlin = this.geocoder.computeWKT (document); Assert.assertNotNull (wkt_berlin, "Berlin geometry not found."); Geometry berlin = reader.read (wkt_berlin); Assert.assertFalse (france.contains (berlin), "Berlin geometry is found inside france"); }
Example #16
Source Project: geowe-core Author: geowe File: AbstractJTSService.java License: GNU General Public License v3.0 | 5 votes |
protected Geometry getGeometry(final String wkt) { Geometry geom = null; final GeometryFactory factory = new GeometryFactory( PackedCoordinateSequenceFactory.DOUBLE_FACTORY); final WKTReader reader = new WKTReader(factory); try { geom = reader.read(wkt); } catch (ParseException e) { LOG.error(INVALID_WKT_MESSAGE + e.getMessage()); throw new IllegalArgumentException(INVALID_WKT_MESSAGE, e); } return geom; }
Example #17
Source Project: geowe-core Author: geowe File: DivideLineStringTool.java License: GNU General Public License v3.0 | 5 votes |
private Geometry getGeometry(final String wkt) { Geometry geom = null; final GeometryFactory factory = new GeometryFactory( PackedCoordinateSequenceFactory.DOUBLE_FACTORY); final WKTReader reader = new WKTReader(factory); try { geom = reader.read(wkt); } catch (ParseException e) { LOG.error("Invalid WKT" + e.getMessage()); throw new IllegalArgumentException("Invalid WKT", e); } return geom; }
Example #18
Source Project: geowe-core Author: geowe File: DividePolygonTool.java License: GNU General Public License v3.0 | 5 votes |
private Geometry getGeometry(final String wkt) { Geometry geom = null; final GeometryFactory factory = new GeometryFactory( PackedCoordinateSequenceFactory.DOUBLE_FACTORY); final WKTReader reader = new WKTReader(factory); try { geom = reader.read(wkt); } catch (ParseException e) { LOG.error(INVALID_WKT_MESSAGE + e.getMessage()); throw new IllegalArgumentException(INVALID_WKT_MESSAGE, e); } return geom; }
Example #19
Source Project: rya Author: apache File: MongoGeoTupleSet.java License: Apache License 2.0 | 5 votes |
@Override public CloseableIteration<Statement, QueryEvaluationException> performSearch(String queryText, StatementConstraints contraints) throws QueryEvaluationException { try { WKTReader reader = new WKTReader(); Geometry geometry = reader.read(queryText); CloseableIteration<Statement, QueryEvaluationException> statements = geoIndexer.queryWithin( geometry, contraints); return statements; } catch (ParseException e) { throw new QueryEvaluationException(e); } }
Example #20
Source Project: rya Author: apache File: MongoGeoTupleSet.java License: Apache License 2.0 | 5 votes |
@Override public CloseableIteration<Statement, QueryEvaluationException> performSearch(String queryText, StatementConstraints contraints) throws QueryEvaluationException { try { WKTReader reader = new WKTReader(); Geometry geometry = reader.read(queryText); CloseableIteration<Statement, QueryEvaluationException> statements = geoIndexer.queryWithin( geometry, contraints); return statements; } catch (ParseException e) { throw new QueryEvaluationException(e); } }
Example #21
Source Project: rya Author: apache File: MongoGeoTupleSet.java License: Apache License 2.0 | 5 votes |
@Override public CloseableIteration<Statement, QueryEvaluationException> performSearch(String queryText, StatementConstraints contraints) throws QueryEvaluationException { try { WKTReader reader = new WKTReader(); Geometry geometry = reader.read(queryText); CloseableIteration<Statement, QueryEvaluationException> statements = geoIndexer.queryWithin( geometry, contraints); return statements; } catch (ParseException e) { throw new QueryEvaluationException(e); } }
Example #22
Source Project: rya Author: apache File: MongoGeoTupleSet.java License: Apache License 2.0 | 5 votes |
@Override public CloseableIteration<Statement, QueryEvaluationException> performSearch(String queryText, StatementConstraints contraints) throws QueryEvaluationException { try { WKTReader reader = new WKTReader(); Geometry geometry = reader.read(queryText); CloseableIteration<Statement, QueryEvaluationException> statements = geoIndexer.queryWithin( geometry, contraints); return statements; } catch (ParseException e) { throw new QueryEvaluationException(e); } }
Example #23
Source Project: rya Author: apache File: MongoGeoTupleSet.java License: Apache License 2.0 | 5 votes |
@Override public CloseableIteration<Statement, QueryEvaluationException> performSearch(String queryText, StatementConstraints contraints) throws QueryEvaluationException { try { WKTReader reader = new WKTReader(); Geometry geometry = reader.read(queryText); CloseableIteration<Statement, QueryEvaluationException> statements = geoIndexer.queryWithin( geometry, contraints); return statements; } catch (ParseException e) { throw new QueryEvaluationException(e); } }
Example #24
Source Project: rya Author: apache File: MongoGeoTupleSet.java License: Apache License 2.0 | 5 votes |
@Override public CloseableIteration<Statement, QueryEvaluationException> performSearch(String queryText, StatementConstraints contraints) throws QueryEvaluationException { try { WKTReader reader = new WKTReader(); Geometry geometry = reader.read(queryText); CloseableIteration<Statement, QueryEvaluationException> statements = geoIndexer.queryWithin( geometry, contraints); return statements; } catch (ParseException e) { throw new QueryEvaluationException(e); } }
Example #25
Source Project: rya Author: apache File: MongoGeoTupleSet.java License: Apache License 2.0 | 5 votes |
@Override public CloseableIteration<Statement, QueryEvaluationException> performSearch(String queryText, StatementConstraints contraints) throws QueryEvaluationException { try { WKTReader reader = new WKTReader(); Geometry geometry = reader.read(queryText); CloseableIteration<Statement, QueryEvaluationException> statements = geoIndexer.queryWithin( geometry, contraints); return statements; } catch (ParseException e) { throw new QueryEvaluationException(e); } }
Example #26
Source Project: rya Author: apache File: MongoGeoTupleSet.java License: Apache License 2.0 | 5 votes |
@Override public CloseableIteration<Statement, QueryEvaluationException> performSearch(String queryText, StatementConstraints contraints) throws QueryEvaluationException { try { WKTReader reader = new WKTReader(); Geometry geometry = reader.read(queryText); CloseableIteration<Statement, QueryEvaluationException> statements = geoIndexer.queryWithin( geometry, contraints); return statements; } catch (ParseException e) { throw new QueryEvaluationException(e); } }
Example #27
Source Project: rya Author: apache File: GeoTupleSet.java License: Apache License 2.0 | 5 votes |
@Override public CloseableIteration<Statement, QueryEvaluationException> performSearch(final String queryText, final StatementConstraints contraints) throws QueryEvaluationException { try { final WKTReader reader = new WKTReader(); final Geometry geometry = reader.read(queryText); final CloseableIteration<Statement, QueryEvaluationException> statements = geoIndexer.queryEquals( geometry, contraints); return statements; } catch (final ParseException e) { throw new QueryEvaluationException(e); } }
Example #28
Source Project: rya Author: apache File: GeoTupleSet.java License: Apache License 2.0 | 5 votes |
@Override public CloseableIteration<Statement, QueryEvaluationException> performSearch(final String queryText, final StatementConstraints contraints) throws QueryEvaluationException { try { final WKTReader reader = new WKTReader(); final Geometry geometry = reader.read(queryText); final CloseableIteration<Statement, QueryEvaluationException> statements = geoIndexer.queryDisjoint( geometry, contraints); return statements; } catch (final ParseException e) { throw new QueryEvaluationException(e); } }
Example #29
Source Project: rya Author: apache File: GeoTupleSet.java License: Apache License 2.0 | 5 votes |
@Override public CloseableIteration<Statement, QueryEvaluationException> performSearch(final String queryText, final StatementConstraints contraints) throws QueryEvaluationException { try { final WKTReader reader = new WKTReader(); final Geometry geometry = reader.read(queryText); final CloseableIteration<Statement, QueryEvaluationException> statements = geoIndexer.queryIntersects( geometry, contraints); return statements; } catch (final ParseException e) { throw new QueryEvaluationException(e); } }
Example #30
Source Project: rya Author: apache File: GeoTupleSet.java License: Apache License 2.0 | 5 votes |
@Override public CloseableIteration<Statement, QueryEvaluationException> performSearch(final String queryText, final StatementConstraints contraints) throws QueryEvaluationException { try { final WKTReader reader = new WKTReader(); final Geometry geometry = reader.read(queryText); final CloseableIteration<Statement, QueryEvaluationException> statements = geoIndexer.queryTouches( geometry, contraints); return statements; } catch (final ParseException e) { throw new QueryEvaluationException(e); } }