Java Code Examples for com.vividsolutions.jts.io.WKTReader#read()
The following examples show how to use
com.vividsolutions.jts.io.WKTReader#read() .
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 File: GeometryType.java From liquibase-spatial with 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 2
Source File: GeometryInputDialog.java From jts with 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 3
Source File: ShapeInMemFeatureModelTest.java From geomajas-project-server with GNU Affero General Public License v3.0 | 5 votes |
@Test public void setGeometry() throws Exception { WKTReader wktReader = new WKTReader(); Point pt = (Point) wktReader.read("POINT (5 5)"); featureModel.setGeometry(feature, pt); Assert.assertEquals(5, featureModel.getGeometry(feature).getCoordinate().x, 0.00001); }
Example 4
Source File: MongoGeoTupleSet.java From rya with 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 5
Source File: MongoGeoTupleSet.java From rya with 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 6
Source File: GeoTupleSet.java From rya with 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.queryCrosses( geometry, contraints); return statements; } catch (final ParseException e) { throw new QueryEvaluationException(e); } }
Example 7
Source File: MongoGeoTupleSet.java From rya with 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 8
Source File: MongoGeoTupleSet.java From rya with 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 9
Source File: GeoServiceTest.java From geomajas-project-server with GNU Affero General Public License v3.0 | 5 votes |
@Test public void transformGeometryEmptyResultOnException() throws Exception { GeometryFactory geometryFactory = new GeometryFactory(); WKTReader reader = new WKTReader( geometryFactory ); Point point = (Point) reader.read("POINT (1 1)"); Geometry geometry = geoService.transform(point, new ThrowingTransform()); Assert.assertEquals(Point.class, geometry.getClass()); Assert.assertTrue(geometry.isEmpty()); LineString lineString = (LineString) reader.read("LINESTRING (0 1,1 1)"); geometry = geoService.transform(lineString, new ThrowingTransform()); Assert.assertEquals(LineString.class, geometry.getClass()); Assert.assertTrue(geometry.isEmpty()); Polygon polygon = (Polygon) reader.read("POLYGON ((0 0,1 1,0 1,0 0))"); geometry = geoService.transform(polygon, new ThrowingTransform()); Assert.assertEquals(Polygon.class, geometry.getClass()); Assert.assertTrue(geometry.isEmpty()); MultiPoint multipoint = (MultiPoint) reader.read("MULTIPOINT ((1 1),(2 1))"); geometry = geoService.transform(multipoint, new ThrowingTransform()); Assert.assertEquals(MultiPoint.class, geometry.getClass()); Assert.assertTrue(geometry.isEmpty()); MultiLineString multilineString = (MultiLineString) reader.read("MULTILINESTRING ((0 1,1 1),(0 2,2 2))"); geometry = geoService.transform(multilineString, new ThrowingTransform()); Assert.assertEquals(MultiLineString.class, geometry.getClass()); Assert.assertTrue(geometry.isEmpty()); MultiPolygon multipolygon = (MultiPolygon) reader.read("MULTIPOLYGON (((0 0,1 1,0 1,0 0)),((0 0,2 2,0 2,0 0)))"); geometry = geoService.transform(multipolygon, new ThrowingTransform()); Assert.assertEquals(MultiPolygon.class, geometry.getClass()); Assert.assertTrue(geometry.isEmpty()); Geometry collection = (GeometryCollection) reader.read("GEOMETRYCOLLECTION(POINT(4 6),LINESTRING(4 6,7 10)) "); geometry = geoService.transform(collection, new ThrowingTransform()); Assert.assertEquals(GeometryCollection.class, geometry.getClass()); Assert.assertTrue(geometry.isEmpty()); }
Example 10
Source File: UserMapper.java From C4SG-Obsolete with 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 11
Source File: AbstractJTSService.java From geowe-core with 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 12
Source File: GeoTupleSet.java From rya with 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.queryWithin( geometry, contraints); return statements; } catch (final ParseException e) { throw new QueryEvaluationException(e); } }
Example 13
Source File: LineStringSelfIntersections.java From jts with GNU Lesser General Public License v2.1 | 5 votes |
public static void main(String[] args) throws Exception { WKTReader rdr = new WKTReader(); LineString line1 = (LineString) (rdr.read("LINESTRING (0 0, 10 10, 20 20)")); showSelfIntersections(line1); LineString line2 = (LineString) (rdr.read("LINESTRING (0 40, 60 40, 60 0, 20 0, 20 60)")); showSelfIntersections(line2); }
Example 14
Source File: AreaAuthorizationInfo.java From geomajas-project-server with GNU Affero General Public License v3.0 | 5 votes |
private Geometry readWkt(String area) { try { WKTReader wktReader = new WKTReader(new GeometryFactory(new PrecisionModel(), 0)); return wktReader.read(area); } catch (ParseException pe) { throw new IllegalArgumentException("Could not parse geometry " + area, pe); } }
Example 15
Source File: GeoTupleSet.java From rya with 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.queryOverlaps( geometry, contraints); return statements; } catch (final ParseException e) { throw new QueryEvaluationException(e); } }
Example 16
Source File: LineStringImplTest.java From jts with GNU Lesser General Public License v2.1 | 4 votes |
public void testEquals8() throws Exception { WKTReader reader = new WKTReader(new GeometryFactory(new PrecisionModel(1000), 0)); MultiLineString l1 = (MultiLineString) reader.read("MULTILINESTRING((1732328800 519578384, 1732026179 519976285, 1731627364 519674014, 1731929984 519276112, 1732328800 519578384))"); MultiLineString l2 = (MultiLineString) reader.read("MULTILINESTRING((1731627364 519674014, 1731929984 519276112, 1732328800 519578384, 1732026179 519976285, 1731627364 519674014))"); assertTrue(l1.equals(l2)); }
Example 17
Source File: ConvexHullTest.java From jts with GNU Lesser General Public License v2.1 | 4 votes |
public void test5() throws Exception { WKTReader reader = new WKTReader(new GeometryFactory(new PrecisionModel(1), 0)); Geometry geometry = reader.read("MULTIPOINT (0 0, 5 0, 10 0)"); LineString convexHull = (LineString) reader.read("LINESTRING (0 0, 10 0)"); assertTrue(convexHull.equalsExact(geometry.convexHull())); }
Example 18
Source File: GeoTupleSet.java From rya with Apache License 2.0 | 4 votes |
@Override public CloseableIteration<Statement, QueryEvaluationException> performSearch(final String queryText, final StatementConstraints contraints) throws QueryEvaluationException { try { final String[] args = queryText.split(NEAR_DELIM); Optional<Double> maxDistanceOpt = Optional.empty(); Optional<Double> minDistanceOpt = Optional.empty(); final String query = args[0]; for (int ii = 1; ii < args.length; ii++) { String numArg = args[ii]; // remove pre-padding 0's since NumberUtils.isNumber() // will assume its octal if it starts with a 0. while (numArg.startsWith("0")) { numArg = numArg.substring(1); } // was 0 if (numArg.equals("")) { // if max hasn't been set, set it to 0. // Otherwise, min is just ignored. if (!maxDistanceOpt.isPresent()) { maxDistanceOpt = Optional.of(0.0); } } else { if (!maxDistanceOpt.isPresent() && NumberUtils.isNumber(numArg)) { // no variable identifier, going by order. maxDistanceOpt = getDistanceOpt(numArg, "maxDistance"); } else if (NumberUtils.isNumber(numArg)) { // no variable identifier, going by order. minDistanceOpt = getDistanceOpt(numArg, "minDistance"); } else { throw new IllegalArgumentException(numArg + " is not a valid Near function argument."); } } } final WKTReader reader = new WKTReader(); final Geometry geometry = reader.read(query); final NearQuery nearQuery = new NearQuery(maxDistanceOpt, minDistanceOpt, geometry); return geoIndexer.queryNear(nearQuery, contraints); } catch (final ParseException e) { throw new QueryEvaluationException(e); } }
Example 19
Source File: ConvexHullTest.java From jts with GNU Lesser General Public License v2.1 | 4 votes |
public void test4() throws Exception { WKTReader reader = new WKTReader(new GeometryFactory(new PrecisionModel(1), 0)); Geometry geometry = reader.read("MULTIPOINT (0 0, 10 0, 10 0)"); LineString convexHull = (LineString) reader.read("LINESTRING (0 0, 10 0)"); assertTrue(convexHull.equalsExact(geometry.convexHull())); }
Example 20
Source File: LineStringImplTest.java From jts with GNU Lesser General Public License v2.1 | 4 votes |
public void testEquals9() throws Exception { WKTReader reader = new WKTReader(new GeometryFactory(new PrecisionModel(1), 0)); MultiLineString l1 = (MultiLineString) reader.read("MULTILINESTRING((1732328800 519578384, 1732026179 519976285, 1731627364 519674014, 1731929984 519276112, 1732328800 519578384))"); MultiLineString l2 = (MultiLineString) reader.read("MULTILINESTRING((1731627364 519674014, 1731929984 519276112, 1732328800 519578384, 1732026179 519976285, 1731627364 519674014))"); assertTrue(l1.equals(l2)); }