Esri / spatial-framework-for-hadoop

The Spatial Framework for Hadoop allows developers and data scientists to use the Hadoop data processing system for spatial data analysis.
Apache License 2.0
363 stars 160 forks source link

ST_GeometryFromShape #103

Closed randallwhitman closed 7 years ago

randallwhitman commented 7 years ago

ST_GeomFromShape in SQL-RDBMS ST_AsShape for Hive

randallwhitman commented 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;
        }
    }

}
randallwhitman commented 7 years ago

Need to add to the documentation on wiki

randallwhitman commented 7 years ago

https://github.com/Esri/spatial-framework-for-hadoop/wiki/UDF-Constructors#st_geomfromshape