public static OGCGeometry geometryFromEsriShape(BytesWritable geomref, boolean bytesRecycled) {

    if (geomref == null) {
      return null;
    }

    // this geomref might actually be a LazyGeometryBytesWritable which
    // means we don't need to deserialize from bytes
    if (geomref instanceof CachedGeometryBytesWritable) {
      return ((CachedGeometryBytesWritable) geomref).getGeometry();
    }

    // if geomref bytes are recycled, we can't use the cache because every
    // key in the cache will be the same byte array
    if (!bytesRecycled) {
      // check for a cache hit to previously created geometries
      OGCGeometry cachedGeom = geometryCache.getIfPresent(geomref);

      if (cachedGeom != null) {
        return cachedGeom;
      }
    }

    // not in cache or instance of CachedGeometryBytesWritable. now
    // need to create the geometry from its bytes
    int wkid = getWKID(geomref);
    ByteBuffer shapeBuffer = getShapeByteBuffer(geomref);

    //minimum for a shape, even an empty one, is the 4 byte type record
    if (shapeBuffer.limit() < 4) {
      return null;
    } else {
      if (shapeBuffer.getInt(0) == Geometry.Type.Unknown.value()) { //empty Geometry, intentional
        return null;
      } else {
        SpatialReference spatialReference = null;
        if (wkid != GeometryUtils.WKID_UNKNOWN) {
          spatialReference = SpatialReference.create(wkid);
        }

        Geometry esriGeom = OperatorImportFromESRIShape.local().execute(0, Geometry.Type.Unknown, shapeBuffer);
        OGCGeometry createdGeom = OGCGeometry.createFromEsriGeometry(esriGeom, spatialReference);

        if (!bytesRecycled) {
          // only add bytes to cache if we know they aren't being recycled
          geometryCache.put(geomref, createdGeom);
        }

        return createdGeom;
      }
    }
  }
@param geomref1
@param geomref2
@return return true if both geometries are in the same spatial reference
ql/src/java/org/apache/hadoop/hive/ql/udf/esri/GeometryUtils.java