/** * 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); } }
/** * Get the union. * * @param r the other geometry * @return the union of this geometry envelope and another geometry envelope */ public Value getEnvelopeUnion(ValueGeometry r) { GeometryFactory gf = new GeometryFactory(); Envelope mergedEnvelope = new Envelope(getGeometryNoCopy().getEnvelopeInternal()); mergedEnvelope.expandToInclude(r.getGeometryNoCopy().getEnvelopeInternal()); return get(gf.toGeometry(mergedEnvelope)); }
GeometryFactory geometryFactory = new GeometryFactory(); QueryGraph queryGraph = new QueryGraph(graphHopperStorage); final EdgeFilter filter = DefaultEdgeFilter.allEdges(graphHopperStorage.getEncodingManager().getEncoder("foot"));
GeometryFactory gf = new GeometryFactory(); SimpleFeatureType featureType = DataUtilities.createType(
public LineString toLineString(boolean includeElevation) { GeometryFactory gf = new GeometryFactory(); Coordinate[] coordinates = new Coordinate[getSize() == 1 ? 2 : getSize()]; for (int i = 0; i < getSize(); i++) { coordinates[i] = includeElevation ? new Coordinate( round6(getLongitude(i)), round6(getLatitude(i)), round2(getElevation(i))) : new Coordinate( round6(getLongitude(i)), round6(getLatitude(i))); } // special case as just 1 point is not supported in the specification #1412 if (getSize() == 1) coordinates[1] = coordinates[0]; return gf.createLineString(coordinates); }
@Override public boolean startObject() throws ParseException, IOException { if (properties == NULL_LIST) { properties = new ArrayList(); } else if (properties != null) { // start of a new object in properties means a geometry delegate = new GeometryHandler(new GeometryFactory()); } return super.startObject(); }
/** * Converts an arbitrary Java2D shape into a JTS geometry. The created JTS geometry may be any * of {@link LineString}, {@link LinearRing} or {@link MultiLineString}. * * @param shape the input shape * @return A new JTS geometry instance * @throws IllegalArgumentException if {@code shape} is {@code null} */ public static Geometry toGeometry(final Shape shape) { return toGeometry(shape, new GeometryFactory()); }
@Override protected Geometry getEmpty() { if (EMPTY == null) { EMPTY = new GeometryFactory().createMultiPolygon(null); } return EMPTY; }
private GeometryFactory findGeometryFactory(Hints hints) { GeometryFactory geomFactory = (GeometryFactory) hints.get(Hints.JTS_GEOMETRY_FACTORY); if (geomFactory == null) { CoordinateSequenceFactory seqFac; seqFac = (CoordinateSequenceFactory) hints.get(Hints.JTS_COORDINATE_SEQUENCE_FACTORY); if (seqFac == null) { seqFac = PackedCoordinateSequenceFactory.DOUBLE_FACTORY; } geomFactory = new GeometryFactory(seqFac); } return geomFactory; }
public TestData(int initialFidValue) throws Exception { this.initialFidValue = initialFidValue; gf = new GeometryFactory(); ff = CommonFactoryFinder.getFilterFactory(null); }
public void testIntersectsFilterFunctionUnreferencedGeometry() throws Exception { GeometryFactory gf = new GeometryFactory(); LineString ls = gf.createLineString( new Coordinate[] {new Coordinate(10, 15), new Coordinate(20, 25)}); Function intersects = ff.function("intersects", ff.property("geom"), ff.literal(ls)); Function clone = (Function) intersects.accept(reprojector, null); assertNotSame(intersects, clone); assertEquals(clone.getParameters().get(0), intersects.getParameters().get(0)); assertEquals(clone.getParameters().get(1), intersects.getParameters().get(1)); }
/** Tests encoding for X, Y, M ordinates number */ @Test public void testEncodeXYM() throws Exception { GeometryFactory gf = new GeometryFactory(); Point pointM = gf.createPoint(new CoordinateXYM(1, 1, 4)); CoordinateSequence seq = pointM.getCoordinateSequence(); Document doc = encode(seq, GML.pos); checkPosOrdinates(doc, 4); }
public void testEncode3DLineFromLiteCS() throws Exception { LineStringEncoder encoder = new LineStringEncoder(gtEncoder, "gml", GML.NAMESPACE); LiteCoordinateSequence cs = new LiteCoordinateSequence(new double[] {0, 0, 50, 120, 0, 100}, 3); LineString geometry = new GeometryFactory().createLineString(cs); Document doc = encode(encoder, geometry); // print(doc); assertEquals("0 0 50 120 0 100", xpath.evaluate("//gml:posList", doc)); } }
protected void addFeature(SimpleFeatureType featureType, JDBCFeatureStore features) throws Exception { SimpleFeatureBuilder b = new SimpleFeatureBuilder(featureType); b.add("four"); b.add(new GeometryFactory().createPoint(new Coordinate(4, 4))); SimpleFeature f = b.buildFeature(null); features.addFeatures(DataUtilities.collection(f)); // pattern match to handle the multi primary key case assertTrue( ((String) f.getUserData().get("fid")) .matches(tname(featureType.getTypeName()) + ".4(\\..*)?")); }
private SimpleFeatureCollection createLineFeatureCollection() throws Exception { AttributeDescriptor[] types = new AttributeDescriptor[2]; GeometryFactory geomFac = new GeometryFactory(); CoordinateReferenceSystem crs = DefaultGeographicCRS.WGS84; MemoryDataStore data = new MemoryDataStore(); data.addFeature(createLineFeature("LongLabel1", crs, geomFac, 10, 0, 0, 10)); data.addFeature(createLineFeature("LongLabel2", crs, geomFac, 10, 10, 0, 0)); // data.addFeature(createPointFeature(0,2,"LongLabel3",crs, geomFac, types)); // data.addFeature(createPointFeature(2,0,"Label4",crs, geomFac, types)); // data.addFeature(createPointFeature(0,4,"LongLabel6",crs, geomFac, types)); return data.getFeatureSource(Rendering2DTest.LINE).getFeatures(); }
public void testEncodePointZMFromLiteCSNoMeasuresEncoded() throws Exception { // create a point with M values and encode it in GML LiteCoordinateSequence cs = new LiteCoordinateSequence(new double[] {0, 1, 10, -1.5}, 4, 1); Point geometry = new GeometryFactory().createPoint(cs); PointEncoder encoder = new PointEncoder(gtEncoder, "gml", GML.NAMESPACE); Document document = encode(encoder, geometry, false, "line"); // check that we got the expected result XpathEngine xpath = XMLUnit.newXpathEngine(); // print(document); assertEquals("0 1 10", xpath.evaluate("//gml:pos", document)); } }
@Test public void testDWithin() { Point geom = new GeometryFactory().createPoint(new Coordinate(0, 0)); Filter filter = ff.dwithin(ff.property("name"), ff.literal(geom), 100, "metre"); Envelope env = (Envelope) filter.accept(visitor, null); assertEquals(new Envelope(-100, 100, -100, 100), env); }
@Test public void testDisjoint() { Coordinate[] coords = new Coordinate[] {new Coordinate(0, 0), new Coordinate(10, 10)}; LineString lineString = new GeometryFactory().createLineString(coords); Filter filter = ff.disjoint(ff.property("name"), ff.literal(lineString)); Envelope env = (Envelope) filter.accept(visitor, null); assertEquals(infinity, env); }
public void testIntersectsUnreferencedGeometry() throws Exception { GeometryFactory gf = new GeometryFactory(); LineString ls = gf.createLineString( new Coordinate[] {new Coordinate(10, 15), new Coordinate(20, 25)}); // see if coordinates gets flipped, urn forces lat/lon interpretation Intersects original = ff.intersects(ff.property("geom"), ff.literal(ls)); Filter clone = (Filter) original.accept(reprojector, null); assertNotSame(original, clone); assertEquals(original, clone); }
public void testIntersectsRingFilter() throws Exception { FilterFactory2 ff = CommonFactoryFinder.getFilterFactory2(null); // should match only "r1" GeometryFactory gf = new GeometryFactory(); PackedCoordinateSequenceFactory sf = new PackedCoordinateSequenceFactory(); LineString ls = gf.createLinearRing(sf.create(new double[] {2, 1, 2, 3, 0, 3, 2, 1}, 2)); Intersects is = ff.intersects(ff.property(aname("geom")), ff.literal(ls)); FeatureCollection features = dataStore.getFeatureSource(tname("road")).getFeatures(is); checkSingleResult(features, "r1"); }