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
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
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 3
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 4
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 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);
			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 6
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 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);
			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 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);
			return GeometryUtils.geometryToEsriShapeBytesWritable(ogcObj);
		} catch (Exception e) {  // IllegalArgumentException, GeometryException
			LOG.error(e.getMessage());
			return null;
		}
	}
 
Example 9
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 10
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 11
Source Project: geometry-api-java   File: TestOGC.java    License: 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 12
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 13
private static void assertGeometryEquals(OGCGeometry actual, OGCGeometry expected)
{
    actual.setSpatialReference(null);
    expected.setSpatialReference(null);
    ensureEnvelopeLoaded(actual);
    ensureEnvelopeLoaded(expected);
    assertEquals(actual, expected);
}
 
Example 14
Source Project: geometry-api-java   File: TestOGC.java    License: 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 15
Source Project: geometry-api-java   File: TestOGC.java    License: 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 16
Source Project: geometry-api-java   File: TestOGC.java    License: 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 17
Source Project: geometry-api-java   File: TestOGC.java    License: 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 18
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 19
Source Project: geometry-api-java   File: TestOGC.java    License: 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 20
private static OGCGeometry parseWkt(String wkt) {
	OGCGeometry geometry = OGCGeometry.fromText(wkt);
	geometry.setSpatialReference(null);
	return geometry;
}