com.esri.core.geometry.ogc.OGCLineString Java Examples
The following examples show how to use
com.esri.core.geometry.ogc.OGCLineString.
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: ST_InteriorRingN.java From spatial-framework-for-hadoop with Apache License 2.0 | 6 votes |
public BytesWritable evaluate(BytesWritable geomref, IntWritable index) { if (geomref == null || geomref.getLength() == 0 || index == null) { LogUtils.Log_ArgumentsNull(LOG); return null; } OGCGeometry ogcGeometry = GeometryUtils.geometryFromEsriShape(geomref); if (ogcGeometry == null){ LogUtils.Log_ArgumentsNull(LOG); return null; } int idx = index.get() - 1; // 1-based UI, 0-based engine if (GeometryUtils.getType(geomref) == GeometryUtils.OGCType.ST_POLYGON) { try { OGCLineString hole = ((OGCPolygon)(ogcGeometry)).interiorRingN(idx); return GeometryUtils.geometryToEsriShapeBytesWritable(hole); } catch (Exception e) { LogUtils.Log_InternalError(LOG, "ST_InteriorRingN: " + e); return null; } } else { LogUtils.Log_InvalidType(LOG, GeometryUtils.OGCType.ST_POLYGON, GeometryUtils.getType(geomref)); return null; } }
Example #2
Source File: TestOGC.java From geometry-api-java with Apache License 2.0 | 6 votes |
@Test public void testFirstPointOfPolygon() { OGCGeometry g = OGCGeometry .fromText("POLYGON((-10 -10, 10 -10, 10 10, -10 10, -10 -10), (-5 -5, -5 5, 5 5, 5 -5, -5 -5))"); assertTrue(g.geometryType().equals("Polygon")); OGCPolygon p = (OGCPolygon) g; assertTrue(p.numInteriorRing() == 1); OGCLineString ls = p.exteriorRing(); OGCPoint p1 = ls.pointN(1); assertTrue(ls.pointN(1).equals(OGCGeometry.fromText("POINT(10 -10)"))); OGCPoint p2 = ls.pointN(3); assertTrue(ls.pointN(3).equals(OGCGeometry.fromText("POINT(-10 10)"))); OGCPoint p0 = ls.pointN(0); assertTrue(ls.pointN(0).equals(OGCGeometry.fromText("POINT(-10 -10)"))); String ms = g.convertToMulti().asText(); assertTrue(ms.equals("MULTIPOLYGON (((-10 -10, 10 -10, 10 10, -10 10, -10 -10), (-5 -5, -5 5, 5 5, 5 -5, -5 -5)))")); }
Example #3
Source File: GeoFunctions.java From presto with Apache License 2.0 | 5 votes |
@Description("Returns a LineString from an array of points") @ScalarFunction("ST_LineString") @SqlType(GEOMETRY_TYPE_NAME) public static Slice stLineString(@SqlType("array(" + GEOMETRY_TYPE_NAME + ")") Block input) { MultiPath multipath = new Polyline(); OGCPoint previousPoint = null; for (int i = 0; i < input.getPositionCount(); i++) { Slice slice = GEOMETRY.getSlice(input, i); if (slice.getInput().available() == 0) { throw new PrestoException(INVALID_FUNCTION_ARGUMENT, format("Invalid input to ST_LineString: null point at index %s", i + 1)); } OGCGeometry geometry = deserialize(slice); if (!(geometry instanceof OGCPoint)) { throw new PrestoException(INVALID_FUNCTION_ARGUMENT, format("ST_LineString takes only an array of valid points, %s was passed", geometry.geometryType())); } OGCPoint point = (OGCPoint) geometry; if (point.isEmpty()) { throw new PrestoException(INVALID_FUNCTION_ARGUMENT, format("Invalid input to ST_LineString: empty point at index %s", i + 1)); } if (previousPoint == null) { multipath.startPath(point.X(), point.Y()); } else { if (point.Equals(previousPoint)) { throw new PrestoException(INVALID_FUNCTION_ARGUMENT, format("Invalid input to ST_LineString: consecutive duplicate points at index %s", i + 1)); } multipath.lineTo(point.X(), point.Y()); } previousPoint = point; } OGCLineString linestring = new OGCLineString(multipath, 0, null); return serialize(linestring); }
Example #4
Source File: GeoFunctions.java From presto with Apache License 2.0 | 5 votes |
@SqlNullable @Description("Returns the vertex of a linestring at the specified index (indices started with 1) ") @ScalarFunction("ST_PointN") @SqlType(GEOMETRY_TYPE_NAME) public static Slice stPointN(@SqlType(GEOMETRY_TYPE_NAME) Slice input, @SqlType(INTEGER) long index) { OGCGeometry geometry = deserialize(input); validateType("ST_PointN", geometry, EnumSet.of(LINE_STRING)); OGCLineString linestring = (OGCLineString) geometry; if (index < 1 || index > linestring.numPoints()) { return null; } return serialize(linestring.pointN(toIntExact(index) - 1)); }
Example #5
Source File: GeoFunctions.java From presto with Apache License 2.0 | 5 votes |
@SqlNullable @Description("Returns TRUE if and only if the line is closed and simple") @ScalarFunction("ST_IsRing") @SqlType(BOOLEAN) public static Boolean stIsRing(@SqlType(GEOMETRY_TYPE_NAME) Slice input) { OGCGeometry geometry = deserialize(input); validateType("ST_IsRing", geometry, EnumSet.of(LINE_STRING)); OGCLineString line = (OGCLineString) geometry; return line.isClosed() && line.isSimple(); }
Example #6
Source File: GeometrySerde.java From presto with Apache License 2.0 | 5 votes |
private static OGCGeometry createFromEsriGeometry(Geometry geometry, boolean multiType) { Geometry.Type type = geometry.getType(); switch (type) { case Polygon: { if (!multiType && ((Polygon) geometry).getExteriorRingCount() <= 1) { return new OGCPolygon((Polygon) geometry, null); } return new OGCMultiPolygon((Polygon) geometry, null); } case Polyline: { if (!multiType && ((Polyline) geometry).getPathCount() <= 1) { return new OGCLineString((Polyline) geometry, 0, null); } return new OGCMultiLineString((Polyline) geometry, null); } case MultiPoint: { if (!multiType && ((MultiPoint) geometry).getPointCount() <= 1) { if (geometry.isEmpty()) { return new OGCPoint(new Point(), null); } return new OGCPoint(((MultiPoint) geometry).getPoint(0), null); } return new OGCMultiPoint((MultiPoint) geometry, null); } case Point: { if (!multiType) { return new OGCPoint((Point) geometry, null); } return new OGCMultiPoint((Point) geometry, null); } case Envelope: { Polygon polygon = new Polygon(); polygon.addEnvelope((Envelope) geometry, false); return new OGCPolygon(polygon, null); } default: throw new IllegalArgumentException("Unexpected geometry type: " + type); } }
Example #7
Source File: ST_IsRing.java From spatial-framework-for-hadoop with Apache License 2.0 | 5 votes |
public BooleanWritable evaluate(BytesWritable geomref) { if (geomref == null || geomref.getLength() == 0) { LogUtils.Log_ArgumentsNull(LOG); return null; } OGCGeometry ogcGeometry = GeometryUtils.geometryFromEsriShape(geomref); if (ogcGeometry == null){ LogUtils.Log_ArgumentsNull(LOG); return null; } try { switch(GeometryUtils.getType(geomref)) { case ST_LINESTRING: OGCLineString lns = (OGCLineString)ogcGeometry; resultBoolean.set(lns.isClosed() && lns.isSimple()); return resultBoolean; default: // ST_IsRing gives ERROR on Point, Polygon, or MultiLineString - on Postgres LogUtils.Log_InvalidType(LOG, GeometryUtils.OGCType.ST_LINESTRING, GeometryUtils.getType(geomref)); return null; } } catch (Exception e) { LogUtils.Log_InternalError(LOG, "ST_IsRing" + e); return null; } }
Example #8
Source File: TestEstimateMemorySize.java From geometry-api-java with Apache License 2.0 | 5 votes |
@Test public void testInstanceSizes() { assertEquals(getInstanceSize(AttributeStreamOfFloat.class), SizeOf.SIZE_OF_ATTRIBUTE_STREAM_OF_FLOAT); assertEquals(getInstanceSize(AttributeStreamOfDbl.class), SizeOf.SIZE_OF_ATTRIBUTE_STREAM_OF_DBL); assertEquals(getInstanceSize(AttributeStreamOfInt8.class), SizeOf.SIZE_OF_ATTRIBUTE_STREAM_OF_INT8); assertEquals(getInstanceSize(AttributeStreamOfInt16.class), SizeOf.SIZE_OF_ATTRIBUTE_STREAM_OF_INT16); assertEquals(getInstanceSize(AttributeStreamOfInt32.class), SizeOf.SIZE_OF_ATTRIBUTE_STREAM_OF_INT32); assertEquals(getInstanceSize(AttributeStreamOfInt64.class), SizeOf.SIZE_OF_ATTRIBUTE_STREAM_OF_INT64); assertEquals(getInstanceSize(Envelope.class), SizeOf.SIZE_OF_ENVELOPE); assertEquals(getInstanceSize(Envelope2D.class), SizeOf.SIZE_OF_ENVELOPE2D); assertEquals(getInstanceSize(Line.class), SizeOf.SIZE_OF_LINE); assertEquals(getInstanceSize(MultiPath.class), SizeOf.SIZE_OF_MULTI_PATH); assertEquals(getInstanceSize(MultiPathImpl.class), SizeOf.SIZE_OF_MULTI_PATH_IMPL); assertEquals(getInstanceSize(MultiPoint.class), SizeOf.SIZE_OF_MULTI_POINT); assertEquals(getInstanceSize(MultiPointImpl.class), SizeOf.SIZE_OF_MULTI_POINT_IMPL); assertEquals(getInstanceSize(Point.class), SizeOf.SIZE_OF_POINT); assertEquals(getInstanceSize(Polygon.class), SizeOf.SIZE_OF_POLYGON); assertEquals(getInstanceSize(Polyline.class), SizeOf.SIZE_OF_POLYLINE); assertEquals(getInstanceSize(OGCConcreteGeometryCollection.class), SizeOf.SIZE_OF_OGC_CONCRETE_GEOMETRY_COLLECTION); assertEquals(getInstanceSize(OGCLineString.class), SizeOf.SIZE_OF_OGC_LINE_STRING); assertEquals(getInstanceSize(OGCMultiLineString.class), SizeOf.SIZE_OF_OGC_MULTI_LINE_STRING); assertEquals(getInstanceSize(OGCMultiPoint.class), SizeOf.SIZE_OF_OGC_MULTI_POINT); assertEquals(getInstanceSize(OGCMultiPolygon.class), SizeOf.SIZE_OF_OGC_MULTI_POLYGON); assertEquals(getInstanceSize(OGCPoint.class), SizeOf.SIZE_OF_OGC_POINT); assertEquals(getInstanceSize(OGCPolygon.class), SizeOf.SIZE_OF_OGC_POLYGON); assertEquals(getInstanceSize(RasterizedGeometry2DImpl.class), SizeOf.SIZE_OF_RASTERIZED_GEOMETRY_2D_IMPL); assertEquals(getInstanceSize(RasterizedGeometry2DImpl.ScanCallbackImpl.class), SizeOf.SIZE_OF_SCAN_CALLBACK_IMPL); assertEquals(getInstanceSize(Transformation2D.class), SizeOf.SIZE_OF_TRANSFORMATION_2D); assertEquals(getInstanceSize(SimpleRasterizer.class), SizeOf.SIZE_OF_SIMPLE_RASTERIZER); assertEquals(getInstanceSize(SimpleRasterizer.Edge.class), SizeOf.SIZE_OF_EDGE); assertEquals(getInstanceSize(QuadTreeImpl.class), SizeOf.SIZE_OF_QUAD_TREE_IMPL); assertEquals(getInstanceSize(QuadTreeImpl.Data.class), SizeOf.SIZE_OF_DATA); assertEquals(getInstanceSize(StridedIndexTypeCollection.class), SizeOf.SIZE_OF_STRIDED_INDEX_TYPE_COLLECTION); }
Example #9
Source File: TestOGC.java From geometry-api-java with Apache License 2.0 | 5 votes |
@Test public void testFirstPointOfLineString() { OGCGeometry g = OGCGeometry .fromText("LINESTRING(-10 -10, 10 -10, 10 10, -10 10, -10 -10)"); assertTrue(g.geometryType().equals("LineString")); OGCLineString p = (OGCLineString) g; assertTrue(p.numPoints() == 5); assertTrue(p.isClosed()); assertTrue(p.pointN(1).equals(OGCGeometry.fromText("POINT(10 -10)"))); String ms = g.convertToMulti().asText(); assertTrue(ms.equals("MULTILINESTRING ((-10 -10, 10 -10, 10 10, -10 10, -10 -10))")); }
Example #10
Source File: TestGeomToGeoJson.java From geometry-api-java with Apache License 2.0 | 5 votes |
@Test public void testOGCLineString() { Polyline p = new Polyline(); p.startPath(100.0, 0.0); p.lineTo(101.0, 0.0); p.lineTo(101.0, 1.0); p.lineTo(100.0, 1.0); OGCLineString ogcLineString = new OGCLineString(p, 0, null); String result = ogcLineString.asGeoJson(); assertEquals("{\"type\":\"LineString\",\"coordinates\":[[100,0],[101,0],[101,1],[100,1]],\"crs\":null}", result); }
Example #11
Source File: EncodedPolylineFunctions.java From presto with Apache License 2.0 | 4 votes |
private static OGCLineString decodePolyline(String polyline) { MultiPath multipath = new Polyline(); boolean isFirstPoint = true; int index = 0; int latitude = 0; int longitude = 0; while (index < polyline.length()) { int result = 1; int shift = 0; int bytes; do { bytes = polyline.charAt(index++) - 63 - 1; result += bytes << shift; shift += 5; } while (bytes >= 0x1f); latitude += (result & 1) != 0 ? ~(result >> 1) : (result >> 1); result = 1; shift = 0; do { bytes = polyline.charAt(index++) - 63 - 1; result += bytes << shift; shift += 5; } while (bytes >= 0x1f); longitude += (result & 1) != 0 ? ~(result >> 1) : (result >> 1); if (isFirstPoint) { multipath.startPath(longitude * 1e-5, latitude * 1e-5); isFirstPoint = false; } else { multipath.lineTo(longitude * 1e-5, latitude * 1e-5); } } return new OGCLineString(multipath, 0, null); }
Example #12
Source File: TestOGC.java From geometry-api-java with Apache License 2.0 | 4 votes |
@Test public void testPolygon() throws Exception { OGCGeometry g = OGCGeometry .fromText("POLYGON((-10 -10, 10 -10, 10 10, -10 10, -10 -10), (-5 -5, -5 5, 5 5, 5 -5, -5 -5))"); assertTrue(g.geometryType().equals("Polygon")); OGCPolygon p = (OGCPolygon) g; assertTrue(p.numInteriorRing() == 1); OGCLineString ls = p.exteriorRing(); // assertTrue(ls.pointN(1).equals(OGCGeometry.fromText("POINT(10 -10)"))); boolean b = ls .Equals(OGCGeometry .fromText("LINESTRING(-10 -10, 10 -10, 10 10, -10 10, -10 -10)")); assertTrue(b); OGCLineString lsi = p.interiorRingN(0); b = lsi.Equals(OGCGeometry .fromText("LINESTRING(-5 -5, -5 5, 5 5, 5 -5, -5 -5)")); assertTrue(b); b = lsi.equals((Object)OGCGeometry .fromText("LINESTRING(-5 -5, -5 5, 5 5, 5 -5, -5 -5)")); assertTrue(!lsi.Equals(ls)); OGCMultiCurve boundary = p.boundary(); String s = boundary.asText(); assertTrue(s.equals("MULTILINESTRING ((-10 -10, 10 -10, 10 10, -10 10, -10 -10), (-5 -5, -5 5, 5 5, 5 -5, -5 -5))")); { OGCGeometry g2 = OGCGeometry.fromGeoJson( "{\"type\": \"Polygon\", \"coordinates\": [[[1.00000001,1.00000001], [4.00000001,1.00000001], [4.00000001,4.00000001], [1.00000001,4.00000001]]]}"); OGCGeometry .fromGeoJson( "{\"type\": \"LineString\", \"coordinates\": [[1.00000001,1.00000001], [7.00000001,8.00000001]]}") .intersects(g2); OGCGeometry .fromGeoJson( "{\"type\": \"LineString\", \"coordinates\": [[2.449,4.865], [7.00000001,8.00000001]]}") .intersects(g2); OGCGeometry g3 = OGCGeometry.fromGeoJson( "{\"type\": \"Polygon\", \"coordinates\": [[[1.00000001,1.00000001], [4.00000001,1.00000001], [4.00000001,4.00000001], [1.00000001,4.00000001]]]}"); boolean bb = g2.equals((Object) g3); assertTrue(bb); } }
Example #13
Source File: TestGeomToGeoJson.java From geometry-api-java with Apache License 2.0 | 4 votes |
@Test public void testGeometryCollection() { SpatialReference sr = SpatialReference.create(4326); StringBuilder geometrySb = new StringBuilder(); geometrySb .append("{\"type\" : \"GeometryCollection\", \"geometries\" : ["); OGCPoint point = new OGCPoint(new Point(1.0, 1.0), sr); assertEquals("{\"x\":1,\"y\":1,\"spatialReference\":{\"wkid\":4326}}", point.asJson()); assertEquals( "{\"type\":\"Point\",\"coordinates\":[1,1],\"crs\":{\"type\":\"name\",\"properties\":{\"name\":\"EPSG:4326\"}}}", point.asGeoJson()); geometrySb.append(point.asGeoJson()).append(", "); OGCLineString line = new OGCLineString(new Polyline( new Point(1.0, 1.0), new Point(2.0, 2.0)), 0, sr); assertEquals( "{\"paths\":[[[1,1],[2,2]]],\"spatialReference\":{\"wkid\":4326}}", line.asJson()); assertEquals( "{\"type\":\"LineString\",\"coordinates\":[[1,1],[2,2]],\"crs\":{\"type\":\"name\",\"properties\":{\"name\":\"EPSG:4326\"}}}", line.asGeoJson()); geometrySb.append(line.asGeoJson()).append(", "); Polygon p = new Polygon(); p.startPath(1.0, 1.0); p.lineTo(2.0, 2.0); p.lineTo(3.0, 1.0); p.lineTo(2.0, 0.0); OGCPolygon polygon = new OGCPolygon(p, sr); assertEquals( "{\"rings\":[[[1,1],[2,2],[3,1],[2,0],[1,1]]],\"spatialReference\":{\"wkid\":4326}}", polygon.asJson()); assertEquals( "{\"type\":\"Polygon\",\"coordinates\":[[[1,1],[2,0],[3,1],[2,2],[1,1]]],\"crs\":{\"type\":\"name\",\"properties\":{\"name\":\"EPSG:4326\"}}}", polygon.asGeoJson()); geometrySb.append(polygon.asGeoJson()).append("]}"); List<OGCGeometry> geoms = new ArrayList<OGCGeometry>(3); geoms.add(point); geoms.add(line); geoms.add(polygon); OGCConcreteGeometryCollection collection = new OGCConcreteGeometryCollection( geoms, sr); String s2 = collection.asGeoJson(); assertEquals("{\"type\":\"GeometryCollection\",\"geometries\":[{\"type\":\"Point\",\"coordinates\":[1,1]},{\"type\":\"LineString\",\"coordinates\":[[1,1],[2,2]]},{\"type\":\"Polygon\",\"coordinates\":[[[1,1],[2,0],[3,1],[2,2],[1,1]]]}],\"crs\":{\"type\":\"name\",\"properties\":{\"name\":\"EPSG:4326\"}}}", collection.asGeoJson()); }