org.locationtech.jts.geom.GeometryFactory Java Examples
The following examples show how to use
org.locationtech.jts.geom.GeometryFactory.
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: ExtractGeometryFilterVisitorTest.java From geowave with Apache License 2.0 | 6 votes |
@Test public void testOverlaps() throws CQLException, TransformException, ParseException { final Filter filter = CQL.toFilter( String.format( "OVERLAPS(%s, POLYGON((0 0, 0 25, 10 25, 10 0, 0 0)))", geomAttributeName)); final Query query = new Query("type", filter); final ExtractGeometryFilterVisitorResult result = (ExtractGeometryFilterVisitorResult) query.getFilter().accept(visitorWithDescriptor, null); final Envelope bounds = new Envelope(0, 10, 0, 25); final Geometry bbox = new GeometryFactory().toGeometry(bounds); assertTrue(bbox.equalsTopo(result.getGeometry())); assertTrue(result.getCompareOp() == CompareOperation.OVERLAPS); }
Example #2
Source File: GeophilePointWithinDistanceQueryPlan.java From fdb-record-layer with Apache License 2.0 | 6 votes |
@Nullable @Override protected SpatialJoin.Filter<RecordWithSpatialObject, GeophileRecordImpl> getFilter(@Nonnull EvaluationContext context) { if (covering) { Double distanceValue = distance.getValue(context); Double centerLatitudeValue = centerLatitude.getValue(context); Double centerLongitudeValue = centerLongitude.getValue(context); if (distanceValue == null || centerLatitudeValue == null || centerLongitudeValue == null) { return null; } final GeometryFactory geometryFactory = new GeometryFactory(); final Geometry center = geometryFactory.createPoint(new Coordinate(centerLatitudeValue, centerLongitudeValue)); return (spatialObject, record) -> { Point point = (Point)record.spatialObject(); Geometry geometry = geometryFactory.createPoint(new Coordinate(point.x(), point.y())); return geometry.isWithinDistance(center, distanceValue); }; } else { return null; } }
Example #3
Source File: FeatureUtilities.java From geopaparazzi with GNU General Public License v3.0 | 6 votes |
/** * Tries to split an invalid polygon in its {@link GeometryCollection}. * <p/> * <p>Based on JTSBuilder code. * * @param invalidPolygon the invalid polygon. * @return the geometries. */ @SuppressWarnings("rawtypes") public static Geometry invalidPolygonSplit(Geometry invalidPolygon) { PrecisionModel pm = new PrecisionModel(10000000); GeometryFactory geomFact = invalidPolygon.getFactory(); List lines = LinearComponentExtracter.getLines(invalidPolygon); List nodedLinework = new GeometryNoder(pm).node(lines); // union the noded linework to remove duplicates Geometry nodedDedupedLinework = geomFact.buildGeometry(nodedLinework).union(); // polygonize the result Polygonizer polygonizer = new Polygonizer(); polygonizer.add(nodedDedupedLinework); Collection polys = polygonizer.getPolygons(); // convert to collection for return Polygon[] polyArray = GeometryFactory.toPolygonArray(polys); return geomFact.createGeometryCollection(polyArray); }
Example #4
Source File: SplitsProviderIT.java From geowave with Apache License 2.0 | 6 votes |
@Test public void testBimodal() { ingestWithDistribution(Distribution.BIMODAL); QueryConstraints query = new ExplicitSpatialQuery( new GeometryFactory().toGeometry(new Envelope(-180, 180, -90, 90))); assertTrue(getSplitsMSE(query, 12, 12) < 0.1); query = new ExplicitSpatialQuery( new GeometryFactory().toGeometry(new Envelope(-120, -60, -90, 90))); assertTrue(getSplitsMSE(query, 12, 12) < 0.1); query = new ExplicitSpatialQuery(new GeometryFactory().toGeometry(new Envelope(-20, 20, -90, 90))); assertTrue(getSplitsMSE(query, 12, 12) < 0.1); }
Example #5
Source File: GeometryUtils.java From geowave with Apache License 2.0 | 6 votes |
/** * Recursively decompose geometry into a set of envelopes to create a single set. * * @param geometry * @param destinationListOfSets * @param checkTopoEquality */ private static boolean constructListOfConstraintSetsFromGeometry( final Geometry geometry, final List<ConstraintSet> destinationListOfSets, final boolean checkTopoEquality) { // Get the envelope of the geometry being held final int n = geometry.getNumGeometries(); boolean retVal = true; if (n > 1) { retVal = false; for (int gi = 0; gi < n; gi++) { constructListOfConstraintSetsFromGeometry( geometry.getGeometryN(gi), destinationListOfSets, checkTopoEquality); } } else { final Envelope env = geometry.getEnvelopeInternal(); destinationListOfSets.add(basicConstraintSetFromEnvelope(env)); if (checkTopoEquality) { retVal = new GeometryFactory().toGeometry(env).equalsTopo(geometry); } } return retVal; }
Example #6
Source File: ElasticGeometryFilterIT.java From elasticgeo with GNU General Public License v3.0 | 6 votes |
@Test public void testDWithinFilter() throws Exception { init(); FilterFactory2 ff = (FilterFactory2) dataStore.getFilterFactory(); GeometryFactory gf = new GeometryFactory(); PackedCoordinateSequenceFactory sf = new PackedCoordinateSequenceFactory(); Point ls = gf.createPoint(sf.create(new double[] { 0, 0 }, 2)); DWithin f = ff.dwithin(ff.property("geo"), ff.literal(ls), 3, "m"); SimpleFeatureCollection features = featureSource.getFeatures(f); assertEquals(2, features.size()); SimpleFeatureIterator fsi = features.features(); assertTrue(fsi.hasNext()); assertEquals(fsi.next().getID(), "active.01"); assertTrue(fsi.hasNext()); assertEquals(fsi.next().getID(), "active.10"); }
Example #7
Source File: ElasticGeometryFilterIT.java From elasticgeo with GNU General Public License v3.0 | 6 votes |
@Test public void testGeoPointAsArray() throws Exception { init("active","geo5"); FilterFactory2 ff = (FilterFactory2) dataStore.getFilterFactory(); GeometryFactory gf = new GeometryFactory(); PackedCoordinateSequenceFactory sf = new PackedCoordinateSequenceFactory(); Point ls = gf.createPoint(sf.create(new double[] { 0, 0 }, 2)); DWithin f = ff.dwithin(ff.property("geo5"), ff.literal(ls), 3, "m"); SimpleFeatureCollection features = featureSource.getFeatures(f); assertEquals(2, features.size()); SimpleFeatureIterator fsi = features.features(); assertTrue(fsi.hasNext()); SimpleFeature feature = fsi.next(); assertEquals(feature.getID(), "active.01"); assertNotNull(feature.getDefaultGeometry()); assertTrue(fsi.hasNext()); feature = fsi.next(); assertEquals(feature.getID(), "active.10"); assertNotNull(feature.getDefaultGeometry()); }
Example #8
Source File: ElasticGeometryFilterIT.java From elasticgeo with GNU General Public License v3.0 | 6 votes |
@Test public void testGeoShapeAsWkt() throws Exception { if (client.getVersion() < 6.2) { // wkt unsupported prior to v6.2 return; } init("not-active","geo6"); FilterFactory2 ff = (FilterFactory2) dataStore.getFilterFactory(); GeometryFactory gf = new GeometryFactory(); PackedCoordinateSequenceFactory sf = new PackedCoordinateSequenceFactory(); LineString ls = gf.createLineString(sf.create(new double[] { 0, 0, 2, 2 }, 2)); Crosses f = ff.crosses(ff.property("geo3"), ff.literal(ls)); SimpleFeatureCollection features = featureSource.getFeatures(f); assertEquals(1, features.size()); SimpleFeatureIterator fsi = features.features(); assertTrue(fsi.hasNext()); assertEquals(fsi.next().getID(), "active.12"); sf = new PackedCoordinateSequenceFactory(); ls = gf.createLineString(sf.create(new double[] { 0, 0, 1, 1 }, 2)); f = ff.crosses(ff.property("geo5"), ff.literal(ls)); features = featureSource.getFeatures(f); assertEquals(0, features.size()); }
Example #9
Source File: ExtractGeometryFilterVisitorTest.java From geowave with Apache License 2.0 | 6 votes |
@Test public void testEquals() throws CQLException, TransformException, ParseException { final Filter filter = CQL.toFilter( String.format( "EQUALS(geom, POLYGON((0 0, 0 25, 10 25, 10 0, 0 0)))", geomAttributeName)); final Query query = new Query("type", filter); final ExtractGeometryFilterVisitorResult result = (ExtractGeometryFilterVisitorResult) query.getFilter().accept(visitorWithDescriptor, null); final Envelope bounds = new Envelope(0, 10, 0, 25); final Geometry bbox = new GeometryFactory().toGeometry(bounds); assertTrue(bbox.equalsTopo(result.getGeometry())); assertTrue(result.getCompareOp() == CompareOperation.EQUALS); }
Example #10
Source File: CSVUtil.java From searoute with European Union Public License 1.2 | 6 votes |
/** * Transform CSV data into a feature collection, with point geometry. * * @param csvData * @param xCol * @param yCol * @return */ public static Collection<Feature> CSVToFeatures(Collection<Map<String, String>> csvData, String xCol, String yCol) { Collection<Feature> out = new ArrayList<Feature>(); GeometryFactory gf = new GeometryFactory(); for (Map<String, String> h : csvData) { Feature f = new Feature(); Coordinate c = new Coordinate(0,0); for(Entry<String,String> e : h.entrySet()) { if(xCol.equals(e.getKey())) c.x = Double.parseDouble(e.getValue()); if(yCol.equals(e.getKey())) c.y = Double.parseDouble(e.getValue()); f.setAttribute(e.getKey(), e.getValue()); } f.setGeometry(gf.createPoint(c)); out.add(f); } return out; }
Example #11
Source File: SpatialTemporalQueryIT.java From geowave with Apache License 2.0 | 6 votes |
private static void ingestTimeRangeDataForDuplicateDeletion( final Calendar cal, final Writer writer, final SimpleFeatureBuilder featureTimeRangeBuilder, final int min, final int max, final int field, final String name) throws IOException { final GeometryFactory geomFactory = new GeometryFactory(); cal.set(field, min); featureTimeRangeBuilder.add(geomFactory.createPoint(new Coordinate(0, 0))); featureTimeRangeBuilder.add(cal.getTime()); cal.set(field, max); featureTimeRangeBuilder.add(cal.getTime()); final SimpleFeature feature = featureTimeRangeBuilder.buildFeature(name + ":fullrange"); writer.write(feature); }
Example #12
Source File: ProfileValue.java From arctic-sea with Apache License 2.0 | 6 votes |
public Geometry getGeometry() { if (isSetGeometry()) { TreeMap<Time, Coordinate> map = new TreeMap<>(); int srid = -1; for (ProfileLevel level : getValue()) { if (level.isSetPhenomenonTime() && level.isSetLocation()) { if (srid < 0) { srid = level.getLocation().getSRID(); } map.put(level.getPhenomenonTime(), level.getLocation().getCoordinate()); } } if (!map.isEmpty()) { if (new HashSet<>(map.values()).size() == 1) { return getValue().iterator().next().getLocation(); } else { return new GeometryFactory(new PrecisionModel(), srid) .createLineString(map.values().toArray(new Coordinate[1])); } } } return null; }
Example #13
Source File: GMLConfiguration.java From GeoTriples with Apache License 2.0 | 6 votes |
/** * Configures the gml3 context. * <p> * The following factories are registered: * <ul> * <li>{@link CoordinateArraySequenceFactory} under {@link CoordinateSequenceFactory} * <li>{@link GeometryFactory} * </ul> * </p> */ public void configureContext(MutablePicoContainer container) { super.configureContext(container); container.registerComponentInstance(new FeatureTypeCache()); container.registerComponentInstance(new XSDIdRegistry()); //factories container.registerComponentInstance(CoordinateSequenceFactory.class, CoordinateArraySequenceFactory.instance()); container.registerComponentImplementation(GeometryFactory.class); container.registerComponentInstance(new GML3EncodingUtils()); if (isExtendedArcSurfaceSupport()) { container.registerComponentInstance(new ArcParameters()); } container.registerComponentInstance(srsSyntax); }
Example #14
Source File: SplitsProviderIT.java From geowave with Apache License 2.0 | 6 votes |
@Test public void testSkewed() { ingestWithDistribution(Distribution.SKEWED); QueryConstraints query = new ExplicitSpatialQuery( new GeometryFactory().toGeometry(new Envelope(-180, 180, -90, 90))); assertTrue(getSplitsMSE(query, 12, 12) < 0.1); query = new ExplicitSpatialQuery( new GeometryFactory().toGeometry(new Envelope(-180, -140, -90, 90))); assertTrue(getSplitsMSE(query, 12, 12) < 0.1); query = new ExplicitSpatialQuery(new GeometryFactory().toGeometry(new Envelope(0, 180, -90, 90))); assertTrue(getSplitsMSE(query, 12, 12) < 0.1); }
Example #15
Source File: FilterToElastic.java From elasticgeo with GNU General Public License v3.0 | 6 votes |
private void visitLiteralGeometry(Literal expression) throws IOException { // evaluate the literal and store it for later currentGeometry = (Geometry) evaluateLiteral(expression, Geometry.class); if ( currentGeometry instanceof LinearRing ) { // convert LinearRing to LineString final GeometryFactory factory = currentGeometry.getFactory(); final LinearRing linearRing = (LinearRing) currentGeometry; final CoordinateSequence coordinates; coordinates = linearRing.getCoordinateSequence(); currentGeometry = factory.createLineString(coordinates); } final String geoJson = new GeometryJSON().toString(currentGeometry); currentShapeBuilder = mapReader.readValue(geoJson); }
Example #16
Source File: GeoJSONDecoder.java From arctic-sea with Apache License 2.0 | 6 votes |
protected GeometryFactory decodeCRS(JsonNode node, GeometryFactory factory) throws GeoJSONDecodingException { if (!node.path(JSONConstants.CRS).hasNonNull(JSONConstants.TYPE)) { throw new GeoJSONDecodingException("Missing CRS type"); } String type = node.path(JSONConstants.CRS).path(JSONConstants.TYPE).textValue(); JsonNode properties = node.path(JSONConstants.CRS).path(JSONConstants.PROPERTIES); switch (type) { case JSONConstants.NAME: return decodeNamedCRS(properties, factory); case JSONConstants.LINK: return decodeLinkedCRS(properties, factory); default: throw new GeoJSONDecodingException("Unknown CRS type: " + type); } }
Example #17
Source File: GeoWaveGeometryPrecisionIT.java From geowave with Apache License 2.0 | 6 votes |
@Test public void testPrecision3() { final GeometryFactory factory = GeometryUtils.GEOMETRY_FACTORY; final Geometry[] geometries = new Geometry[] { factory.createPoint(new Coordinate(12.123456789, -10.987654321)), factory.createLineString( new Coordinate[] { new Coordinate(123456789.987654321, -123456789.987654321), new Coordinate(987654321.123456789, -987654321.123456789)}), factory.createPoint(new Coordinate(0, 0))}; final Geometry[] expected = new Geometry[] { factory.createPoint(new Coordinate(12.123, -10.988)), factory.createLineString( new Coordinate[] { new Coordinate(123456789.988, -123456789.988), new Coordinate(987654321.123, -987654321.123)}), factory.createPoint(new Coordinate(0, 0))}; testPrecision(geometries, expected, 3); }
Example #18
Source File: GeoFunctions.java From presto with Apache License 2.0 | 6 votes |
private static void buildPointsBlock(Geometry geometry, BlockBuilder blockBuilder) { GeometryType type = GeometryType.getForJtsGeometryType(geometry.getGeometryType()); if (type == GeometryType.POINT) { GEOMETRY.writeSlice(blockBuilder, JtsGeometrySerde.serialize(geometry)); } else if (type == GeometryType.GEOMETRY_COLLECTION) { GeometryCollection collection = (GeometryCollection) geometry; for (int i = 0; i < collection.getNumGeometries(); i++) { Geometry entry = collection.getGeometryN(i); buildPointsBlock(entry, blockBuilder); } } else { GeometryFactory geometryFactory = geometry.getFactory(); Coordinate[] vertices = geometry.getCoordinates(); for (Coordinate coordinate : vertices) { GEOMETRY.writeSlice(blockBuilder, JtsGeometrySerde.serialize(geometryFactory.createPoint(coordinate))); } } }
Example #19
Source File: QueryIndexHelper.java From geowave with Apache License 2.0 | 6 votes |
/** * Clip the provided bounded box with the statistics for the index */ public static Geometry clipIndexedBBOXConstraints( final SimpleFeatureType featureType, final Geometry bbox, final Map<StatisticsId, InternalDataStatistics<SimpleFeature, ?, ?>> statsMap) { final String geoAttrName = featureType.getGeometryDescriptor().getLocalName(); final StatisticsId statId = VectorStatisticsQueryBuilder.newBuilder().factory().bbox().fieldName( geoAttrName).build().getId(); final BoundingBoxDataStatistics bboxStats = (BoundingBoxDataStatistics) statsMap.get(statId); if ((bboxStats != null) && bboxStats.isSet() && (bbox != null)) { final Geometry geo = new GeometryFactory().toGeometry(bboxStats.getResult()); return geo.intersection(bbox); } return bbox; }
Example #20
Source File: JTSTest.java From sis with Apache License 2.0 | 6 votes |
/** * Tests {@link JTS#getCoordinateReferenceSystem(Geometry)}. * * @throws FactoryException if an EPSG code can not be resolved. */ @Test public void testGetCoordinateReferenceSystem() throws FactoryException { final GeometryFactory factory = new GeometryFactory(); final Geometry geometry = factory.createPoint(new Coordinate(5, 6)); CoordinateReferenceSystem crs = JTS.getCoordinateReferenceSystem(geometry); assertNull(crs); /* * Test CRS as user data. */ geometry.setUserData(CommonCRS.ED50.geographic()); assertEquals(CommonCRS.ED50.geographic(), JTS.getCoordinateReferenceSystem(geometry)); /* * Test CRS as map value. */ geometry.setUserData(Collections.singletonMap(JTS.CRS_KEY, CommonCRS.NAD83.geographic())); assertEquals(CommonCRS.NAD83.geographic(), JTS.getCoordinateReferenceSystem(geometry)); /* * Test CRS as srid. */ geometry.setUserData(null); geometry.setSRID(4326); assertEquals(CommonCRS.WGS84.geographic(), JTS.getCoordinateReferenceSystem(geometry)); }
Example #21
Source File: CommonQueries.java From hortonmachine with GNU General Public License v3.0 | 6 votes |
/** * Calculates the GeodesicLength between to points. * * @param connection the database connection. * @param p1 the first point. * @param p2 the second point. * @param srid the srid. If <0, 4326 will be used. This needs to be a geographic prj. * @return the distance. * @throws Exception */ public static double getDistanceBetween( IHMConnection connection, Coordinate p1, Coordinate p2, int srid ) throws Exception { if (srid < 0) { srid = 4326; } GeometryFactory gf = new GeometryFactory(); LineString lineString = gf.createLineString(new Coordinate[]{p1, p2}); String sql = "select GeodesicLength(LineFromText(\"" + lineString.toText() + "\"," + srid + "));"; try (IHMStatement stmt = connection.createStatement(); IHMResultSet rs = stmt.executeQuery(sql);) { if (rs.next()) { double length = rs.getDouble(1); return length; } throw new RuntimeException("Could not calculate distance."); } }
Example #22
Source File: ExtractGeometryFilterVisitorTest.java From geowave with Apache License 2.0 | 6 votes |
@Test public void testIntesectAndCrossesAndLike() throws CQLException, TransformException, ParseException { // we are testing to see if we are able to combine dissimilar geometric // relations correctly // to extract query geometry. Note, that returned predicate is null // since we can't represent // CQL expression fully into single query geometry and predicate final Filter filter = CQL.toFilter( String.format( "CROSSES(%s, POLYGON((0 0, 0 25, 10 25, 10 0, 0 0))) AND location == 'abc'", geomAttributeName)); final Query query = new Query("type", filter); final ExtractGeometryFilterVisitorResult result = (ExtractGeometryFilterVisitorResult) query.getFilter().accept(visitorWithDescriptor, null); final Envelope bounds = new Envelope(0, 10, 0, 25); final Geometry bbox = new GeometryFactory().toGeometry(bounds); assertTrue(bbox.equalsTopo(result.getGeometry())); assertTrue(result.getCompareOp() == null); }
Example #23
Source File: VectorTileEncoderPerformanceTest.java From java-vector-tile with Apache License 2.0 | 6 votes |
/** * A utility to help benchmark the building performance of large Point based * vector tiles. This adds 512x512 "pixels" of data 100 times, allowing a * profiler to connect and determine where the bottlenecks are. */ public void testManyPoints() { int tileSize = 512; Map<String, Object> empty = Collections.emptyMap(); for (int i = 0; i < 100; i++) { VectorTileEncoder encoder = new VectorTileEncoder(tileSize, 0, false); GeometryFactory geometryFactory = new GeometryFactory(); Stopwatch sw = new Stopwatch(); int features = 0; for (int x = 0; x < tileSize; x++) { for (int y = 0; y < tileSize; y++) { Geometry geom = geometryFactory.createPoint(new Coordinate(x, y)); encoder.addFeature("layer1", empty, geom); features++; } } System.out.println("Added " + features + " in " + sw.getTime() + "msecs"); } }
Example #24
Source File: SpatialQueryTest.java From geowave with Apache License 2.0 | 6 votes |
@Test public void test() { final GeometryFactory factory = new GeometryFactory(); final ExplicitSpatialQuery query = new ExplicitSpatialQuery( factory.createPolygon( new Coordinate[] { new Coordinate(24, 33), new Coordinate(28, 33), new Coordinate(28, 31), new Coordinate(24, 31), new Coordinate(24, 33)})); final ExplicitSpatialQuery queryCopy = new ExplicitSpatialQuery(); queryCopy.fromBinary(query.toBinary()); assertEquals(queryCopy.getQueryGeometry(), query.getQueryGeometry()); }
Example #25
Source File: SubsetUI.java From snap-desktop with GNU General Public License v3.0 | 6 votes |
private void getGeoRegion() { geoRegion = null; geoText.setText(""); if (geoCoordRadio.isSelected()) { final GeoPos[] selectionBox = worldMapUI.getSelectionBox(); if (selectionBox != null) { final Coordinate[] coords = new Coordinate[selectionBox.length + 1]; for (int i = 0; i < selectionBox.length; ++i) { coords[i] = new Coordinate(selectionBox[i].getLon(), selectionBox[i].getLat()); } coords[selectionBox.length] = new Coordinate(selectionBox[0].getLon(), selectionBox[0].getLat()); final GeometryFactory geometryFactory = new GeometryFactory(); final LinearRing linearRing = geometryFactory.createLinearRing(coords); geoRegion = geometryFactory.createPolygon(linearRing, null); geoText.setText(geoRegion.toText()); } } }
Example #26
Source File: ExtractGeometryFilterVisitorTest.java From geowave with Apache License 2.0 | 6 votes |
@Test public void testIntersects() throws CQLException, TransformException, ParseException { final Filter filter = CQL.toFilter( String.format( "INTERSECTS(%s, POLYGON((0 0, 0 25, 10 25, 10 0, 0 0)))", geomAttributeName)); final Query query = new Query("type", filter); final ExtractGeometryFilterVisitorResult result = (ExtractGeometryFilterVisitorResult) query.getFilter().accept(visitorWithDescriptor, null); final Envelope bounds = new Envelope(0, 10, 0, 25); final Geometry bbox = new GeometryFactory().toGeometry(bounds); assertTrue(bbox.equalsTopo(result.getGeometry())); assertTrue(result.getCompareOp() == CompareOperation.INTERSECTS); }
Example #27
Source File: ElasticGeometryFilterIT.java From elasticgeo with GNU General Public License v3.0 | 5 votes |
@Test public void testBeyondFilter() throws Exception { init(); FilterFactory2 ff = (FilterFactory2) dataStore.getFilterFactory(); GeometryFactory gf = new GeometryFactory(); PackedCoordinateSequenceFactory sf = new PackedCoordinateSequenceFactory(); Point ls = gf.createPoint(sf.create(new double[] { 0, 0 }, 2)); Beyond f = ff.beyond(ff.property("geo"), ff.literal(ls), 1, "m"); SimpleFeatureCollection features = featureSource.getFeatures(f); assertEquals(9, features.size()); }
Example #28
Source File: ElasticGeometryFilterIT.java From elasticgeo with GNU General Public License v3.0 | 5 votes |
@Test public void testNotCrossesFilter() throws Exception { init("not-active","geo3"); FilterFactory2 ff = (FilterFactory2) dataStore.getFilterFactory(); GeometryFactory gf = new GeometryFactory(); PackedCoordinateSequenceFactory sf = new PackedCoordinateSequenceFactory(); LineString ls = gf.createLineString(sf.create(new double[] { 0, 0, 1, 1 }, 2)); Crosses f = ff.crosses(ff.property("geo3"), ff.literal(ls)); SimpleFeatureCollection features = featureSource.getFeatures(f); assertEquals(0, features.size()); }
Example #29
Source File: SpatialTemporalQueryIT.java From geowave with Apache License 2.0 | 5 votes |
private static void ingestTimeRangeData( final Calendar cal, final Writer writer, final SimpleFeatureBuilder featureTimeRangeBuilder, final int min, final int max, final int field, final String name) throws IOException { final GeometryFactory geomFactory = new GeometryFactory(); final int midPoint = (int) Math.floor((min + max) / 2.0); cal.set(field, min); featureTimeRangeBuilder.add(geomFactory.createPoint(new Coordinate(0, 0))); featureTimeRangeBuilder.add(cal.getTime()); cal.set(field, max); featureTimeRangeBuilder.add(cal.getTime()); SimpleFeature feature = featureTimeRangeBuilder.buildFeature(name + ":fullrange"); writer.write(feature); cal.set(field, min); featureTimeRangeBuilder.add(geomFactory.createPoint(new Coordinate(-0.1, -0.1))); featureTimeRangeBuilder.add(cal.getTime()); cal.set(field, midPoint); featureTimeRangeBuilder.add(cal.getTime()); feature = featureTimeRangeBuilder.buildFeature(name + ":firsthalfrange"); writer.write(feature); featureTimeRangeBuilder.add(geomFactory.createPoint(new Coordinate(0.1, 0.1))); featureTimeRangeBuilder.add(cal.getTime()); cal.set(field, max); featureTimeRangeBuilder.add(cal.getTime()); feature = featureTimeRangeBuilder.buildFeature(name + ":secondhalfrange"); writer.write(feature); }
Example #30
Source File: ElasticGeometryFilterIT.java From elasticgeo with GNU General Public License v3.0 | 5 votes |
@Test public void testContainsFilter() throws Exception { init("not-active","geo3"); FilterFactory2 ff = (FilterFactory2) dataStore.getFilterFactory(); GeometryFactory gf = new GeometryFactory(); PackedCoordinateSequenceFactory sf = new PackedCoordinateSequenceFactory(); Polygon ls = gf.createPolygon(sf.create(new double[] { 2, 2, 3, 2, 3, 3, 2, 3, 2, 2 }, 2)); Contains f = ff.contains(ff.property("geo3"), ff.literal(ls)); SimpleFeatureCollection features = featureSource.getFeatures(f); assertEquals(1, features.size()); SimpleFeatureIterator fsi = features.features(); assertTrue(fsi.hasNext()); assertEquals(fsi.next().getID(), "active.12"); }