com.esri.core.geometry.OperatorUnion Java Examples

The following examples show how to use com.esri.core.geometry.OperatorUnion. 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: OGCGeometry.java    From geometry-api-java with Apache License 2.0 6 votes vote down vote up
public OGCGeometry union(OGCGeometry another) {
	String thisType = geometryType();
	String anotherType = another.geometryType();
	if (thisType != anotherType || thisType == OGCConcreteGeometryCollection.TYPE) {
		//heterogeneous union.
		//We make a geometry collection, then process to union parts and remove overlaps.
		ArrayList<OGCGeometry> geoms = new ArrayList<OGCGeometry>();
		geoms.add(this);
		geoms.add(another);
		OGCConcreteGeometryCollection geomCol = new OGCConcreteGeometryCollection(geoms, esriSR);
		return geomCol.flattenAndRemoveOverlaps().reduceFromMulti();
	}
	
	OperatorUnion op = (OperatorUnion) OperatorFactoryLocal.getInstance()
			.getOperator(Operator.Type.Union);
	GeometryCursorAppend ap = new GeometryCursorAppend(
			getEsriGeometryCursor(), another.getEsriGeometryCursor());
	com.esri.core.geometry.GeometryCursor cursor = op.execute(ap,
			getEsriSpatialReference(), null);
	return OGCGeometry.createFromEsriCursor(cursor, esriSR);
}
 
Example #2
Source File: ST_Aggr_Union.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 (xgc == null) {
				firstWKID = GeometryUtils.getWKID(geomref);
				if (firstWKID != GeometryUtils.WKID_UNKNOWN) {
					spatialRef = SpatialReference.create(firstWKID);
				}
				// Need new geometry cursors both initially and after every terminatePartial(),
				// because the geometry cursors can not be re-used after extracting the
				// unioned geometry with GeometryCursor.next().
				//Create an empty listener.
				lgc = new ListeningGeometryCursor();
				//Obtain union operator - after taking note of spatial reference.
				xgc = OperatorUnion.local().execute(lgc, spatialRef, null);
			} else if (firstWKID != GeometryUtils.getWKID(geomref)) {
				LogUtils.Log_SRIDMismatch(LOG, geomref, firstWKID);
				return false;
			}

			try {
				lgc.tick(GeometryUtils.geometryFromEsriShape(geomref).getEsriGeometry());   // push
				xgc.tock();   // tock to match tick
				return true;
			} catch (Exception e) {
				LogUtils.Log_InternalError(LOG, "ST_Aggr_Union: " + e);
				return false;
			}

		}
 
Example #3
Source File: GeoFunctions.java    From presto with Apache License 2.0 4 votes vote down vote up
private static Slice stUnion(Iterable<Slice> slices)
{
    // The current state of Esri/geometry-api-java does not allow support for multiple dimensions being
    // fed to the union operator without dropping the lower dimensions:
    // https://github.com/Esri/geometry-api-java/issues/199
    // When operating over a collection of geometries, it is more efficient to reuse the same operator
    // for the entire operation.  Therefore, split the inputs and operators by dimension, and then union
    // each dimension's result at the end.
    ListeningGeometryCursor[] cursorsByDimension = new ListeningGeometryCursor[NUMBER_OF_DIMENSIONS];
    GeometryCursor[] operatorsByDimension = new GeometryCursor[NUMBER_OF_DIMENSIONS];

    setAll(cursorsByDimension, i -> new ListeningGeometryCursor());
    setAll(operatorsByDimension, i -> OperatorUnion.local().execute(cursorsByDimension[i], null, null));

    Iterator<Slice> slicesIterator = slices.iterator();
    if (!slicesIterator.hasNext()) {
        return null;
    }
    while (slicesIterator.hasNext()) {
        Slice slice = slicesIterator.next();
        // Ignore null inputs
        if (slice.getInput().available() == 0) {
            continue;
        }

        for (OGCGeometry geometry : flattenCollection(deserialize(slice))) {
            int dimension = geometry.dimension();
            cursorsByDimension[dimension].tick(geometry.getEsriGeometry());
            operatorsByDimension[dimension].tock();
        }
    }

    List<OGCGeometry> outputs = new ArrayList<>();
    for (GeometryCursor operator : operatorsByDimension) {
        OGCGeometry unionedGeometry = createFromEsriGeometry(operator.next(), null);
        if (unionedGeometry != null) {
            outputs.add(unionedGeometry);
        }
    }

    if (outputs.size() == 1) {
        return serialize(outputs.get(0));
    }
    return serialize(new OGCConcreteGeometryCollection(outputs, null).flattenAndRemoveOverlaps().reduceFromMulti());
}