Java Code Examples for com.esri.core.geometry.GeometryEngine#union()

The following examples show how to use com.esri.core.geometry.GeometryEngine#union() . 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: GeoFunctions.java    From Bats with Apache License 2.0 5 votes vote down vote up
/** Computes the union of {@code geom1} and {@code geom2}. */
public static Geom ST_Union(Geom geom1, Geom geom2) {
  SpatialReference sr = geom1.sr();
  final Geometry g =
      GeometryEngine.union(new Geometry[]{geom1.g(), geom2.g()}, sr);
  return bind(g, sr);
}
 
Example 2
Source File: GeoFunctions.java    From Bats with Apache License 2.0 5 votes vote down vote up
/** Computes the union of the geometries in {@code geomCollection}. */
 public static Geom ST_Union(Geom geomCollection) {
  SpatialReference sr = geomCollection.sr();
  final Geometry g =
      GeometryEngine.union(new Geometry[] {geomCollection.g()}, sr);
  return bind(g, sr);
}
 
Example 3
Source File: GeoFunctions.java    From Quicksql with MIT License 5 votes vote down vote up
/** Computes the union of {@code geom1} and {@code geom2}. */
public static Geom ST_Union(Geom geom1, Geom geom2) {
  SpatialReference sr = geom1.sr();
  final Geometry g =
      GeometryEngine.union(new Geometry[]{geom1.g(), geom2.g()}, sr);
  return bind(g, sr);
}
 
Example 4
Source File: GeoFunctions.java    From Quicksql with MIT License 5 votes vote down vote up
/** Computes the union of the geometries in {@code geomCollection}. */
@SemiStrict public static Geom ST_Union(Geom geomCollection) {
  SpatialReference sr = geomCollection.sr();
  final Geometry g =
      GeometryEngine.union(new Geometry[] {geomCollection.g()}, sr);
  return bind(g, sr);
}
 
Example 5
Source File: GeoFunctions.java    From calcite with Apache License 2.0 5 votes vote down vote up
/** Computes the union of {@code geom1} and {@code geom2}. */
public static Geom ST_Union(Geom geom1, Geom geom2) {
  SpatialReference sr = geom1.sr();
  final Geometry g =
      GeometryEngine.union(new Geometry[]{geom1.g(), geom2.g()}, sr);
  return bind(g, sr);
}
 
Example 6
Source File: GeoFunctions.java    From calcite with Apache License 2.0 5 votes vote down vote up
/** Computes the union of the geometries in {@code geomCollection}. */
@SemiStrict public static Geom ST_Union(Geom geomCollection) {
  SpatialReference sr = geomCollection.sr();
  final Geometry g =
      GeometryEngine.union(new Geometry[] {geomCollection.g()}, sr);
  return bind(g, sr);
}
 
Example 7
Source File: ST_Union.java    From spatial-framework-for-hadoop with Apache License 2.0 4 votes vote down vote up
public BytesWritable evaluate (BytesWritable ... geomrefs){
	// validate arguments
	if (geomrefs == null || geomrefs.length < 2){
		LogUtils.Log_VariableArgumentLength(LOG);
	}

	int firstWKID = 0;

	SpatialReference spatialRef = null;

	// validate spatial references and geometries first
	for (int i=0;i<geomrefs.length; i++){
		
		BytesWritable geomref = geomrefs[i];
		
		if (geomref == null || geomref.getLength() == 0){
			LogUtils.Log_ArgumentsNull(LOG);
			return null;
		}

		if (i==0){
			firstWKID = GeometryUtils.getWKID(geomref);
			if (firstWKID != GeometryUtils.WKID_UNKNOWN) {
				spatialRef = SpatialReference.create(firstWKID);
			}
		} else if (firstWKID != GeometryUtils.getWKID(geomref)){
			LogUtils.Log_SRIDMismatch(LOG, geomrefs[0], geomref);
			return null;
		}
	}
	
	// now build geometry array to pass to GeometryEngine.union
	Geometry [] geomsToUnion = new Geometry[geomrefs.length];
	
	for (int i=0;i<geomrefs.length;i++){
		//HiveGeometry hiveGeometry = GeometryUtils.geometryFromEsriShape(geomrefs[i]);
		OGCGeometry ogcGeometry = GeometryUtils.geometryFromEsriShape(geomrefs[i]);
		
		// if (i==0){   // get from ogcGeometry rather than re-create above?
		// 	spatialRef = hiveGeometry.spatialReference;
		// }
		
		if (ogcGeometry == null){
			LogUtils.Log_ArgumentsNull(LOG);
			return null;
		}
		
		geomsToUnion[i] = ogcGeometry.getEsriGeometry();
	}
	
	try {
		Geometry unioned = GeometryEngine.union(geomsToUnion, spatialRef);

		// we have to infer the type of the differenced geometry because we don't know
		// if it's going to end up as a single or multi-part geometry
		OGCType inferredType = GeometryUtils.getInferredOGCType(unioned);
		
		return GeometryUtils.geometryToEsriShapeBytesWritable(unioned, firstWKID, inferredType);
	} catch (Exception e){
		LogUtils.Log_ExceptionThrown(LOG, "GeometryEngine.union", e);
		return null;
	}
}