// Path: hive/src/main/java/com/esri/hadoop/hive/GeometryUtils.java
// public enum OGCType {
// 	UNKNOWN(0),
// 	ST_POINT(1),
// 	ST_LINESTRING(2),
// 	ST_POLYGON(3),
// 	ST_MULTIPOINT(4),
// 	ST_MULTILINESTRING(5),
// 	ST_MULTIPOLYGON(6);
// 		
// 	private final int index;
// 		
// 	OGCType(int index){
// 		this.index = index;
// 	}
// 		
// 	public int getIndex(){
// 		return this.index;
// 	}
// }


import org.apache.commons.logging.Log;
import org.apache.commons.logging.LogFactory;
import org.apache.hadoop.hive.ql.exec.Description;
import org.apache.hadoop.io.BytesWritable;
import com.esri.core.geometry.Geometry;
import com.esri.core.geometry.GeometryEngine;
import com.esri.core.geometry.SpatialReference;
import com.esri.hadoop.hive.GeometryUtils.OGCType;
import com.esri.core.geometry.ogc.OGCGeometry;
			} 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
// Path: hive/src/main/java/com/esri/hadoop/hive/GeometryUtils.java
// public enum OGCType {
// 	UNKNOWN(0),
// 	ST_POINT(1),
// 	ST_LINESTRING(2),
// 	ST_POLYGON(3),
// 	ST_MULTIPOINT(4),
// 	ST_MULTILINESTRING(5),
// 	ST_MULTIPOLYGON(6);
// 		
// 	private final int index;
// 		
// 	OGCType(int index){
// 		this.index = index;
// 	}
// 		
// 	public int getIndex(){
// 		return this.index;
// 	}
// }


// Path: hive/src/main/java/com/esri/hadoop/hive/ST_Union.java
import org.apache.commons.logging.Log;
import org.apache.commons.logging.LogFactory;
import org.apache.hadoop.hive.ql.exec.Description;
import org.apache.hadoop.io.BytesWritable;
import com.esri.core.geometry.Geometry;
import com.esri.core.geometry.GeometryEngine;
import com.esri.core.geometry.SpatialReference;
import com.esri.hadoop.hive.GeometryUtils.OGCType;
import com.esri.core.geometry.ogc.OGCGeometry;

			} 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);