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

The following examples show how to use com.esri.core.geometry.ogc.OGCGeometry. 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_MLineFromWKB.java    From spatial-framework-for-hadoop with Apache License 2.0 6 votes vote down vote up
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 #2
Source File: ST_AsText.java    From spatial-framework-for-hadoop with Apache License 2.0 6 votes vote down vote up
public Text 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;
	}
	
	int wktExportFlag = getWktExportFlag(GeometryUtils.getType(geomref));
	
	try {
		// mind: GeometryType with ST_AsText(ST_GeomFromText('MultiLineString((0 80, 0.03 80.04))'))
		// return new Text(ogcGeometry.asText());
		return new Text(GeometryEngine.geometryToWkt(ogcGeometry.getEsriGeometry(), wktExportFlag));
	} catch (Exception e){
		LOG.error(e.getMessage());
		return null;
	}
}
 
Example #3
Source File: GeometrySerde.java    From presto with Apache License 2.0 6 votes vote down vote up
private static void writePoint(DynamicSliceOutput output, OGCGeometry geometry)
{
    Geometry esriGeometry = geometry.getEsriGeometry();
    verify(esriGeometry instanceof Point, "geometry is expected to be an instance of Point");
    Point point = (Point) esriGeometry;
    verify(!point.hasAttribute(VertexDescription.Semantics.Z) &&
                    !point.hasAttribute(VertexDescription.Semantics.M) &&
                    !point.hasAttribute(VertexDescription.Semantics.ID),
            "Only 2D points with no ID nor M attribute are supported");
    output.appendByte(GeometrySerializationType.POINT.code());
    if (!point.isEmpty()) {
        output.appendDouble(point.getX());
        output.appendDouble(point.getY());
    }
    else {
        output.appendDouble(NaN);
        output.appendDouble(NaN);
    }
}
 
Example #4
Source File: ST_LineString.java    From spatial-framework-for-hadoop with Apache License 2.0 6 votes vote down vote up
public BytesWritable evaluate(Text wkwrap) throws UDFArgumentException {
	String wkt = wkwrap.toString();
	try {
		OGCGeometry ogcObj = OGCGeometry.fromText(wkt);
		ogcObj.setSpatialReference(null);
		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
		LogUtils.Log_InvalidText(LOG, wkt);
		return null;
	}
}
 
Example #5
Source File: ST_NumInteriorRing.java    From spatial-framework-for-hadoop with Apache License 2.0 6 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;
	}
	if (GeometryUtils.getType(geomref) == GeometryUtils.OGCType.ST_POLYGON) {
		try {
			resultInt.set(((OGCPolygon)(ogcGeometry)).numInteriorRing());
			return resultInt;
		} catch (Exception e) {
			LogUtils.Log_InternalError(LOG, "ST_NumInteriorRing: " + e);
			return null;
		}
	} else {
		LogUtils.Log_InvalidType(LOG, GeometryUtils.OGCType.ST_POLYGON, GeometryUtils.getType(geomref));
		return null;
	}
}
 
Example #6
Source File: TestOGC.java    From geometry-api-java with Apache License 2.0 6 votes vote down vote up
@Test
public void testMultiPolygonUnion() {
	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))");
	OGCGeometry g2 = OGCGeometry
			.fromText("POLYGON((90 90, 110 90, 110 110, 90 110, 90 90))");
	OGCGeometry u = g.union(g2);
	assertTrue(u.geometryType().equals("MultiPolygon"));
	assertTrue(!u.contains(OGCGeometry.fromText("POINT(0 0)")));
	assertTrue(u.contains(OGCGeometry.fromText("POINT(9 9)")));
	assertTrue(!u.contains(OGCGeometry.fromText("POINT(-20 1)")));
	assertTrue(u.disjoint(OGCGeometry.fromText("POINT(0 0)")));
	assertTrue(!u.disjoint(OGCGeometry.fromText("POINT(9 9)")));
	assertTrue(u.disjoint(OGCGeometry.fromText("POINT(-20 1)")));
	assertTrue(u.contains(OGCGeometry.fromText("POINT(100 100)")));
}
 
Example #7
Source File: ST_Buffer.java    From spatial-framework-for-hadoop with Apache License 2.0 6 votes vote down vote up
public BytesWritable evaluate(BytesWritable geometryref1, DoubleWritable distance)
{
	if (geometryref1 == null || geometryref1.getLength() == 0 || distance == null) {
		return null;
	}

	OGCGeometry ogcGeometry = GeometryUtils.geometryFromEsriShape(geometryref1);
	if (ogcGeometry == null){
		LogUtils.Log_ArgumentsNull(LOG);
		return null;
	}

	OGCGeometry bufferedGeometry = ogcGeometry.buffer(distance.get());
	// TODO persist type information (polygon vs multipolygon)
	return GeometryUtils.geometryToEsriShapeBytesWritable(bufferedGeometry);
}
 
