com.esri.core.geometry.Geometry.Type Java Examples
The following examples show how to use
com.esri.core.geometry.Geometry.Type.
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: TestIntersect2.java From geometry-api-java with Apache License 2.0 | 6 votes |
@Test public void testPointAndMultiPoint1() { Point basePl = new Point(-116, 20); MultiPoint compPl = new MultiPoint(); compPl.add(new Point(-116, 20)); compPl.add(new Point(-118, 21)); int noException = 1; // no exception Geometry intersectGeom = null; try { intersectGeom = GeometryEngine.intersect(basePl, compPl, SpatialReference.create(4326)); } catch (Exception ex) { noException = 0; } assertEquals(noException, 1); assertNotNull(intersectGeom); assertTrue(intersectGeom.getType() == Type.Point); Point ip = (Point) intersectGeom; assertEquals(ip.getX(), -116, 0.1E7); assertEquals(ip.getY(), 20, 0.1E7); }
Example #2
Source File: TestIntersect2.java From geometry-api-java with Apache License 2.0 | 6 votes |
@Test public void testPointAndPoint1() { Point basePl = new Point(-116, 20); Point compPl = new Point(-116, 20); int noException = 1; // no exception Geometry intersectGeom = null; try { intersectGeom = GeometryEngine.intersect(basePl, compPl, SpatialReference.create(4326)); } catch (Exception ex) { noException = 0; } assertEquals(noException, 1); assertNotNull(intersectGeom); assertTrue(intersectGeom.getType() == Type.Point); Point ip = (Point) intersectGeom; assertEquals(ip.getX(), -116, 0.1E7); assertEquals(ip.getY(), 20, 0.1E7); }
Example #3
Source File: TestIntersect2.java From geometry-api-java with Apache License 2.0 | 6 votes |
@Test public void testPointAndPolygon3() { Point basePl = new Point(-121, 20); Polygon compPl = new Polygon(); compPl.startPath(new Point(-116, 20)); compPl.lineTo(new Point(-131, 10)); compPl.lineTo(new Point(-121, 50)); int noException = 1; // no exception Geometry intersectGeom = null; try { intersectGeom = GeometryEngine.intersect(basePl, compPl, SpatialReference.create(4326)); } catch (Exception ex) { noException = 0; } assertEquals(noException, 1); assertNotNull(intersectGeom); assertTrue(intersectGeom.getType() == Type.Point); Point ip = (Point) intersectGeom; assertEquals(ip.getX(), -121, 0.1E7); assertEquals(ip.getY(), 20, 0.1E7); }
Example #4
Source File: PostGISReaderTest.java From barefoot with Apache License 2.0 | 6 votes |
@Test public void testPolygon() throws IOException, JSONException { Properties properties = new Properties(); properties.load(new FileInputStream("config/oberbayern.properties")); RoadReader reader = Loader.reader(properties); Polygon polygon = (Polygon) GeometryEngine.geometryFromWkt( "POLYGON ((11.40848 47.93157, 11.45109 47.93157,11.45109 47.89296,11.40848 47.89296,11.40848 47.93157))", WktImportFlags.wktImportDefaults, Type.Polygon); BaseRoad road = null; reader.open(polygon, null); int count = 0; while ((road = reader.next()) != null) { assertTrue( GeometryEngine.overlaps(polygon, road.geometry(), SpatialReference.create(4326)) || GeometryEngine.contains(polygon, road.geometry(), SpatialReference.create(4326))); count += 1; } reader.close(); assertTrue(count > 0); }
Example #5
Source File: PostGISReaderTest.java From barefoot with Apache License 2.0 | 6 votes |
@Test public void testExclusion() throws IOException, JSONException { Properties properties = new Properties(); properties.load(new FileInputStream("config/oberbayern.properties")); RoadReader reader = Loader.reader(properties); Polygon polygon = (Polygon) GeometryEngine.geometryFromWkt( "POLYGON ((11.40848 47.93157, 11.45109 47.93157,11.45109 47.89296,11.40848 47.89296,11.40848 47.93157))", WktImportFlags.wktImportDefaults, Type.Polygon); HashSet<Short> exclusion = new HashSet<>(Arrays.asList((short) 117)); BaseRoad road = null; reader.open(polygon, exclusion); int count = 0; while ((road = reader.next()) != null) { assertTrue( GeometryEngine.overlaps(polygon, road.geometry(), SpatialReference.create(4326)) || GeometryEngine.contains(polygon, road.geometry(), SpatialReference.create(4326))); assertTrue(!exclusion.contains(road.type())); count += 1; } reader.close(); assertTrue(count > 0); }
Example #6
Source File: TestIntersect2.java From geometry-api-java with Apache License 2.0 | 6 votes |
@Test public void testPointAndPolygon1() { Point basePl = new Point(-116, 20); Polygon compPl = new Polygon(); compPl.startPath(new Point(-116, 20)); compPl.lineTo(new Point(-131, 10)); compPl.lineTo(new Point(-121, 50)); int noException = 1; // no exception Geometry intersectGeom = null; try { intersectGeom = GeometryEngine.intersect(basePl, compPl, SpatialReference.create(4326)); } catch (Exception ex) { noException = 0; } assertEquals(noException, 1); assertNotNull(intersectGeom); assertTrue(intersectGeom.getType() == Type.Point); Point ip = (Point) intersectGeom; assertEquals(ip.getX(), -116, 0.1E7); assertEquals(ip.getY(), 20, 0.1E7); }
Example #7
Source File: TestIntersect2.java From geometry-api-java with Apache License 2.0 | 6 votes |
@Test public void testPointAndPolyline1() { Point basePl = new Point(-116, 20); Polyline compPl = new Polyline(); compPl.startPath(new Point(-116, 20)); compPl.lineTo(new Point(-131, 10)); compPl.lineTo(new Point(-121, 50)); int noException = 1; // no exception Geometry intersectGeom = null; try { intersectGeom = GeometryEngine.intersect(basePl, compPl, SpatialReference.create(4326)); } catch (Exception ex) { noException = 0; } assertEquals(noException, 1); assertNotNull(intersectGeom); assertTrue(intersectGeom.getType() == Type.Point); Point ip = (Point) intersectGeom; assertEquals(ip.getX(), -116, 0.1E7); assertEquals(ip.getY(), 20, 0.1E7); }
Example #8
Source File: TrackIdleProcessor.java From defense-solutions-proofs-of-concept with Apache License 2.0 | 6 votes |
private boolean hasGeometryMoved(MapGeometry geom1, MapGeometry geom2, double tolerance) { if (geom1 != null && geom1.getGeometry() != null && geom1.getGeometry().getType() == Type.Point && geom2 != null && geom2.getGeometry() != null && geom2.getGeometry().getType() == Type.Point) { Point corePt1 = (Point) geom1.getGeometry(); Point corePt2 = (Point) geom2.getGeometry(); double meters = 0.0; try { meters = GeometryEngine.geodesicDistanceOnWGS84(corePt1, corePt2); } catch (Throwable error) { LOGGER.error(error.getMessage()); } double feet = meter2feet(meters); if (feet >= tolerance) return true; else return false; } else { throw new RuntimeException( LOGGER.translate("INVALID_GEOMETRY_TYPE")); } }
Example #9
Source File: TestStAsShape.java From spatial-framework-for-hadoop with Apache License 2.0 | 6 votes |
@Test public void testPointAsShape() { ST_Point point = new ST_Point(); final double longitude = 12.224; final double latitude = 51.829; BytesWritable pointAsWritable = point.evaluate(new DoubleWritable(longitude), new DoubleWritable(latitude)); assertNotNull("The point writable must not be null!", pointAsWritable); ST_AsShape asShape = new ST_AsShape(); BytesWritable shapeAsWritable = asShape.evaluate(pointAsWritable); assertNotNull("The shape writable must not be null!", pointAsWritable); byte[] esriShapeBuffer = shapeAsWritable.getBytes(); Geometry esriGeometry = GeometryEngine.geometryFromEsriShape(esriShapeBuffer, Type.Point); assertNotNull("The geometry must not be null!", esriGeometry); assertTrue("Geometry type point expected!", esriGeometry instanceof Point); Point esriPoint = (Point) esriGeometry; assertEquals("Longitude is different!", longitude, esriPoint.getX(), Epsilon); assertEquals("Latitude is different!", latitude, esriPoint.getY(), Epsilon); }
Example #10
Source File: GeographyTest.java From barefoot with Apache License 2.0 | 5 votes |
@Test public void testPathInterception2() { String point = "POINT(11.584009286555187 48.17578656762985)"; String line = "LINESTRING(11.5852021 48.1761996, 11.585284 48.175924, 11.5852937 48.1758945)"; Point c = (Point) GeometryEngine.geometryFromWkt(point, WktImportFlags.wktImportDefaults, Type.Point); Polyline ab = (Polyline) GeometryEngine.geometryFromWkt(line, WktImportFlags.wktImportDefaults, Type.Polyline); sw1.start(); double f = spatial.intercept(ab, c); sw1.stop(); double l = spatial.length(ab); sw2.start(); Point p = spatial.interpolate(ab, l, f); sw2.stop(); double d = spatial.distance(p, c); assertEquals(p.getX(), 11.585274842230357, 10E-6); assertEquals(p.getY(), 48.17595481677191, 10E-6); assertEquals(f, 0.801975106391962, 10E-6); assertEquals(l, 34.603061318901396, 10E-6); assertEquals(d, 95.96239015496631, 10E-6); if (benchmark) { System.out.println("[Geography] path interception " + sw1.us() + " us (gnomonic), path interpolation " + sw2.us() + " us (geodesic)"); } }
Example #11
Source File: TestIntersect2.java From geometry-api-java with Apache License 2.0 | 5 votes |
@Test public void testMultiPointAndMultiPoint2() { MultiPoint basePl = new MultiPoint(); basePl.add(new Point(-116, 20)); basePl.add(new Point(-118, 21)); MultiPoint compPl = new MultiPoint(); compPl.add(new Point(-116, 20)); compPl.add(new Point(-118, 21)); int noException = 1; // no exception Geometry intersectGeom = null; try { intersectGeom = GeometryEngine.intersect(basePl, compPl, SpatialReference.create(4326)); } catch (Exception ex) { noException = 0; } assertEquals(noException, 1); assertNotNull(intersectGeom); assertTrue(intersectGeom.getType() == Type.MultiPoint); MultiPoint ip = (MultiPoint) intersectGeom; assertEquals(ip.getPoint(0).getX(), -116, 0.1E7); assertEquals(ip.getPoint(0).getY(), 20, 0.1E7); assertEquals(ip.getPoint(0).getX(), -118, 0.1E7); assertEquals(ip.getPoint(0).getY(), 21, 0.1E7); }
Example #12
Source File: TestIntersect2.java From geometry-api-java with Apache License 2.0 | 5 votes |
@Test public void testMultiPointAndMultiPoint1() { MultiPoint basePl = new MultiPoint(); basePl.add(new Point(-116, 20)); basePl.add(new Point(-117, 20)); MultiPoint compPl = new MultiPoint(); compPl.add(new Point(-116, 20)); compPl.add(new Point(-118, 21)); int noException = 1; // no exception Geometry intersectGeom = null; try { intersectGeom = GeometryEngine.intersect(basePl, compPl, SpatialReference.create(4326)); } catch (Exception ex) { noException = 0; } assertEquals(noException, 1); assertNotNull(intersectGeom); assertTrue(intersectGeom.getType() == Type.MultiPoint); MultiPoint imp = (MultiPoint) intersectGeom; assertEquals(imp.getCoordinates2D().length, 1); assertEquals(imp.getCoordinates2D()[0].x, -116, 0.0); assertEquals(imp.getCoordinates2D()[0].y, 20, 0.0); }
Example #13
Source File: SegmentBuffer.java From geometry-api-java with Apache License 2.0 | 5 votes |
public void create(Geometry.Type type) { if (type == Geometry.Type.Line) createLine(); else throw new GeometryException("not implemented"); }
Example #14
Source File: SegmentBuffer.java From geometry-api-java with Apache License 2.0 | 5 votes |
public void set(Segment seg) { m_seg = seg; if (seg != null) { if (seg.getType() == Type.Line) { Line ln = (Line) seg; m_line = ln; } throw GeometryException.GeometryInternalError(); } }
Example #15
Source File: GeographyTest.java From barefoot with Apache License 2.0 | 5 votes |
@Test public void testPathInterception1() { String point = "POINT(11.410624 48.144161)"; String line = "LINESTRING(11.4047013 48.1402147,11.4047038 48.1402718,11.4047661 48.1403687,11.4053519 48.141055,11.4054617 48.1411901,11.4062664 48.1421968,11.4064586 48.1424479,11.4066449 48.1427372,11.4067254 48.1429028,11.4067864 48.1430673,11.4068647 48.1433303,11.4069456 48.1436822,11.4070524 48.1440368,11.4071569 48.1443314,11.4072635 48.1445915,11.4073887 48.1448641,11.4075228 48.1450729,11.407806 48.1454843,11.4080135 48.1458112,11.4083012 48.1463167,11.4086211 48.1469061,11.4087461 48.1471386,11.4088719 48.1474078,11.4089422 48.1476014,11.409028 48.1478353,11.409096 48.1480701,11.4091568 48.1483459,11.4094282 48.1498536)"; Point c = (Point) GeometryEngine.geometryFromWkt(point, WktImportFlags.wktImportDefaults, Type.Point); Polyline ab = (Polyline) GeometryEngine.geometryFromWkt(line, WktImportFlags.wktImportDefaults, Type.Polyline); sw1.start(); double f = spatial.intercept(ab, c); sw1.stop(); double l = spatial.length(ab); sw2.start(); Point p = spatial.interpolate(ab, l, f); sw2.stop(); double d = spatial.distance(p, c); assertEquals(p.getX(), 11.407547966254612, 10E-6); assertEquals(p.getY(), 48.14510945890138, 10E-6); assertEquals(f, 0.5175157549609246, 10E-6); assertEquals(l, 1138.85464239099, 10E-6); assertEquals(d, 252.03375312704165, 10E-6); if (benchmark) { System.out.println("[Geography] path interception " + sw1.us() + " us (gnomonic), path interpolation " + sw2.us() + " us (geodesic)"); } }
Example #16
Source File: MatcherKStateTest.java From barefoot with Apache License 2.0 | 5 votes |
@Override public void open() throws SourceException { if (roads.isEmpty()) { for (Entry entry : entries) { Polyline geometry = (Polyline) GeometryEngine.geometryFromWkt(entry.five(), WktImportFlags.wktImportDefaults, Type.Polyline); roads.add(new BaseRoad(entry.one(), entry.two(), entry.three(), entry.one(), entry.four(), (short) 0, 1.0f, 100.0f, 100.0f, (float) spatial.length(geometry), geometry)); } } iterator = roads.iterator(); }
Example #17
Source File: MatcherTest.java From barefoot with Apache License 2.0 | 5 votes |
@Override public void open() throws SourceException { if (roads.isEmpty()) { for (Entry entry : entries) { Polyline geometry = (Polyline) GeometryEngine.geometryFromWkt(entry.five(), WktImportFlags.wktImportDefaults, Type.Polyline); roads.add(new BaseRoad(entry.one(), entry.two(), entry.three(), entry.one(), entry.four(), (short) 0, 1.0f, 100.0f, 100.0f, (float) spatial.length(geometry), geometry)); } } iterator = roads.iterator(); }
Example #18
Source File: QuadTreeIndex.java From barefoot with Apache License 2.0 | 5 votes |
/** * Adds a polyline ({@link Polyline}) in WKB format to spatial index with some reference * identifier. * * @param id Identifier reference for polyline. * @param wkb {@link ByteBuffer} object of geometry in WKB format. */ public void add(int id, byte[] wkb) { Polyline geometry = (Polyline) OperatorImportFromWkb.local().execute(WkbImportFlags.wkbImportDefaults, Type.Polyline, ByteBuffer.wrap(wkb), null); Envelope2D env = new Envelope2D(); geometry.queryEnvelope2D(env); index.insert(id, env); geometries.put(id, wkb); }
Example #19
Source File: MatcherSample.java From barefoot with Apache License 2.0 | 5 votes |
/** * Creates a {@link MatcherSample} object from its JSON representation. * * @param json JSON representation of {@link MatcherSample} object. JSONException thrown on JSON * extraction or parsing error. * @throws JSONException thrown on JSON parse error. */ public MatcherSample(JSONObject json) throws JSONException { super(json); id = json.getString("id"); String wkt = json.getString("point"); point = (Point) GeometryEngine.geometryFromWkt(wkt, WktImportFlags.wktImportDefaults, Type.Point); if (json.has("azimuth")) { azimuth = norm(json.getDouble("azimuth")); } else { azimuth = Double.NaN; } }
Example #20
Source File: GeometryTypeJsonSerializer.java From spatial-framework-for-hadoop with Apache License 2.0 | 4 votes |
@Override public void serialize(Type geometryType, JsonGenerator jsonGenerator, SerializerProvider arg2) throws IOException, JsonProcessingException { jsonGenerator.writeString("esriGeometry" + geometryType); }
Example #21
Source File: GeographyTest.java From barefoot with Apache License 2.0 | 4 votes |
@Test public void testLineInterception() { Polyline ab = (Polyline) GeometryEngine.geometryFromWkt( "LINESTRING(11.4047661 48.1403687,11.4053519 48.141055)", WktImportFlags.wktImportDefaults, Type.Polyline); Point a = ab.getPoint(0), b = ab.getPoint(1); String points[] = new String[] {"POINT(11.406501117689324 48.14051652560591)", // East "POINT(11.406713245538327 48.14182906667162)", // Northeast "POINT(11.404923416812364 48.14258477213369)", // North "POINT(11.403300759321036 48.14105540093837)", // Northwest "POINT(11.403193249043934 48.140881120346386)", // West "POINT(11.40327279698731 48.13987351306362)", // Southwest "POINT(11.405221721600025 48.1392039845402)", // South "POINT(11.406255844863914 48.13963486923349)" // Southeast }; for (int i = 0; i < points.length; ++i) { Point c = (Point) GeometryEngine.geometryFromWkt(points[i], WktImportFlags.wktImportDefaults, Type.Point); sw1.start(); double f = spatial.intercept(a, b, c); Point p = spatial.interpolate(a, b, f); sw1.stop(); sw2.start(); Triple<Point, Double, Double> res = intercept(a, b, c); sw2.stop(); sw3.start(); double s = spatial.distance(p, c); sw3.stop(); sw4.start(); double s_esri = distance(p, c); sw4.stop(); if (benchmark) { System.out.println("[Geography] interception & interpolation " + sw1.us() + " us (gnomonic/geodesic) " + sw2.us() + " us (iterative)"); System.out.println("[Geography] distance " + sw3.us() + " us (GeoLib) " + sw4.us() + " us (ESRI)"); } assertEquals(f > 1 ? 1 : f < 0 ? 0 : f, res.three(), 0.2); assertEquals(p.getX(), res.one().getX(), 10E-2); assertEquals(p.getY(), res.one().getY(), 10E-2); assertEquals(s, s_esri, 10E-6); } }
Example #22
Source File: QuadTreeIndex.java From barefoot with Apache License 2.0 | 4 votes |
@Override public Set<Tuple<Integer, Double>> knearest(Point c, int k) { if (index.getElementCount() == 0) { return null; } Set<Integer> visited = new HashSet<>(); PriorityQueue<Triple<Integer, Double, Double>> queue = new PriorityQueue<>(k, new Comparator<Triple<Integer, Double, Double>>() { @Override public int compare(Triple<Integer, Double, Double> left, Triple<Integer, Double, Double> right) { return left.three() < right.three() ? -1 : left.three() > right.three() ? +1 : 0; } }); double radius = 100; do { Envelope2D env = spatial.envelope(c, radius); QuadTreeIterator it = index.getIterator(env, 0); int handle = -1; while ((handle = it.next()) != -1) { int id = index.getElement(handle); if (visited.contains(id)) { continue; } Polyline geometry = (Polyline) OperatorImportFromWkb.local().execute( WkbImportFlags.wkbImportDefaults, Type.Polyline, ByteBuffer.wrap(geometries.get(id)), null); double f = spatial.intercept(geometry, c); Point p = spatial.interpolate(geometry, spatial.length(geometry), f); double d = spatial.distance(p, c); if (d < radius) { // Only within radius, we can be sure that we have semantically // correct k-nearest neighbors. queue.add(new Triple<>(id, f, d)); visited.add(id); } } radius *= 2; } while (queue.size() < k); Set<Tuple<Integer, Double>> result = new HashSet<>(); while (result.size() < k) { Triple<Integer, Double, Double> e = queue.poll(); result.add(new Tuple<>(e.one(), e.two())); } return result; }
Example #23
Source File: QuadTreeIndex.java From barefoot with Apache License 2.0 | 4 votes |
@Override public Set<Tuple<Integer, Double>> nearest(Point c) { if (index.getElementCount() == 0) { return null; } Set<Tuple<Integer, Double>> nearests = new HashSet<>(); double radius = 100, min = Double.MAX_VALUE; do { Envelope2D env = spatial.envelope(c, radius); QuadTreeIterator it = index.getIterator(env, 0); int handle = -1; while ((handle = it.next()) != -1) { int id = index.getElement(handle); Polyline geometry = (Polyline) OperatorImportFromWkb.local().execute( WkbImportFlags.wkbImportDefaults, Type.Polyline, ByteBuffer.wrap(geometries.get(id)), null); double f = spatial.intercept(geometry, c); Point p = spatial.interpolate(geometry, spatial.length(geometry), f); double d = spatial.distance(p, c); if (d > min) { continue; } if (d < min) { min = d; nearests.clear(); } nearests.add(new Tuple<>(id, f)); } radius *= 2; } while (nearests.isEmpty()); return nearests; }
Example #24
Source File: BaseRoad.java From barefoot with Apache License 2.0 | 2 votes |
/** * Gets road's geometry as a {@link Polyline} from the road's source to its target. * * @return Road's geometry as {@link Polyline} from source to target. */ public Polyline geometry() { return (Polyline) OperatorImportFromWkb.local().execute(WkbImportFlags.wkbImportDefaults, Type.Polyline, ByteBuffer.wrap(geometry), null); }