/** * Get or create a geometry value for the given geometry. * * @param s the WKT representation of the geometry * @param srid the srid of the object * @return the value */ public static ValueGeometry get(String s, int srid) { try { GeometryFactory geometryFactory = new GeometryFactory(new PrecisionModel(), srid); Geometry g = new WKTReader(geometryFactory).read(s); return get(g); } catch (ParseException ex) { throw DbException.convert(ex); } }
public static PrecisionModel pm() { if (precModel == null) { precModel = new PrecisionModel(); } return (precModel); }
@Override protected void init(Map<String, String> args, ClassLoader classLoader) { super.init(args, classLoader); initField("datelineRule"); initField("validationRule"); initField("autoIndex"); initField("allowMultiOverlap"); initField("useJtsPoint"); initField("useJtsLineString"); initField("useJtsMulti"); String scaleStr = args.get("precisionScale"); String modelStr = args.get("precisionModel"); if (scaleStr != null) { if (modelStr != null && !modelStr.equals("fixed")) throw new RuntimeException("Since precisionScale was specified; precisionModel must be 'fixed' but got: "+modelStr); precisionModel = new PrecisionModel(Double.parseDouble(scaleStr)); } else if (modelStr != null) { if (modelStr.equals("floating")) { precisionModel = new PrecisionModel(PrecisionModel.FLOATING); } else if (modelStr.equals("floating_single")) { precisionModel = new PrecisionModel(PrecisionModel.FLOATING_SINGLE); } else if (modelStr.equals("fixed")) { throw new RuntimeException("For fixed model, must specifiy 'precisionScale'"); } else { throw new RuntimeException("Unknown precisionModel: "+modelStr); } } }
/** * Returns the polygon surrounding the specified rectangle. Code lifted from ArcGridDataSource * (temporary). */ public static Polygon getPolygon(final Rectangle2D rect, final int srid) { final PrecisionModel pm = new PrecisionModel(); final GeometryFactory gf = new GeometryFactory(pm, srid); final Coordinate[] coord = new Coordinate[] { new Coordinate(rect.getMinX(), rect.getMinY()), new Coordinate(rect.getMaxX(), rect.getMinY()), new Coordinate(rect.getMaxX(), rect.getMaxY()), new Coordinate(rect.getMinX(), rect.getMaxY()), new Coordinate(rect.getMinX(), rect.getMinY()) }; final LinearRing ring = gf.createLinearRing(coord); return new Polygon(ring, null, gf); }
public void testValidConstruction() throws Exception { Literal a = new LiteralExpressionImpl(new Double(10)); Literal b = new LiteralExpressionImpl("Label"); Literal c = new LiteralExpressionImpl(Integer.valueOf(10)); GeometryFactory gf = new GeometryFactory(new PrecisionModel()); Literal d = new LiteralExpressionImpl(gf.createGeometryCollection(null)); }
private GeometryFactory getGeometryFactory(final Hints queryHints) { // setup the geometry factory according to the hints final Hints hints; if (queryHints == null) { hints = GeoTools.getDefaultHints(); } else { hints = queryHints; } GeometryFactory gf = (GeometryFactory) hints.get(Hints.JTS_GEOMETRY_FACTORY); if (gf == null) { PrecisionModel pm = (PrecisionModel) hints.get(Hints.JTS_PRECISION_MODEL); if (pm == null) { pm = new PrecisionModel(); } Integer SRID = (Integer) hints.get(Hints.JTS_SRID); int srid = SRID == null ? 0 : SRID.intValue(); Integer dimension = (Integer) hints.get(Hints.COORDINATE_DIMENSION); CoordinateSequenceFactory csFactory = (CoordinateSequenceFactory) hints.get(Hints.JTS_COORDINATE_SEQUENCE_FACTORY); if (csFactory == null) { if (dimension == null || dimension <= 3) { csFactory = CoordinateArraySequenceFactory.instance(); } else { csFactory = new LiteCoordinateSequenceFactory(); } } gf = new GeometryFactory(pm, srid, csFactory); } return gf; }
public void testDistanceGeometry() throws Exception { Coordinate[] coords2 = new Coordinate[5]; coords2[0] = new Coordinate(10, 10); coords2[1] = new Coordinate(15, 10); coords2[2] = new Coordinate(15, 15); coords2[3] = new Coordinate(10, 15); coords2[4] = new Coordinate(10, 10); GeometryFactory gf = new GeometryFactory(new PrecisionModel()); Literal right = fac.literal(gf.createPolygon(gf.createLinearRing(coords2), null)); DWithin filter = fac.dwithin(fac.property("testGeometry"), right, 10, "m"); assertAttributeName(filter, "testGeometry"); }
public void testDWithin() throws Exception { // Test DWithin PropertyName left = new AttributeExpressionImpl(testSchema, "testGeometry"); Coordinate[] coords2 = new Coordinate[5]; coords2[0] = new Coordinate(10, 10); coords2[1] = new Coordinate(15, 10); coords2[2] = new Coordinate(15, 15); coords2[3] = new Coordinate(10, 15); coords2[4] = new Coordinate(10, 10); GeometryFactory gf = new GeometryFactory(new PrecisionModel()); Literal right = new LiteralExpressionImpl(gf.createPolygon(gf.createLinearRing(coords2), null)); DWithin filter = fac.dwithin(left, right, 20, "m"); LOGGER.finer(filter.toString()); LOGGER.finer("contains feature: " + filter.evaluate(testFeature)); assertTrue(filter.evaluate(testFeature)); filter = fac.dwithin(left, right, 2, "m"); LOGGER.finer(filter.toString()); LOGGER.finer("contains feature: " + filter.evaluate(testFeature)); assertFalse(filter.evaluate(testFeature)); right = new LiteralExpressionImpl(null); filter = fac.dwithin(left, right, 2, "m"); LOGGER.finer(filter.toString()); LOGGER.finer("contains feature: " + filter.evaluate(testFeature)); assertFalse(filter.evaluate(testFeature)); }
public void testGeometryEquals() throws Exception { Coordinate[] coords = new Coordinate[3]; coords[0] = new Coordinate(1, 2); coords[1] = new Coordinate(3, 4); coords[2] = new Coordinate(5, 6); // Test Equals PropertyName left = new AttributeExpressionImpl(testSchema, "testGeometry"); GeometryFactory gf = new GeometryFactory(new PrecisionModel()); LineString geom = gf.createLineString(coords); Literal right = new LiteralExpressionImpl(geom); Equals filter = fac.equal(left, right); LOGGER.finer(filter.toString()); LOGGER.finer("contains feature: " + filter.evaluate(testFeature)); assertTrue(filter.evaluate(testFeature)); Function function = new GeometryFunction(geom); filter = fac.equal(left, function); LOGGER.finer(filter.toString()); LOGGER.finer("contains feature: " + filter.evaluate(testFeature)); assertTrue(filter.evaluate(testFeature)); coords[0] = new Coordinate(0, 0); right = new LiteralExpressionImpl(geom); filter = fac.equal(left, right); LOGGER.finer(filter.toString()); LOGGER.finer("contains feature: " + filter.evaluate(testFeature)); assertFalse(filter.evaluate(testFeature)); filter = fac.equal(left, new LiteralExpressionImpl(null)); LOGGER.finer(filter.toString()); LOGGER.finer("contains feature: " + filter.evaluate(testFeature)); assertFalse(filter.evaluate(testFeature)); }
GeometryFactory gf = new GeometryFactory(new PrecisionModel()); f[0] = SimpleFeatureBuilder.build(
schema = ftb.buildFeatureType(); GeometryFactory gf = new GeometryFactory(new PrecisionModel()); SimpleFeature[] f = new SimpleFeature[3]; f[0] =
coords[2] = new Coordinate(6, 0); GeometryFactory gf = new GeometryFactory(new PrecisionModel());
public void testDistance3D() { FilterFactoryImpl ff = new FilterFactoryImpl(); GeometryFactory gf = new GeometryFactory(new PrecisionModel()); SimpleFeatureType type = null; try { type = DataUtilities.createType("testSchema", "name:String,*geom:Geometry"); } catch (SchemaException e) { java.util.logging.Logger.getGlobal().log(java.util.logging.Level.INFO, "", e); } Feature f = SimpleFeatureBuilder.build( type, new Object[] {"testFeature1", gf.createPoint(new Coordinate(10, 20, 30))}, null); Literal literal_geom = ff.literal(gf.createPoint(new Coordinate(10, 30, 40))); Function exp = ff.function("distance3D", ff.property("geom"), literal_geom); Object value = exp.evaluate(f); assertTrue(value instanceof Double); assertEquals(14.142135623730951, (Double) value, 0.00001); } }
/** * Test the geometry operators. * * @throws IllegalFilterException If the constructed filter is not valid. */ public void testGeometry() throws IllegalFilterException { Coordinate[] coords = new Coordinate[3]; coords[0] = new Coordinate(1, 2); coords[1] = new Coordinate(3, 4); coords[2] = new Coordinate(5, 6); // Test Equals PropertyName att = fac.property("testGeometry"); GeometryFactory gf = new GeometryFactory(new PrecisionModel()); Literal geom = fac.literal(gf.createLineString(coords)); Equals filter = fac.equal(att, geom); assertAttributeName(filter, "testGeometry"); filter = fac.equal(att, att); assertAttributeName(filter, "testGeometry"); filter = fac.equal(geom, att); assertAttributeName(filter, "testGeometry"); }
public void testDistance3D() { FilterFactoryImpl ff = new FilterFactoryImpl(); GeometryFactory gf = new GeometryFactory(new PrecisionModel()); SimpleFeatureType type = null; try { type = DataUtilities.createType("testSchema", "name:String,*geom:Geometry"); } catch (SchemaException e) { java.util.logging.Logger.getGlobal().log(java.util.logging.Level.INFO, "", e); } Feature f = SimpleFeatureBuilder.build( type, new Object[] {"testFeature1", gf.createPoint(new Coordinate(10, 20, 30))}, null); Literal literal_geom = ff.literal(gf.createPoint(new Coordinate(10, 30, 40))); Literal literal_num = ff.literal(15.0); Function exp = ff.function("isWithinDistance3D", ff.property("geom"), literal_geom, literal_num); Object value = exp.evaluate(f); assertTrue(value instanceof Boolean); assertTrue((Boolean) value); } }
coords2[3] = new Coordinate(10, 15); coords2[4] = new Coordinate(10, 10); GeometryFactory gf = new GeometryFactory(new PrecisionModel()); Literal right = new LiteralExpressionImpl(gf.createPolygon(gf.createLinearRing(coords2), null));
public void testBbox3D() { FilterFactory2 ff = CommonFactoryFinder.getFilterFactory2(); GeometryFactory gf = new GeometryFactory(new PrecisionModel());
GeometryFactory gf = new GeometryFactory(new PrecisionModel()); SimpleFeatureType type = null; try {
public void testGeometryCollection() throws Exception { PrecisionModel precisionModel = new PrecisionModel(); int SRID = 4326; GeometryFactory gf = new GeometryFactory(precisionModel, SRID); Coordinate[] points = {new Coordinate(30, 40), new Coordinate(50, 60)}; LineString[] geometries = new LineString[2]; geometries[0] = gf.createLineString(points); Coordinate[] points2 = {new Coordinate(40, 30), new Coordinate(70, 40)}; geometries[1] = gf.createLineString(points2); GeometryFactory factory = new GeometryFactory(); GeometryCollection geometry = new GeometryCollection(geometries, factory); FilterFactory2 ff = CommonFactoryFinder.getFilterFactory2(null); PropertyName p = ff.property(aname("geom")); Literal collect = ff.literal(geometry); DWithin dwithinGeomCo = ((FilterFactory2) ff).dwithin(p, collect, 5, "meter"); Query dq = new Query(tname("road"), dwithinGeomCo); SimpleFeatureCollection features = dataStore.getFeatureSource(tname("road")).getFeatures(dq); assertEquals(0, features.size()); } }
public void testBounds() throws Exception { PrecisionModel pm = new PrecisionModel(); Geometry[] g = new Geometry[4]; GeometryFactory gf = new GeometryFactory(pm); g[0] = gf.createPoint(new Coordinate(0, 0)); g[1] = gf.createPoint(new Coordinate(0, 10)); g[2] = gf.createPoint(new Coordinate(10, 0)); g[3] = gf.createPoint(new Coordinate(10, 10)); GeometryCollection gc = gf.createGeometryCollection(g); SimpleFeatureTypeBuilder tb = new SimpleFeatureTypeBuilder(); tb.setName("bounds"); tb.setCRS(null); tb.add("p1", Point.class); SimpleFeatureType t = tb.buildFeatureType(); TreeSetFeatureCollection fc = new TreeSetFeatureCollection(null, t); SimpleFeatureBuilder b = new SimpleFeatureBuilder(t); for (int i = 0; i < g.length; i++) { b.add(g[i]); fc.add(b.buildFeature(null)); } assertEquals(gc.getEnvelopeInternal(), fc.getBounds()); }