Example #8
Source File: ST_AsJson.java    From spatial-framework-for-hadoop with Apache License 2.0 6 votes vote down vote up
public Text 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;
	}

	Geometry esriGeom = ogcGeometry.getEsriGeometry();
	int wkid = GeometryUtils.getWKID(geomref);
	return new Text(GeometryEngine.geometryToJson(wkid, esriGeom));
}
 
Example #9
Source File: ST_PointFromWKB.java    From spatial-framework-for-hadoop with Apache License 2.0 6 votes vote down vote up
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 #10
Source File: GeoFunctions.java    From presto with Apache License 2.0 6 votes vote down vote up
@Description("Returns a Geometry type object from Spatial Framework for Hadoop representation")
@ScalarFunction("geometry_from_hadoop_shape")
@SqlType(GEOMETRY_TYPE_NAME)
public static Slice geometryFromHadoopShape(@SqlType(VARBINARY) Slice input)
{
    requireNonNull(input, "input is null");

    try {
        OGCGeometry geometry = OGCGeometry.fromEsriShape(getShapeByteBuffer(input));
        String wkt = geometryToWkt(geometry.getEsriGeometry(), getWktExportFlags(input));
        return serialize(OGCGeometry.fromText(wkt));
    }
    catch (IndexOutOfBoundsException | UnsupportedOperationException | IllegalArgumentException e) {
        throw new PrestoException(INVALID_FUNCTION_ARGUMENT, "Invalid Hadoop shape", e);
    }
}
 
Example #11
Source File: ST_M.java    From spatial-framework-for-hadoop with Apache License 2.0 6 votes vote down vote up
public DoubleWritable evaluate(BytesWritable geomref) {
	if (geomref == null || geomref.getLength() == 0) {
		LogUtils.Log_ArgumentsNull(LOG);
		return null;
	}

	OGCGeometry ogcGeometry = GeometryUtils.geometryFromEsriShape(geomref);
	if (ogcGeometry == null){
		return null;
	}
	if (!ogcGeometry.isMeasured()) {
		LogUtils.Log_NotMeasured(LOG);
		return null;
	}

	switch(GeometryUtils.getType(geomref)) {
	case ST_POINT:
		OGCPoint pt = (OGCPoint)ogcGeometry;
		resultDouble.set(pt.M());
		return resultDouble;
	default:
		LogUtils.Log_InvalidType(LOG, GeometryUtils.OGCType.ST_POINT, GeometryUtils.getType(geomref));
		return null;
	}
}
 
Example #12
Source File: ST_GeomCollection.java    From spatial-framework-for-hadoop with Apache License 2.0 6 votes vote down vote up
public BytesWritable evaluate(Text wkwrap, int wkid) throws UDFArgumentException {

		String wkt = wkwrap.toString();

		try {
			Geometry geomObj = GeometryEngine.geometryFromWkt(wkt,
															  0,
															  Geometry.Type.Unknown);
			SpatialReference spatialReference = null;  // Idea: OGCGeometry.setSpatialReference after .fromText
			if (wkid != GeometryUtils.WKID_UNKNOWN) {
				spatialReference = SpatialReference.create(wkid);
			}
			OGCGeometry ogcObj = OGCGeometry.createFromEsriGeometry(geomObj, spatialReference);
			return GeometryUtils.geometryToEsriShapeBytesWritable(ogcObj);
		} catch (Exception e) {  // IllegalArgumentException, GeometryException
			LogUtils.Log_InvalidText(LOG, wkt);
			return null;
		}
	}
 
Example #13
Source File: ST_MultiPoint.java    From spatial-framework-for-hadoop with Apache License 2.0 6 votes vote down vote up
public BytesWritable evaluate(DoubleWritable ... xyPairs) throws UDFArgumentLengthException{

		if (xyPairs == null || xyPairs.length == 0 ||  xyPairs.length%2 != 0) {
			LogUtils.Log_VariableArgumentLengthXY(LOG);
			return null;
		}

		try {
			MultiPoint mPoint = new MultiPoint();

			for (int i=0;i<xyPairs.length;i+=2){
				mPoint.add(xyPairs[i].get(), xyPairs[i+1].get());
			}

			return GeometryUtils.geometryToEsriShapeBytesWritable(OGCGeometry.createFromEsriGeometry(mPoint, null, true));
		} catch (Exception e) {
		    LogUtils.Log_InternalError(LOG, "ST_MultiPoint: " + e);
		    return null;
		}
	}
 
