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;
 }
  private void testIndexRealData(String source, double checkPeriod, DiskRTree tree)
      throws NoSuchTableException, DataSourceCreationException, DriverException, IOException,
          Exception {
    DataSource ds = dsf.getDataSource(source);
    String fieldName = "the_geom";

    ds.open();
    int fieldIndex = ds.getFieldIndexByName(fieldName);
    for (int i = 0; i < ds.getRowCount(); i++) {
      if (i / (int) checkPeriod == i / checkPeriod) {
        tree.checkTree();
        tree.close();
        tree.openIndex(indexFile);
        tree.checkTree();
        checkLookUp(tree, ds, fieldIndex);
      }
      Envelope value = ds.getFieldValue(i, fieldIndex).getAsGeometry().getEnvelopeInternal();
      tree.insert(value, i);
    }
    for (int i = 0; i < ds.getRowCount(); i++) {
      if (i / (int) checkPeriod == i / checkPeriod) {
        tree.checkTree();
        tree.save();
        tree.checkTree();
        checkLookUp(tree, ds, fieldIndex);
      }
      Value value = ds.getFieldValue(i, fieldIndex);
      tree.delete(value.getAsGeometry().getEnvelopeInternal(), i);
    }

    ds.close();
  }
示例#3
0
  @Override
  public Number[] getScope(int dimension) throws DriverException {
    if (cachedScope == null) {
      boolean open = isOpen();
      if (!open) {
        open();
      }
      for (int i = 0; i < getRowCount(); i++) {
        Metadata m = getMetadata();
        for (int j = 0; j < m.getFieldCount(); j++) {
          int typeCode = m.getFieldType(j).getTypeCode();
          Envelope r = null;
          if ((typeCode & Type.GEOMETRY) != 0) {
            Value v = getFieldValue(i, j);
            if ((v != null) && (!v.isNull())) {
              r = v.getAsGeometry().getEnvelopeInternal();
            }
          } else if (typeCode == Type.RASTER) {
            Value v = getFieldValue(i, j);
            if ((v != null) && (!v.isNull())) {
              r = v.getAsRaster().getMetadata().getEnvelope();
            }
          } else if (typeCode == Type.STREAM) {
            Value v = getFieldValue(i, j);
            if ((v != null) && (!v.isNull())) {
              r = v.getAsStream().getEnvelope();
            }
          }
          if (r != null) {
            if (cachedScope == null) {
              cachedScope = new Envelope(r);
            } else {
              cachedScope.expandToInclude(r);
            }
          }
        }
      }
      if (!open) {
        close();
      }
    }

    if (cachedScope == null) {
      return new Number[] {0, 0};
    } else {
      if (dimension == DataSet.X) {
        return new Number[] {cachedScope.getMinX(), cachedScope.getMaxX()};
      } else if (dimension == DataSet.Y) {
        return new Number[] {cachedScope.getMinY(), cachedScope.getMaxY()};
      } else {
        throw new UnsupportedOperationException("Not yet implemented");
      }
    }
  }