Java Code Examples for com.esri.core.geometry.ogc.OGCGeometry#fromBinary()

The following examples show how to use com.esri.core.geometry.ogc.OGCGeometry#fromBinary() . 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 Project: HolandaCatalinaFw   File: GeoUtils.java    License: Apache License 2.0 6 votes vote down vote up
public static final OGCGeometry createGeometry(Object object) {
    OGCGeometry geometry;
    if(object instanceof byte[]) {
        geometry = OGCGeometry.fromBinary(ByteBuffer.wrap((byte[])object));
    } else if(object instanceof String) {
        if(((String)object).startsWith(Strings.START_OBJECT) || ((String)object).startsWith(Strings.START_SUB_GROUP)) {
            geometry = fromGeoJson((Map<String, Object>) JsonUtils.createObject((String)object));
        } else {
            geometry = OGCGeometry.fromText((String) object);
        }
    } else if(object instanceof Map) {
        geometry = fromGeoJson((Map<String,Object>)object);
    } else {
        throw new HCJFRuntimeException("Illegal argument exception, unsupported geom data type: %s", object.getClass());
    }
    return geometry;
}
 
Example 2
public BytesWritable evaluate(BytesWritable wkb, int wkid) throws UDFArgumentException {

		try {
			SpatialReference spatialReference = null;
			if (wkid != GeometryUtils.WKID_UNKNOWN) {
				spatialReference = SpatialReference.create(wkid);
			}
			byte [] byteArr = wkb.getBytes();
            ByteBuffer byteBuf = ByteBuffer.allocate(byteArr.length);
			byteBuf.put(byteArr);
			OGCGeometry ogcObj = OGCGeometry.fromBinary(byteBuf);
			ogcObj.setSpatialReference(spatialReference);
			String gType = ogcObj.geometryType();
			if (gType.equals("MultiLineString") || gType.equals("LineString")) {
				return GeometryUtils.geometryToEsriShapeBytesWritable(ogcObj);
			} else {
				LogUtils.Log_InvalidType(LOG, GeometryUtils.OGCType.ST_MULTILINESTRING, GeometryUtils.OGCType.UNKNOWN);
				return null;
			}
		} catch (Exception e) {  // IllegalArgumentException, GeometryException
			LOG.error(e.getMessage());
			return null;
		}
	}
 
Example 3
public BytesWritable evaluate(BytesWritable wkb, int wkid) throws UDFArgumentException {

		try {
			SpatialReference spatialReference = null;
			if (wkid != GeometryUtils.WKID_UNKNOWN) {
				spatialReference = SpatialReference.create(wkid);
			}
			byte [] byteArr = wkb.getBytes();
            ByteBuffer byteBuf = ByteBuffer.allocate(byteArr.length);
			byteBuf.put(byteArr);
			OGCGeometry ogcObj = OGCGeometry.fromBinary(byteBuf);
			ogcObj.setSpatialReference(spatialReference);
			String gType = ogcObj.geometryType();
			if (gType.equals("MultiPoint") || gType.equals("Point")) {
				return GeometryUtils.geometryToEsriShapeBytesWritable(ogcObj);
			} else {
				LogUtils.Log_InvalidType(LOG, GeometryUtils.OGCType.ST_LINESTRING, GeometryUtils.OGCType.UNKNOWN);
				return null;
			}
		} catch (Exception e) {  // IllegalArgumentException, GeometryException
			LOG.error(e.getMessage());
			return null;
		}
	}
 
Example 4
public BytesWritable evaluate(BytesWritable wkb, int wkid) throws UDFArgumentException {

		try {
			SpatialReference spatialReference = null;
			if (wkid != GeometryUtils.WKID_UNKNOWN) {
				spatialReference = SpatialReference.create(wkid);
			}
			byte [] byteArr = wkb.getBytes();
            ByteBuffer byteBuf = ByteBuffer.allocate(byteArr.length);
			byteBuf.put(byteArr);
			OGCGeometry ogcObj = OGCGeometry.fromBinary(byteBuf);
			ogcObj.setSpatialReference(spatialReference);
			if (ogcObj.geometryType().equals("LineString")) {
				return GeometryUtils.geometryToEsriShapeBytesWritable(ogcObj);
			} else {
				LogUtils.Log_InvalidType(LOG, GeometryUtils.OGCType.ST_LINESTRING, GeometryUtils.OGCType.UNKNOWN);
				return null;
			}
		} catch (Exception e) {  // IllegalArgumentException, GeometryException
			LOG.error(e.getMessage());
			return null;
		}
	}
 
