private static BytesWritable serialize(Geometry geometry, int wkid, OGCType type) {
    if (geometry == null) {
      return null;
    }

    // first get shape buffer for geometry
    byte[] shape = GeometryEngine.geometryToEsriShape(geometry);

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

    byte[] shapeWithData = new byte[shape.length + SIZE_WKID + SIZE_TYPE];

    System.arraycopy(shape, 0, shapeWithData, SIZE_WKID + SIZE_TYPE, shape.length);

    BytesWritable hiveGeometryBytes = new BytesWritable(shapeWithData);

    setWKID(hiveGeometryBytes, wkid);
    setType(hiveGeometryBytes, type);

    BytesWritable ret = new BytesWritable(shapeWithData);

    return ret;
  }
Sets the WKID (in place) for the given hive geometry bytes

@param geomref reference to hive geometry bytes
@param wkid
ql/src/java/org/apache/hadoop/hive/ql/udf/esri/GeometryUtils.java