Example #14
Source File: TestStGeomFromShape.java    From spatial-framework-for-hadoop with Apache License 2.0 6 votes vote down vote up
@Test
public void testGeomFromLineShape() throws UDFArgumentException {
	Polyline line = createLine();
	byte[] esriShape = GeometryEngine.geometryToEsriShape(line);
	assertNotNull("The shape must not be null!", esriShape);

	BytesWritable shapeAsWritable = new BytesWritable(esriShape);
	assertNotNull("The shape writable must not be null!", shapeAsWritable);

	final int wkid = 4326;
	ST_GeomFromShape fromShape = new ST_GeomFromShape();
	BytesWritable geometryAsWritable = fromShape.evaluate(shapeAsWritable, wkid);
	assertNotNull("The geometry writable must not be null!", geometryAsWritable);

	OGCGeometry ogcGeometry = GeometryUtils.geometryFromEsriShape(geometryAsWritable);
	assertNotNull("The OGC geometry must not be null!", ogcGeometry);

	Geometry esriGeometry = ogcGeometry.getEsriGeometry();
	assertNotNull("The Esri geometry must not be null!", esriGeometry);
	assertTrue("The geometries are different!",
			GeometryEngine.equals(line, esriGeometry, SpatialReference.create(wkid)));
}
 
Example #15
Source File: ST_GeometryRelational.java    From spatial-framework-for-hadoop with Apache License 2.0 6 votes vote down vote up
@Override
public Object evaluate(DeferredObject[] args) throws HiveException {
	
	OGCGeometry geom1 = geomHelper1.getGeometry(args);
	OGCGeometry geom2 = geomHelper2.getGeometry(args);
	
	if (geom1 == null || geom2 == null) {
		return false;
	}

	if (firstRun && geomHelper1.isConstant()) {
		
		// accelerate geometry 1 for quick relation operations since it is constant
		geom1IsAccelerated = opSimpleRelation.accelerateGeometry(geom1.getEsriGeometry(), 
				geom1.getEsriSpatialReference(), GeometryAccelerationDegree.enumMedium);
	}

	firstRun = false;
	
	return opSimpleRelation.execute(geom1.getEsriGeometry(), geom2.getEsriGeometry(), geom1.getEsriSpatialReference(), null);
}
 
Example #16
Source File: GeoFunctions.java    From presto with Apache License 2.0 6 votes vote down vote up
@SqlNullable
@Description("Returns an array of interior rings of a polygon")
@ScalarFunction("ST_InteriorRings")
@SqlType("array(" + GEOMETRY_TYPE_NAME + ")")
public static Block stInteriorRings(@SqlType(GEOMETRY_TYPE_NAME) Slice input)
{
    OGCGeometry geometry = deserialize(input);
    validateType("ST_InteriorRings", geometry, EnumSet.of(POLYGON));
    if (geometry.isEmpty()) {
        return null;
    }

    OGCPolygon polygon = (OGCPolygon) geometry;
    BlockBuilder blockBuilder = GEOMETRY.createBlockBuilder(null, polygon.numInteriorRing());
    for (int i = 0; i < polygon.numInteriorRing(); i++) {
        GEOMETRY.writeSlice(blockBuilder, serialize(polygon.interiorRingN(i)));
    }
    return blockBuilder.build();
}
 
Example #17
Source File: ST_IsSimple.java    From spatial-framework-for-hadoop with Apache License 2.0 6 votes vote down vote up
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 {
		resultBoolean.set(ogcGeometry.isSimple());
	} catch (Exception e) {
	    LogUtils.Log_InternalError(LOG, "ST_IsSimple" + e);
		return null;
	}
	return resultBoolean;
}
 
Example #18
Source File: TestEstimateMemorySize.java    From geometry-api-java with Apache License 2.0 6 votes vote down vote up
private void testAcceleratedGeometry(OGCGeometry geometry) {
	long initialSize = geometry.estimateMemorySize();
	assertTrue(initialSize > 0);

	Envelope envelope = new Envelope();
	geometry.getEsriGeometry().queryEnvelope(envelope);

	long withEnvelopeSize = geometry.estimateMemorySize();
	assertTrue(withEnvelopeSize > initialSize);

	accelerate(geometry, GeometryAccelerationDegree.enumMild);
	long mildAcceleratedSize = geometry.estimateMemorySize();
	assertTrue(mildAcceleratedSize > withEnvelopeSize);

	accelerate(geometry, GeometryAccelerationDegree.enumMedium);
	long mediumAcceleratedSize = geometry.estimateMemorySize();
	assertTrue(mediumAcceleratedSize > mildAcceleratedSize);

	accelerate(geometry, GeometryAccelerationDegree.enumHot);
	long hotAcceleratedSize = geometry.estimateMemorySize();
	assertTrue(hotAcceleratedSize > mediumAcceleratedSize);
}
 