Example 5
public BytesWritable evaluate(BytesWritable wkb, int wkid) throws UDFArgumentException {

		try {
			SpatialReference spatialReference = null;
			if (wkid != GeometryUtils.WKID_UNKNOWN) {
				spatialReference = SpatialReference.create(wkid);
			}
			byte [] byteArr = wkb.getBytes();
            ByteBuffer byteBuf = ByteBuffer.allocate(byteArr.length);
			byteBuf.put(byteArr);
			OGCGeometry ogcObj = OGCGeometry.fromBinary(byteBuf);
			ogcObj.setSpatialReference(spatialReference);
			String gType = ogcObj.geometryType();
			if (gType.equals("MultiPolygon") || gType.equals("Polygon")) {
				return GeometryUtils.geometryToEsriShapeBytesWritable(ogcObj);
			} else {
				LogUtils.Log_InvalidType(LOG, GeometryUtils.OGCType.ST_MULTIPOLYGON, GeometryUtils.OGCType.UNKNOWN);
				return null;
			}
		} catch (Exception e) {  // IllegalArgumentException, GeometryException
			LOG.error(e.getMessage());
			return null;
		}
	}
 
Example 6
public BytesWritable evaluate(BytesWritable wkb, int wkid) throws UDFArgumentException {

		try {
			SpatialReference spatialReference = null;
			if (wkid != GeometryUtils.WKID_UNKNOWN) {
				spatialReference = SpatialReference.create(wkid);
			}
			byte [] byteArr = wkb.getBytes();
            ByteBuffer byteBuf = ByteBuffer.allocate(byteArr.length);
			byteBuf.put(byteArr);
			OGCGeometry ogcObj = OGCGeometry.fromBinary(byteBuf);
			ogcObj.setSpatialReference(spatialReference);
			return GeometryUtils.geometryToEsriShapeBytesWritable(ogcObj);
		} catch (Exception e) {  // IllegalArgumentException, GeometryException
			LOG.error(e.getMessage());
			return null;
		}
	}
 
Example 7
public BytesWritable evaluate(BytesWritable wkb, int wkid) throws UDFArgumentException {

		try {
			SpatialReference spatialReference = null;
			if (wkid != GeometryUtils.WKID_UNKNOWN) {
				spatialReference = SpatialReference.create(wkid);
			}
			byte [] byteArr = wkb.getBytes();
            ByteBuffer byteBuf = ByteBuffer.allocate(byteArr.length);
			byteBuf.put(byteArr);
			OGCGeometry ogcObj = OGCGeometry.fromBinary(byteBuf);
			ogcObj.setSpatialReference(spatialReference);
			if (ogcObj.geometryType().equals("Polygon")) {
				return GeometryUtils.geometryToEsriShapeBytesWritable(ogcObj);
			} else {
				LogUtils.Log_InvalidType(LOG, GeometryUtils.OGCType.ST_POLYGON, GeometryUtils.OGCType.UNKNOWN);
				return null;
			}
		} catch (Exception e) {  // IllegalArgumentException, GeometryException
			LOG.error(e.getMessage());
			return null;
		}
	}
 
