com.esri.core.geometry.ogc.OGCMultiPolygon Java Examples
The following examples show how to use
com.esri.core.geometry.ogc.OGCMultiPolygon.
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: GeoFunctions.java From presto with Apache License 2.0 | 5 votes |
@Description("Returns the Point value that is the mathematical centroid of a Geometry") @ScalarFunction("ST_Centroid") @SqlType(GEOMETRY_TYPE_NAME) public static Slice stCentroid(@SqlType(GEOMETRY_TYPE_NAME) Slice input) { OGCGeometry geometry = deserialize(input); validateType("ST_Centroid", geometry, EnumSet.of(POINT, MULTI_POINT, LINE_STRING, MULTI_LINE_STRING, POLYGON, MULTI_POLYGON)); GeometryType geometryType = GeometryType.getForEsriGeometryType(geometry.geometryType()); if (geometryType == GeometryType.POINT) { return input; } int pointCount = ((MultiVertexGeometry) geometry.getEsriGeometry()).getPointCount(); if (pointCount == 0) { return serialize(createFromEsriGeometry(new Point(), geometry.getEsriSpatialReference())); } Point centroid; switch (geometryType) { case MULTI_POINT: centroid = computePointsCentroid((MultiVertexGeometry) geometry.getEsriGeometry()); break; case LINE_STRING: case MULTI_LINE_STRING: centroid = computeLineCentroid((Polyline) geometry.getEsriGeometry()); break; case POLYGON: centroid = computePolygonCentroid((Polygon) geometry.getEsriGeometry()); break; case MULTI_POLYGON: centroid = computeMultiPolygonCentroid((OGCMultiPolygon) geometry); break; default: throw new PrestoException(INVALID_FUNCTION_ARGUMENT, "Unexpected geometry type: " + geometryType); } return serialize(createFromEsriGeometry(centroid, geometry.getEsriSpatialReference())); }
Example #2
Source File: GeoFunctions.java From presto with Apache License 2.0 | 5 votes |
private static Point computeMultiPolygonCentroid(OGCMultiPolygon multiPolygon) { double xSum = 0; double ySum = 0; double weightSum = 0; for (int i = 0; i < multiPolygon.numGeometries(); i++) { Point centroid = computePolygonCentroid((Polygon) multiPolygon.geometryN(i).getEsriGeometry()); Polygon polygon = (Polygon) multiPolygon.geometryN(i).getEsriGeometry(); double weight = polygon.calculateArea2D(); weightSum += weight; xSum += centroid.getX() * weight; ySum += centroid.getY() * weight; } return new Point(xSum / weightSum, ySum / weightSum); }
Example #3
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 #4
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 #5
Source File: ST_NumGeometries.java From spatial-framework-for-hadoop with Apache License 2.0 | 4 votes |
public IntWritable 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 { GeometryUtils.OGCType ogcType = GeometryUtils.getType(geomref); switch(ogcType) { case ST_POINT: LogUtils.Log_InvalidType(LOG, GeometryUtils.OGCType.ST_MULTIPOINT, ogcType); return null; case ST_LINESTRING: LogUtils.Log_InvalidType(LOG, GeometryUtils.OGCType.ST_MULTILINESTRING, ogcType); return null; case ST_POLYGON: LogUtils.Log_InvalidType(LOG, GeometryUtils.OGCType.ST_MULTIPOLYGON, ogcType); return null; case ST_MULTIPOINT: resultInt.set(((OGCMultiPoint)ogcGeometry).numGeometries()); break; case ST_MULTILINESTRING: resultInt.set(((OGCMultiLineString)ogcGeometry).numGeometries()); break; case ST_MULTIPOLYGON: resultInt.set(((OGCMultiPolygon)ogcGeometry).numGeometries()); break; } } catch (ClassCastException cce) { // single vs Multi geometry type resultInt.set(1); } catch (Exception e) { LogUtils.Log_InternalError(LOG, "ST_NumGeometries: " + e); return null; } return resultInt; }
Example #6
Source File: ST_GeometryN.java From spatial-framework-for-hadoop with Apache License 2.0 | 4 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 try { GeometryUtils.OGCType ogcType = GeometryUtils.getType(geomref); OGCGeometry ogcGeom = null; switch(ogcType) { case ST_POINT: LogUtils.Log_InvalidType(LOG, GeometryUtils.OGCType.ST_MULTIPOINT, ogcType); return null; case ST_LINESTRING: LogUtils.Log_InvalidType(LOG, GeometryUtils.OGCType.ST_MULTILINESTRING, ogcType); return null; case ST_POLYGON: LogUtils.Log_InvalidType(LOG, GeometryUtils.OGCType.ST_MULTIPOLYGON, ogcType); return null; case ST_MULTIPOINT: ogcGeom = ((OGCMultiPoint)ogcGeometry).geometryN(idx); break; case ST_MULTILINESTRING: ogcGeom = ((OGCMultiLineString)ogcGeometry).geometryN(idx); break; case ST_MULTIPOLYGON: ogcGeom = ((OGCMultiPolygon)ogcGeometry).geometryN(idx); break; } return GeometryUtils.geometryToEsriShapeBytesWritable(ogcGeom); } catch (Exception e) { LogUtils.Log_InternalError(LOG, "ST_GeometryN: " + e); return null; } }