Example #19
Source File: TestOGC.java    From geometry-api-java with Apache License 2.0 6 votes vote down vote up
@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 #20
Source File: UserDefinedGeoJsonSpatialFilter.java    From bboxdb with Apache License 2.0 6 votes vote down vote up
/**
 * Perform a real join based on the geometry of the data
 */
@Override
public boolean filterJoinCandidate(final Tuple tuple1, final Tuple tuple2, final byte[] customData) {
	
	final String geoJsonString1 = new String(tuple1.getDataBytes());
	final String geoJsonString2 = new String(tuple2.getDataBytes());

	// Full text search on string (if provided)
	if(customData != null) {
		final String customDataString = new String(customData);
		if(! geoJsonString1.contains(customDataString) && 
				! geoJsonString2.contains(customDataString)) {
			return false;
		}
	}
	
	final OGCGeometry geometry1 = extractGeometry(geoJsonString1);
	final OGCGeometry geometry2 = extractGeometry(geoJsonString2);
	
	if(geometry1 instanceof OGCPoint) {
		final double geometryDistrance = geometry1.distance(geometry2);
		return geometryDistrance < MAX_OVERLAPPING_POINT_DISTANCE;
	} else {
	    return geometry1.intersects(geometry2);
	}
}
 
Example #21
Source File: ST_MPolyFromWKB.java    From spatial-framework-for-hadoop with Apache License 2.0 6 votes vote down vote up
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 #22
Source File: TestOGC.java    From geometry-api-java with Apache License 2.0 5 votes vote down vote up
@Test
public void testNullSr() {
	String wkt = "point (0 0)";
	OGCGeometry g = OGCGeometry.fromText(wkt);
	g.setSpatialReference(null);
	assertTrue(g.SRID() < 1);
}
 
Example #23
Source File: ST_Aggr_Union.java    From spatial-framework-for-hadoop with Apache License 2.0 5 votes vote down vote up
public BytesWritable terminatePartial() throws HiveException {
	try {
		Geometry rslt = xgc.next();
		lgc = null;  // not reusable
		xgc = null;  // not reusable
		OGCGeometry ogeom = OGCGeometry.createFromEsriGeometry(rslt, spatialRef);
		return GeometryUtils.geometryToEsriShapeBytesWritable(ogeom);
	} catch (Exception e) {
		LogUtils.Log_InternalError(LOG, "ST_Aggr_Union: " + e);
	}
	return null;
}
 
Example #24
Source File: TestSpatialPartitioningInternalAggregation.java    From presto with Apache License 2.0 5 votes vote down vote up
private List<OGCGeometry> makeGeometries()
{
    ImmutableList.Builder<OGCGeometry> geometries = ImmutableList.builder();
    for (int i = 0; i < 10; i++) {
        for (int j = 0; j < 10; j++) {
            geometries.add(new OGCPoint(new Point(-10 + i, -10 + j), null));
        }
    }

    for (int i = 0; i < 5; i++) {
        for (int j = 0; j < 5; j++) {
            geometries.add(new OGCPoint(new Point(-10 + 2 * i, 2 * j), null));
        }
    }

    for (int i = 0; i < 4; i++) {
        for (int j = 0; j < 4; j++) {
            geometries.add(new OGCPoint(new Point(2.5 * i, -10 + 2.5 * j), null));
        }
    }

    for (int i = 0; i < 3; i++) {
        for (int j = 0; j < 3; j++) {
            geometries.add(new OGCPoint(new Point(5 * i, 5 * j), null));
        }
    }

    return geometries.build();
}
 