Example 8
public BytesWritable evaluate(BytesWritable wkb, int wkid) throws UDFArgumentException {

		try {
			SpatialReference spatialReference = null;
			if (wkid != GeometryUtils.WKID_UNKNOWN) {
				spatialReference = SpatialReference.create(wkid);
			}
			byte [] byteArr = wkb.getBytes();
            ByteBuffer byteBuf = ByteBuffer.allocate(byteArr.length);
			byteBuf.put(byteArr);
			OGCGeometry ogcObj = OGCGeometry.fromBinary(byteBuf);
			ogcObj.setSpatialReference(spatialReference);
			if (ogcObj.geometryType().equals("Point")) {
				return GeometryUtils.geometryToEsriShapeBytesWritable(ogcObj);
			} else {
				LogUtils.Log_InvalidType(LOG, GeometryUtils.OGCType.ST_POINT, GeometryUtils.OGCType.UNKNOWN);
				return null;
			}
		} catch (Exception e) {  // IllegalArgumentException, GeometryException
			LOG.error(e.getMessage());
			return null;
		}
	}
 
Example 9
Source Project: presto   File: GeoFunctions.java    License: Apache License 2.0 5 votes vote down vote up
private static OGCGeometry geomFromBinary(Slice input)
{
    requireNonNull(input, "input is null");
    OGCGeometry geometry;
    try {
        geometry = OGCGeometry.fromBinary(input.toByteBuffer().slice());
    }
    catch (IllegalArgumentException | IndexOutOfBoundsException e) {
        throw new PrestoException(INVALID_FUNCTION_ARGUMENT, "Invalid WKB", e);
    }
    geometry.setSpatialReference(null);
    return geometry;
}
 
