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

The following examples show how to use com.esri.core.geometry.ogc.OGCGeometry#setSpatialReference() . 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_MultiLineString.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("MultiLineString")) {
			return GeometryUtils.geometryToEsriShapeBytesWritable(ogcObj);
		} else {
			LogUtils.Log_InvalidType(LOG, GeometryUtils.OGCType.ST_MULTILINESTRING, GeometryUtils.OGCType.UNKNOWN);
			return null;
		}

	} catch (Exception e) {  // IllegalArgumentException, GeometryException
		LogUtils.Log_InvalidText(LOG, wkt);
		return null;
	}
}
 
Example 2
Source File: ST_PolyFromWKB.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("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 3
Source File: ST_MPointFromWKB.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("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
Source File: ST_GeomFromText.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 {
			SpatialReference spatialReference = null;
			if (wkid != GeometryUtils.WKID_UNKNOWN) {
				spatialReference = SpatialReference.create(wkid);
			}
			OGCGeometry ogcObj = OGCGeometry.fromText(wkt);
			ogcObj.setSpatialReference(spatialReference);
			return GeometryUtils.geometryToEsriShapeBytesWritable(ogcObj);
		} catch (Exception e) {  // IllegalArgumentException, GeometryException
			LogUtils.Log_InvalidText(LOG, wkt);
			return null;
		}
	}
 
Example 5
Source File: ST_Polygon.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("Polygon")) {
			return GeometryUtils.geometryToEsriShapeBytesWritable(ogcObj);
		} else {
			LogUtils.Log_InvalidType(LOG, GeometryUtils.OGCType.ST_POLYGON, GeometryUtils.OGCType.UNKNOWN);
			return null;
		}
	} catch (Exception e) {  // IllegalArgumentException, GeometryException
		LogUtils.Log_InvalidText(LOG, wkt);
		return null;
	}
}
 
Example 6
Source File: ST_MultiPolygon.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("MultiPolygon")) {
			return GeometryUtils.geometryToEsriShapeBytesWritable(ogcObj);
		} else {
			LogUtils.Log_InvalidType(LOG, GeometryUtils.OGCType.ST_MULTIPOLYGON, GeometryUtils.OGCType.UNKNOWN);
			return null;
		}
	} catch (Exception e) {  // IllegalArgumentException, GeometryException
		LogUtils.Log_InvalidText(LOG, wkt);
		return null;
	}
}
 
Example 7
Source File: ST_LineFromWKB.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("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 8
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 9
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 10
Source File: ST_GeomFromWKB.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);
			return GeometryUtils.geometryToEsriShapeBytesWritable(ogcObj);
		} catch (Exception e) {  // IllegalArgumentException, GeometryException
			LOG.error(e.getMessage());
			return null;
		}
	}
 
Example 11
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 12
Source File: TestOGC.java    From geometry-api-java with Apache License 2.0 5 votes vote down vote up
@Test
public void testIsectTria2() {
	String wkt = "polygon((1 0, 3 0, 1 2, 1 0))";
	String wk2 = "polygon((0 3, 2 1, 3 1, 0 3))";
	OGCGeometry g0 = OGCGeometry.fromText(wkt);
	OGCGeometry g1 = OGCGeometry.fromText(wk2);
	g0.setSpatialReference(null);
	g1.setSpatialReference(null);
	OGCGeometry rslt = g0.intersection(g1);
	assertTrue(rslt != null);
	assertTrue(rslt.dimension() == 1);
	assertTrue(rslt.geometryType().equals("LineString"));
	String s = rslt.asText();
}
 
Example 13
Source File: ST_Aggr_Intersection.java    From spatial-framework-for-hadoop with Apache License 2.0 5 votes vote down vote up
public boolean iterate(BytesWritable geomref) throws HiveException {

			if (geomref == null) {
				LogUtils.Log_ArgumentsNull(LOG);
				return false;
			}

			if (firstWKID == -2) {
				firstWKID = GeometryUtils.getWKID(geomref);
				if (firstWKID != GeometryUtils.WKID_UNKNOWN) {
					spatialRef = SpatialReference.create(firstWKID);
				}
			} else if (firstWKID != GeometryUtils.getWKID(geomref)) {
				LogUtils.Log_SRIDMismatch(LOG, geomref, firstWKID);
				return false;
			}

			try {
				OGCGeometry rowGeom = GeometryUtils.geometryFromEsriShape(geomref);
				rowGeom.setSpatialReference(spatialRef);
				if (isectGeom == null)
					isectGeom = rowGeom;
				else
					isectGeom = isectGeom.intersection(rowGeom);
				return true;
			} catch (Exception e) {
				LogUtils.Log_InternalError(LOG, "ST_Aggr_Intersection: " + e);
				return false;
			}

		}
 
