com.esri.core.geometry.ogc.OGCMultiPoint Java Examples

The following examples show how to use com.esri.core.geometry.ogc.OGCMultiPoint. 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: TestOGC.java    From geometry-api-java with Apache License 2.0 6 votes vote down vote up
@Test
public void testMultiPointSinglePoint() {
	String wkt = "multipoint((1 0))";
	OGCGeometry g0 = OGCGeometry.fromText(wkt);
	assertTrue(g0.dimension() == 0);
	String gt = g0.geometryType();
	assertTrue(gt.equals("MultiPoint"));
	OGCMultiPoint mp = (OGCMultiPoint)g0;
	assertTrue(mp.numGeometries() == 1);
	OGCGeometry p = mp.geometryN(0);
	String s = p.asText();
	assertTrue(s.equals("POINT (1 0)"));
	
	String ms = p.convertToMulti().asText();
	assertTrue(ms.equals("MULTIPOINT ((1 0))"));
	
}
 
Example #2
Source File: GeometrySerde.java    From presto with Apache License 2.0 5 votes vote down vote up
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 #3
Source File: TestEstimateMemorySize.java    From geometry-api-java with Apache License 2.0 5 votes vote down vote up
@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 #4
Source File: TestGeomToGeoJson.java    From geometry-api-java with Apache License 2.0 5 votes vote down vote up
@Test
public void testOGCMultiPoint() {
	MultiPoint mp = new MultiPoint();
	mp.add(10.0, 20.0);
	mp.add(20.0, 30.0);
	OGCMultiPoint ogcMultiPoint = new OGCMultiPoint(mp, null);
	String result = ogcMultiPoint.asGeoJson();
	assertEquals("{\"type\":\"MultiPoint\",\"coordinates\":[[10,20],[20,30]],\"crs\":null}", result);
}
 
Example #5
Source File: ST_NumGeometries.java    From spatial-framework-for-hadoop with Apache License 2.0 4 votes vote down vote up
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 vote down vote up
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;
	}
}