Closed randallwhitman closed 7 years ago
I found the following untracked file, never committed to git - probably did not pass testing:
package com.esri.hadoop.hive;
import java.nio.ByteBuffer;
import org.apache.commons.logging.Log;
import org.apache.commons.logging.LogFactory;
import org.apache.hadoop.hive.ql.exec.UDFArgumentException;
import org.apache.hadoop.io.BytesWritable;
import com.esri.core.geometry.SpatialReference;
import com.esri.core.geometry.ogc.OGCGeometry;
public class ST_GeomFromShape extends ST_Geometry {
static final Log LOG = LogFactory.getLog(ST_GeomFromShape.class.getName());
public BytesWritable evaluate(BytesWritable shape) throws UDFArgumentException {
return evaluate(shape, 0);
}
public BytesWritable evaluate(BytesWritable shape, int wkid) throws UDFArgumentException {
//String wkt = shape.toString();
LOG.error("geom-from-shape"); /// debug/todo
try {
SpatialReference spatialReference = null;
if (wkid != GeometryUtils.WKID_UNKNOWN) {
spatialReference = SpatialReference.create(wkid);
}
// byte [] byteArr = shape.getBytes();
// ByteBuffer byteBuf = ByteBuffer.allocate(byteArr.length);
// byteBuf.put(byteArr);
// TODO: little-endian order: .order(ByteOrder.LITTLE_ENDIAN)
OGCGeometry ogcObj = OGCGeometry.fromEsriShape(ByteBuffer.wrap(shape.getBytes()));
ogcObj.setSpatialReference(spatialReference);
return GeometryUtils.geometryToEsriShapeBytesWritable(ogcObj);
} catch (Exception e) {
LogUtils.Log_ExceptionThrown(LOG, "geom-from-shape", e); //todo
return null;
}
}
}
Need to add to the documentation on wiki
ST_GeomFromShape in SQL-RDBMS ST_AsShape for Hive