public class HibernateGeometryCreator {

  private int storageEPSG = GeometryHandler.getInstance().getStorageEPSG();
  private int storage3depsg = GeometryHandler.getInstance().getStorage3DEPSG();

  public HibernateGeometryCreator() {}

  public HibernateGeometryCreator(int storageEPSG, int storage3DEPSG) {
    this.storageEPSG = storageEPSG;
    this.storage3depsg = storage3DEPSG;
  }

  private int getStorageEPSG() {
    return storageEPSG;
  }

  private int getStorage3DEPSG() {
    return storage3depsg;
  }

  /**
   * Get the geometry from featureOfInterest object.
   *
   * @param feature
   * @return geometry
   * @throws OwsExceptionReport
   */
  public Geometry createGeometry(final HasCoordinate coodinates) throws OwsExceptionReport {
    if (coodinates.isSetLongLat()) {
      int epsg = getStorageEPSG();
      if (coodinates.isSetSrid()) {
        epsg = coodinates.getSrid();
      }
      final String wktString =
          GeometryHandler.getInstance()
              .getWktString(coodinates.getLongitude(), coodinates.getLatitude(), epsg);
      final Geometry geom = JTSHelper.createGeometryFromWKT(wktString, epsg);
      if (coodinates.isSetAltitude()) {
        geom.getCoordinate().z = JavaHelper.asDouble(coodinates.getAltitude());
        if (geom.getSRID() == getStorage3DEPSG()) {
          geom.setSRID(getStorage3DEPSG());
        }
      }
      return geom;
    }
    return null;
  }
}
示例#2
0
 /** @return Returns a singleton instance of the GeometryHandler. */
 public static GeometryHandler getInstance() {
   if (instance == null) {
     creationLock.lock();
     try {
       if (instance == null) {
         // don't set instance before configuring, or other threads
         // can get access to unconfigured instance!
         final GeometryHandler newInstance = new GeometryHandler();
         SettingsManager.getInstance().configure(newInstance);
         newInstance.initCrsAuthoritycrsAuthority();
         instance = newInstance;
       }
     } finally {
       creationLock.unlock();
     }
   }
   return instance;
 }
 /**
  * Get the geometry from featureOfInterest object.
  *
  * @param feature
  * @return geometry
  * @throws OwsExceptionReport
  */
 public Geometry createGeometry(final HasCoordinate coodinates) throws OwsExceptionReport {
   if (coodinates.isSetLongLat()) {
     int epsg = getStorageEPSG();
     if (coodinates.isSetSrid()) {
       epsg = coodinates.getSrid();
     }
     final String wktString =
         GeometryHandler.getInstance()
             .getWktString(coodinates.getLongitude(), coodinates.getLatitude(), epsg);
     final Geometry geom = JTSHelper.createGeometryFromWKT(wktString, epsg);
     if (coodinates.isSetAltitude()) {
       geom.getCoordinate().z = JavaHelper.asDouble(coodinates.getAltitude());
       if (geom.getSRID() == getStorage3DEPSG()) {
         geom.setSRID(getStorage3DEPSG());
       }
     }
     return geom;
   }
   return null;
 }