Example 10
Source Project: geometry-api-java   File: TestOGC.java    License: Apache License 2.0 4 votes vote down vote up
@Test
public void testGeometryCollection() throws Exception {
	OGCGeometry g = OGCGeometry
			.fromText("GEOMETRYCOLLECTION(POLYGON EMPTY, POINT(1 1), LINESTRING EMPTY, MULTIPOLYGON EMPTY, MULTILINESTRING EMPTY)");
	assertTrue(g.geometryType().equals("GeometryCollection"));
	OGCConcreteGeometryCollection gc = (OGCConcreteGeometryCollection) g;
	assertTrue(gc.numGeometries() == 5);
	assertTrue(gc.geometryN(0).geometryType().equals("Polygon"));
	assertTrue(gc.geometryN(1).geometryType().equals("Point"));
	assertTrue(gc.geometryN(2).geometryType().equals("LineString"));
	assertTrue(gc.geometryN(3).geometryType().equals("MultiPolygon"));
	assertTrue(gc.geometryN(4).geometryType().equals("MultiLineString"));

	g = OGCGeometry
			.fromText("GEOMETRYCOLLECTION(POLYGON EMPTY, POINT(1 1), GEOMETRYCOLLECTION EMPTY, LINESTRING EMPTY, GEOMETRYCOLLECTION(POLYGON EMPTY, POINT(1 1), LINESTRING EMPTY, MULTIPOLYGON EMPTY, MULTILINESTRING EMPTY, MULTIPOINT EMPTY), MULTIPOLYGON EMPTY, MULTILINESTRING EMPTY)");
	assertTrue(g.geometryType().equals("GeometryCollection"));
	gc = (OGCConcreteGeometryCollection) g;
	assertTrue(gc.numGeometries() == 7);
	assertTrue(gc.geometryN(0).geometryType().equals("Polygon"));
	assertTrue(gc.geometryN(1).geometryType().equals("Point"));
	assertTrue(gc.geometryN(2).geometryType().equals("GeometryCollection"));
	assertTrue(gc.geometryN(3).geometryType().equals("LineString"));
	assertTrue(gc.geometryN(4).geometryType().equals("GeometryCollection"));
	assertTrue(gc.geometryN(5).geometryType().equals("MultiPolygon"));
	assertTrue(gc.geometryN(6).geometryType().equals("MultiLineString"));

	OGCConcreteGeometryCollection gc2 = (OGCConcreteGeometryCollection) gc
			.geometryN(4);
	assertTrue(gc2.numGeometries() == 6);
	assertTrue(gc2.geometryN(0).geometryType().equals("Polygon"));
	assertTrue(gc2.geometryN(1).geometryType().equals("Point"));
	assertTrue(gc2.geometryN(2).geometryType().equals("LineString"));
	assertTrue(gc2.geometryN(3).geometryType().equals("MultiPolygon"));
	assertTrue(gc2.geometryN(4).geometryType().equals("MultiLineString"));
	assertTrue(gc2.geometryN(5).geometryType().equals("MultiPoint"));

	ByteBuffer wkbBuffer = g.asBinary();
	g = OGCGeometry.fromBinary(wkbBuffer);

	assertTrue(g.geometryType().equals("GeometryCollection"));
	gc = (OGCConcreteGeometryCollection) g;
	assertTrue(gc.numGeometries() == 7);
	assertTrue(gc.geometryN(0).geometryType().equals("Polygon"));
	assertTrue(gc.geometryN(1).geometryType().equals("Point"));
	assertTrue(gc.geometryN(2).geometryType().equals("GeometryCollection"));
	assertTrue(gc.geometryN(3).geometryType().equals("LineString"));
	assertTrue(gc.geometryN(4).geometryType().equals("GeometryCollection"));
	assertTrue(gc.geometryN(5).geometryType().equals("MultiPolygon"));
	assertTrue(gc.geometryN(6).geometryType().equals("MultiLineString"));

	gc2 = (OGCConcreteGeometryCollection) gc.geometryN(4);
	assertTrue(gc2.numGeometries() == 6);
	assertTrue(gc2.geometryN(0).geometryType().equals("Polygon"));
	assertTrue(gc2.geometryN(1).geometryType().equals("Point"));
	assertTrue(gc2.geometryN(2).geometryType().equals("LineString"));
	assertTrue(gc2.geometryN(3).geometryType().equals("MultiPolygon"));
	assertTrue(gc2.geometryN(4).geometryType().equals("MultiLineString"));
	assertTrue(gc2.geometryN(5).geometryType().equals("MultiPoint"));

	String wktString = g.asText();
	assertTrue(wktString
			.equals("GEOMETRYCOLLECTION (POLYGON EMPTY, POINT (1 1), GEOMETRYCOLLECTION EMPTY, LINESTRING EMPTY, GEOMETRYCOLLECTION (POLYGON EMPTY, POINT (1 1), LINESTRING EMPTY, MULTIPOLYGON EMPTY, MULTILINESTRING EMPTY, MULTIPOINT EMPTY), MULTIPOLYGON EMPTY, MULTILINESTRING EMPTY)"));

	g = OGCGeometry
			.fromGeoJson("{\"type\" : \"GeometryCollection\", \"geometries\" : [{\"type\" : \"Polygon\", \"coordinates\" : []}, {\"type\" : \"Point\", \"coordinates\" : [1, 1]}, {\"type\" : \"GeometryCollection\", \"geometries\" : []}, {\"type\" : \"LineString\", \"coordinates\" : []}, {\"type\" : \"GeometryCollection\", \"geometries\" : [{\"type\": \"Polygon\", \"coordinates\" : []}, {\"type\" : \"Point\", \"coordinates\" : [1,1]}, {\"type\" : \"LineString\", \"coordinates\" : []}, {\"type\" : \"MultiPolygon\", \"coordinates\" : []}, {\"type\" : \"MultiLineString\", \"coordinates\" : []}, {\"type\" : \"MultiPoint\", \"coordinates\" : []}]}, {\"type\" : \"MultiPolygon\", \"coordinates\" : []}, {\"type\" : \"MultiLineString\", \"coordinates\" : []} ] }");

	wktString = g.asText();
	assertTrue(wktString
			.equals("GEOMETRYCOLLECTION (POLYGON EMPTY, POINT (1 1), GEOMETRYCOLLECTION EMPTY, LINESTRING EMPTY, GEOMETRYCOLLECTION (POLYGON EMPTY, POINT (1 1), LINESTRING EMPTY, MULTIPOLYGON EMPTY, MULTILINESTRING EMPTY, MULTIPOINT EMPTY), MULTIPOLYGON EMPTY, MULTILINESTRING EMPTY)"));
	
	assertTrue(g.equals((Object)OGCGeometry.fromText(wktString)));
	
	assertTrue(g.hashCode() == OGCGeometry.fromText(wktString).hashCode());

}