Example 14
Source File: TestOGC.java    From geometry-api-java with Apache License 2.0 5 votes vote down vote up
@Test
public void testIsectTria3() {
	String wkt = "polygon((1 0, 3 0, 1 2, 1 0))";
	String wk2 = "polygon((2 2, 2 1, 3 1, 2 2))";
	OGCGeometry g0 = OGCGeometry.fromText(wkt);
	OGCGeometry g1 = OGCGeometry.fromText(wk2);
	g0.setSpatialReference(SpatialReference.create(4326));
	g1.setSpatialReference(SpatialReference.create(4326));
	OGCGeometry rslt = g0.intersection(g1);
	assertTrue(rslt != null);
	assertTrue(rslt.dimension() == 0);
	assertTrue(rslt.geometryType().equals("Point"));
	assertTrue(rslt.esriSR.getID() == 4326);
	String s = rslt.asText();
}
 
Example 15
Source File: TestOGC.java    From geometry-api-java with Apache License 2.0 5 votes vote down vote up
@Test
public void testIsectTria1() {
	String wkt = "polygon((1 0, 3 0, 1 2, 1 0))";
	String wk2 = "polygon((0 1, 2 1, 0 3, 0 1))";
	OGCGeometry g0 = OGCGeometry.fromText(wkt);
	OGCGeometry g1 = OGCGeometry.fromText(wk2);
	g0.setSpatialReference(SpatialReference.create(4326));
	g1.setSpatialReference(SpatialReference.create(4326));
	OGCGeometry rslt = g0.intersection(g1);
	assertTrue(rslt != null);
	assertTrue(rslt.geometryType().equals("Polygon"));
	assertTrue(rslt.esriSR.getID() == 4326);
	String s = rslt.asText();
}
 
Example 16
Source File: TestOGC.java    From geometry-api-java with Apache License 2.0 5 votes vote down vote up
@Test
public void testIsectPoint() {
	String wkt = "point (0 0)";
	String wk2 = "point (0 0)";
	OGCGeometry g0 = OGCGeometry.fromText(wkt);
	OGCGeometry g1 = OGCGeometry.fromText(wk2);
	g0.setSpatialReference(null);
	g1.setSpatialReference(null);
	try {
		OGCGeometry rslt = g0.intersection(g1); // ArrayIndexOutOfBoundsException
		assertTrue(rslt != null);
	} catch (Exception e) {
		assertTrue(false);
	}
}
 
Example 17
Source File: TestOGC.java    From geometry-api-java with Apache License 2.0 5 votes vote down vote up
@Test
public void testIsectDisjoint() {
	String wk3 = "linestring (0 0, 1 1)";
	String wk4 = "linestring (2 2, 4 4)";
	OGCGeometry g0 = OGCGeometry.fromText(wk3);
	OGCGeometry g1 = OGCGeometry.fromText(wk4);
	g0.setSpatialReference(null);
	g1.setSpatialReference(null);
	try {
		OGCGeometry rslt = g0.intersection(g1); // null
		assertTrue(rslt != null);
	} catch (Exception e) {
		assertTrue(false);
	}
}
 
Example 18
Source File: TestGeometrySerialization.java    From presto with Apache License 2.0 5 votes vote down vote up
private static void assertGeometryEquals(OGCGeometry actual, OGCGeometry expected)
{
    actual.setSpatialReference(null);
    expected.setSpatialReference(null);
    ensureEnvelopeLoaded(actual);
    ensureEnvelopeLoaded(expected);
    assertEquals(actual, expected);
}
 
Example 19
Source File: GeoFunctions.java    From presto with 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 20
Source File: TestEstimateMemorySize.java    From geometry-api-java with Apache License 2.0 4 votes vote down vote up
private static OGCGeometry parseWkt(String wkt) {
	OGCGeometry geometry = OGCGeometry.fromText(wkt);
	geometry.setSpatialReference(null);
	return geometry;
}