private EXGeographicBoundingBox getGeographicBoundingBox(Envelope env, String epsgCode) {
   Envelope newEnvelope;
   if ("EPSG:4326".equals(epsgCode)) {
     newEnvelope = env;
   } else {
     try {
       GeometryFactory gf = new GeometryFactory();
       Polygon poly = (Polygon) gf.toGeometry(env);
       ST_Transform transformFunction = new ST_Transform();
       CoordinateReferenceSystem inputCRS = DataSourceFactory.getCRSFactory().getCRS(epsgCode);
       Value val =
           transformFunction.evaluate(
               null,
               ValueFactory.createValue(poly, inputCRS),
               ValueFactory.createValue("EPSG:4326"));
       newEnvelope = val.getAsGeometry().getEnvelopeInternal();
     } catch (FunctionException fe) {
       return getDummyGeographic();
     } catch (CRSException ex) {
       return getDummyGeographic();
     }
   }
   EXGeographicBoundingBox ret = new EXGeographicBoundingBox();
   ret.setEastBoundLongitude(newEnvelope.getMaxX());
   ret.setWestBoundLongitude(newEnvelope.getMinX());
   ret.setNorthBoundLatitude(newEnvelope.getMaxY());
   ret.setSouthBoundLatitude(newEnvelope.getMinY());
   return ret;
 }
Beispiel #2
0
  private void addMetacardLocation(
      final XstreamPathValueTracker pathValueTracker, MetacardImpl metacard) {
    String westLon = pathValueTracker.getPathValue(BBOX_WEST_LON_PATH);
    String eastLon = pathValueTracker.getPathValue(BBOX_EAST_LON_PATH);
    String southLat = pathValueTracker.getPathValue(BBOX_SOUTH_LAT_PATH);
    String northLat = pathValueTracker.getPathValue(BBOX_NORTH_LAT_PATH);

    if (westLon != null && eastLon != null && southLat != null && northLat != null) {
      WKTWriter wktWriter = new WKTWriter();

      GeometryFactory factory = new GeometryFactory();
      try {
        Envelope envelope =
            new Envelope(
                Double.parseDouble(eastLon.trim()),
                Double.parseDouble(westLon.trim()),
                Double.parseDouble(southLat.trim()),
                Double.parseDouble(northLat.trim()));
        String wkt = wktWriter.write(factory.toGeometry(envelope));
        if (wkt != null) {
          metacard.setLocation(wkt);
        }
      } catch (NumberFormatException nfe) {
        LOGGER.info(
            "Unable to parse double from GMD metadata {}, {}, {}, {}",
            westLon,
            eastLon,
            southLat,
            northLat);
      }
    }
  }
Beispiel #3
0
  public static GeometryCollection createBoxesGeometry(List<Node> leafs, Envelope bound) {
    GeometryFactory factory = new GeometryFactory();

    Geometry[] boxes = new Geometry[leafs.size()];
    for (int i = 0; i < leafs.size(); i++) {
      Node leaf = leafs.get(i);
      Envelope envelope = leaf.getEnvelope().intersection(bound);
      Geometry g = factory.toGeometry(envelope);
      boxes[i] = g;
    }

    return factory.createGeometryCollection(boxes);
  }
 @Test
 public void testGeoShapeEnvelope() throws JsonParseException, JsonMappingException, IOException {
   Envelope envelope = rgb.createRandomEnvelope();
   Geometry expected = geometryFactory.toGeometry(envelope);
   assertTrue(parserUtil.createGeometry(rgb.toMap(envelope)).equalsExact(expected, 1e-9));
 }
 static {
   GeometryFactory fac = new GeometryFactory();
   WORLD_BOUNDS = fac.toGeometry(new Envelope(-180, 180, -90, 90));
 }