Example #25
Source File: GeoFunctions.java    From presto with Apache License 2.0 5 votes vote down vote up
@SqlNullable
@Description("Returns TRUE if the Geometries do not spatially intersect - if they do not share any space together")
@ScalarFunction("ST_Disjoint")
@SqlType(BOOLEAN)
public static Boolean stDisjoint(@SqlType(GEOMETRY_TYPE_NAME) Slice left, @SqlType(GEOMETRY_TYPE_NAME) Slice right)
{
    if (!envelopes(left, right, Envelope::intersect)) {
        return true;
    }
    OGCGeometry leftGeometry = deserialize(left);
    OGCGeometry rightGeometry = deserialize(right);
    verifySameSpatialReference(leftGeometry, rightGeometry);
    return leftGeometry.disjoint(rightGeometry);
}
 
Example #26
Source File: GeometryUtils.java    From presto with Apache License 2.0 5 votes vote down vote up
public static Envelope getEnvelope(OGCGeometry ogcGeometry)
{
    GeometryCursor cursor = ogcGeometry.getEsriGeometryCursor();
    Envelope overallEnvelope = new Envelope();
    while (true) {
        Geometry geometry = cursor.next();
        if (geometry == null) {
            return overallEnvelope;
        }

        Envelope envelope = new Envelope();
        geometry.queryEnvelope(envelope);
        overallEnvelope.merge(envelope);
    }
}
 
Example #27
Source File: ST_EnvIntersects.java    From spatial-framework-for-hadoop with Apache License 2.0 5 votes vote down vote up
public BooleanWritable evaluate(BytesWritable geometryref1, BytesWritable geometryref2)
{
	if (geometryref1 == null || geometryref2 == null ||
	    geometryref1.getLength() == 0 || geometryref2.getLength() == 0) {
		LogUtils.Log_ArgumentsNull(LOG);
		return null;
	}
	if (!GeometryUtils.compareSpatialReferences(geometryref1, geometryref2)) {
		LogUtils.Log_SRIDMismatch(LOG, geometryref1, geometryref2);
		return null;
	}

	OGCGeometry ogcGeom1 = GeometryUtils.geometryFromEsriShape(geometryref1);
	OGCGeometry ogcGeom2 = GeometryUtils.geometryFromEsriShape(geometryref2);
	if (ogcGeom1 == null || ogcGeom2 == null){
		LogUtils.Log_ArgumentsNull(LOG);
		return null;
	}

	Geometry geometry1 = ogcGeom1.getEsriGeometry();
	Geometry geometry2 = ogcGeom2.getEsriGeometry();
	Envelope env1 = new Envelope(), env2 = new Envelope();
	geometry1.queryEnvelope(env1);
	geometry2.queryEnvelope(env2);

	resultBoolean.set(env1.isIntersecting(env2));
	return resultBoolean;
}
 
Example #28
Source File: GeoFunctions.java    From presto with Apache License 2.0 5 votes vote down vote up
private static void validateType(String function, OGCGeometry geometry, Set<GeometryType> validTypes)
{
    GeometryType type = GeometryType.getForEsriGeometryType(geometry.geometryType());
    if (!validTypes.contains(type)) {
        throw new PrestoException(INVALID_FUNCTION_ARGUMENT, format("%s only applies to %s. Input type is: %s", function, OR_JOINER.join(validTypes), type));
    }
}
 
Example #29
Source File: GeoFunctions.java    From presto with Apache License 2.0 5 votes vote down vote up
@SqlNullable
@Description("Returns TRUE if the Geometries spatially intersect in 2D - (share any portion of space) and FALSE if they don't (they are Disjoint)")
@ScalarFunction("ST_Intersects")
@SqlType(BOOLEAN)
public static Boolean stIntersects(@SqlType(GEOMETRY_TYPE_NAME) Slice left, @SqlType(GEOMETRY_TYPE_NAME) Slice right)
{
    if (!envelopes(left, right, Envelope::intersect)) {
        return false;
    }
    OGCGeometry leftGeometry = deserialize(left);
    OGCGeometry rightGeometry = deserialize(right);
    verifySameSpatialReference(leftGeometry, rightGeometry);
    return leftGeometry.intersects(rightGeometry);
}
 
Example #30
Source File: TestOGC.java    From geometry-api-java with Apache License 2.0 5 votes vote down vote up
@Test
public void testPointInPolygon() {
	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"));
	assertTrue(!g.contains(OGCGeometry.fromText("POINT(0 0)")));
	assertTrue(g.contains(OGCGeometry.fromText("POINT(9 9)")));
	assertTrue(!g.contains(OGCGeometry.fromText("POINT(-20 1)")));
	assertTrue(g.disjoint(OGCGeometry.fromText("POINT(0 0)")));
	assertTrue(!g.disjoint(OGCGeometry.fromText("POINT(9 9)")));
	assertTrue(g.disjoint(OGCGeometry.fromText("POINT(-20 1)")));
}