コード例 #1
0
  @Override
  public GeoCouchFeatureStore create(URL configURL) throws ResourceInitException {

    GeoCouchFeatureStore fs = null;
    try {
      GeoCouchFeatureStoreConfig config =
          (GeoCouchFeatureStoreConfig)
              JAXBUtils.unmarshall(CONFIG_JAXB_PACKAGE, CONFIG_SCHEMA, configURL, workspace);

      XMLAdapter resolver = new XMLAdapter();
      resolver.setSystemId(configURL.toString());

      String srs = config.getStorageCRS();
      srs = srs.trim();
      ICRS crs = CRSManager.getCRSRef(srs);

      String couchUrl = config.getGeoCouchUrl();
      if (!couchUrl.endsWith("/")) {
        couchUrl += "/";
      }

      List<String> configSchemas = config.getGMLSchema();
      String[] schemas = new String[configSchemas.size()];
      int i = -1;
      for (String s : configSchemas) {
        schemas[++i] = resolver.resolve(s).toString();
      }

      GMLAppSchemaReader decoder = new GMLAppSchemaReader(null, null, schemas);
      AppSchema schema = decoder.extractAppSchema();

      fs = new GeoCouchFeatureStore(crs, schema, couchUrl);

    } catch (Throwable e) {

      String msg =
          "Error in feature store configuration file '" + configURL + "': " + e.getMessage();
      LOG.error(msg);
      throw new ResourceInitException(msg, e);
    }
    return fs;
  }
コード例 #2
0
  /**
   * @param crs
   * @param bbox
   * @return a new CRS
   */
  public static Envelope getCRSAndEnvelope(String crs, double[] bbox) {
    if (crs.startsWith("AUTO2:")) {
      String[] cs = crs.split(":")[1].split(",");
      int id = Integer.parseInt(cs[0]);
      // this is not supported
      double factor = Double.parseDouble(cs[1]);
      double lon0 = Double.parseDouble(cs[2]);
      double lat0 = Double.parseDouble(cs[3]);

      return new GeometryFactory()
          .createEnvelope(
              factor * bbox[0],
              factor * bbox[1],
              factor * bbox[2],
              factor * bbox[3],
              Utils.getAutoCRS(id, lon0, lat0));
    }
    return new GeometryFactory()
        .createEnvelope(bbox[0], bbox[1], bbox[2], bbox[3], CRSManager.getCRSRef(crs));
  }
コード例 #3
0
 /**
  * @param crs
  * @return a new CRS
  */
 public static ICRS getCRS(String crs) {
   return CRSManager.getCRSRef(crs);
 }
コード例 #4
0
  @Override
  public FeatureStore build() {
    MemoryFeatureStore fs;
    ICRS storageCRS = null;
    AppSchema schema = null;
    try {
      String[] schemaURLs = new String[config.getGMLSchema().size()];
      int i = 0;
      GMLVersionType gmlVersionType = null;
      for (GMLSchema jaxbSchemaURL : config.getGMLSchema()) {
        schemaURLs[i++] =
            metadata
                .getLocation()
                .resolveToFile(jaxbSchemaURL.getValue().trim())
                .toURI()
                .toURL()
                .toString();
        // TODO what about different versions at the same time?
        gmlVersionType = jaxbSchemaURL.getVersion();
      }

      GMLAppSchemaReader decoder = null;
      if (schemaURLs.length == 1 && schemaURLs[0].startsWith("file:")) {
        File file = new File(new URL(schemaURLs[0]).toURI());
        decoder =
            new GMLAppSchemaReader(
                GMLVersion.valueOf(gmlVersionType.name()),
                getHintMap(config.getNamespaceHint()),
                file);
      } else {
        decoder =
            new GMLAppSchemaReader(
                GMLVersion.valueOf(gmlVersionType.name()),
                getHintMap(config.getNamespaceHint()),
                schemaURLs);
      }
      schema = decoder.extractAppSchema();
      if (config.getStorageCRS() != null) {
        storageCRS = CRSManager.lookup(config.getStorageCRS());
      }
    } catch (Exception e) {
      String msg = Messages.getMessage("STORE_MANAGER_STORE_SETUP_ERROR", e.getMessage());
      LOG.error(msg, e);
      throw new ResourceInitException(msg, e);
    }

    try {
      ConnectionProvider lockProvider =
          workspace.getResource(ConnectionProviderProvider.class, "LOCK_DB");
      fs = new MemoryFeatureStore(schema, storageCRS, metadata, lockProvider);
    } catch (FeatureStoreException ex) {
      throw new ResourceInitException(ex.getLocalizedMessage(), ex);
    }
    for (GMLFeatureCollection datasetFile : config.getGMLFeatureCollection()) {
      if (datasetFile != null) {
        try {
          GMLVersion version = GMLVersion.valueOf(datasetFile.getVersion().name());
          URL docURL =
              metadata.getLocation().resolveToFile(datasetFile.getValue().trim()).toURI().toURL();
          GMLStreamReader gmlStream = GMLInputFactory.createGMLStreamReader(version, docURL);
          gmlStream.setApplicationSchema(schema);
          LOG.info("Populating feature store with features from file '" + docURL + "'...");
          FeatureCollection fc = (FeatureCollection) gmlStream.readFeature();
          gmlStream.getIdContext().resolveLocalRefs();

          FeatureStoreTransaction ta = fs.acquireTransaction();
          int fids = ta.performInsert(fc, USE_EXISTING).size();
          LOG.info("Inserted " + fids + " features.");
          ta.commit();
        } catch (Exception e) {
          String msg = Messages.getMessage("STORE_MANAGER_STORE_SETUP_ERROR", e.getMessage());
          LOG.error(msg);
          LOG.trace("Stack trace:", e);
          throw new ResourceInitException(msg, e);
        }
      }
    }
    return fs;
  }
コード例 #5
0
  @SuppressWarnings("boxing")
  private static GetFeature parse110(Map<String, String> kvpParams) throws Exception {

    StandardPresentationParams presentationParams =
        parseStandardPresentationParameters110(kvpParams);
    ResolveParams resolveParams = parseStandardResolveParameters110(kvpParams);

    // optional: 'NAMESPACE'
    Map<String, String> nsBindings = extractNamespaceBindings110(kvpParams);
    if (nsBindings == null) {
      nsBindings = Collections.emptyMap();
    }

    NamespaceBindings nsContext = new NamespaceBindings();
    if (nsBindings != null) {
      for (String key : nsBindings.keySet()) {
        nsContext.addNamespace(key, nsBindings.get(key));
      }
    }

    // optional: SRSNAME
    String srsName = kvpParams.get("SRSNAME");
    ICRS srs = null;
    if (srsName != null) {
      srs = CRSManager.getCRSRef(srsName);
    }

    // optional: 'PROPERTYNAME'
    String propertyStr = kvpParams.get("PROPERTYNAME");
    PropertyName[][] propertyNames = getPropertyNames(propertyStr, nsContext);

    // optional: SORTBY
    String sortbyStr = kvpParams.get("SORTBY");
    SortProperty[] sortBy = getSortBy(sortbyStr, nsContext);

    // optional: FEATUREVERSION
    String featureVersion = kvpParams.get("FEATUREVERSION");

    // mandatory: TYPENAME, but optional if FEATUREID is specified
    String typeStrList = kvpParams.get("TYPENAME");
    TypeName[] typeNames = getTypeNames(typeStrList, nsBindings);

    // optional: FEATUREID
    String featureIdStr = kvpParams.get("FEATUREID");
    String[] featureIds = null;
    if (featureIdStr != null) {
      featureIds = featureIdStr.split(",");
    }
    // optional: BBOX
    String bboxStr = kvpParams.get("BBOX");

    // optional: FILTER
    String filterStr = kvpParams.get("FILTER");

    // optional: 'PROPTRAVXLINKDEPTH'
    String propTravXlinkDepth = kvpParams.get("PROPTRAVXLINKDEPTH");
    String[][] ptxDepthAr = null;
    if (propTravXlinkDepth != null) {
      ptxDepthAr = parseParamList(propTravXlinkDepth);
    }

    // optional: 'PROPTRAVXLINKEXPIRY'
    String propTravXlinkExpiry = kvpParams.get("PROPTRAVXLINKEXPIRY");
    Integer[][] ptxExpAr = null;
    if (propTravXlinkExpiry != null) {
      ptxExpAr = parseParamListAsInts(propTravXlinkDepth);
    }

    propertyNames = getXLinkPropNames(propertyNames, ptxDepthAr, ptxExpAr);
    List<Query> queries = new ArrayList<Query>();

    if ((featureIdStr != null && bboxStr != null)
        || (featureIdStr != null && filterStr != null)
        || (bboxStr != null && filterStr != null)) {
      // TODO make new exception
      throw new Exception("The FEATUREID, BBOX and FILTER keywords are mutually exclusive!");
    }

    if (featureIdStr != null) {
      if (typeStrList == null && propertyNames == null) {
        queries.add(new FeatureIdQuery(null, null, featureVersion, srs, null, sortBy, featureIds));
      } else {
        for (int i = 0; i < featureIds.length; i++) {
          String[] fid = new String[] {featureIds[i]};
          TypeName[] typeName = new TypeName[0];
          if (typeStrList != null) {
            typeName = new TypeName[] {typeNames[i]};
          }
          PropertyName[] projectionClauses = null;
          if (propertyNames != null) {
            projectionClauses = propertyNames[i];
          }
          queries.add(
              new FeatureIdQuery(
                  null, typeName, featureVersion, srs, projectionClauses, sortBy, fid));
        }
      }
    } else if (bboxStr != null) {
      if (typeNames == null) {
        // TODO make new exception
        throw new Exception("The TYPENAME keyword is mandatory if BBOX is present!");
      }

      String[] coordList = bboxStr.split(",");

      // NOTE: Contradiction between spec and CITE tests (for omitted crsUri)
      // - WFS 1.1.0 spec, 14.3.3: coordinates should be in WGS84
      // - CITE tests, wfs:wfs-1.1.0-Basic-GetFeature-tc8.1: If no CRS reference is provided, a
      // service-defined
      // default value must be assumed.
      ICRS bboxCrs = null;
      if (coordList.length % 2 == 1) {
        bboxCrs = CRSManager.getCRSRef(coordList[coordList.length - 1]);
      }

      Envelope bbox = createEnvelope(bboxStr, bboxCrs);
      for (int i = 0; i < typeNames.length; i++) {
        TypeName typeName = typeNames[i];
        PropertyName[] projectionClauses = null;
        if (propertyNames != null) {
          projectionClauses = propertyNames[i];
        }
        queries.add(
            new BBoxQuery(
                null,
                new TypeName[] {typeName},
                featureVersion,
                srs,
                projectionClauses,
                sortBy,
                bbox));
      }
    } else if (filterStr != null || typeNames != null) {
      if (typeNames == null) {
        // TODO make new exception
        throw new Exception("The FILTER element requires the TYPENAME element");
      }

      int length = typeNames.length;

      String[] filters = getFilters(filterStr);

      for (int i = 0; i < length; i++) {
        Filter filter = null;
        if (filters != null) {

          StringReader sr = new StringReader(filters[i]);
          XMLAdapter adapter = new XMLAdapter(sr);
          XMLStreamReaderWrapper streamWrapper =
              new XMLStreamReaderWrapper(
                  adapter.getRootElement().getXMLStreamReaderWithoutCaching(),
                  adapter.getSystemId());
          try {
            streamWrapper.nextTag();
            filter = Filter110XMLDecoder.parse(streamWrapper);
          } catch (XMLParsingException e) {
            e.printStackTrace();
            // TODO raise exception
          } catch (XMLStreamException e) {
            e.printStackTrace();
            // TODO raise exception
          }
        }
        if (propertyNames != null) {
          queries.add(
              new FilterQuery(
                  null,
                  new TypeName[] {typeNames[i]},
                  featureVersion,
                  srs,
                  propertyNames[i],
                  sortBy,
                  filter));
        } else {
          queries.add(
              new FilterQuery(
                  null, new TypeName[] {typeNames[i]}, featureVersion, srs, null, sortBy, filter));
        }
      }
    }
    return new GetFeature(VERSION_110, null, presentationParams, resolveParams, queries);
  }
コード例 #6
0
  @SuppressWarnings("boxing")
  private static GetFeature parse100(Map<String, String> kvpParams, Map<String, String> nsMap)
      throws Exception {

    NamespaceBindings nsContext = new NamespaceBindings();
    if (nsMap != null) {
      for (String key : nsMap.keySet()) {
        nsContext.addNamespace(key, nsMap.get(key));
      }
    }

    StandardPresentationParams presentationParams =
        parseStandardPresentationParameters100(kvpParams);

    // optional: 'PROPERTYNAME'
    String propertyStr = kvpParams.get("PROPERTYNAME");
    PropertyName[][] propertyNames = getPropertyNames(propertyStr, nsContext);

    // optional: FEATUREVERSION
    String featureVersion = kvpParams.get("FEATUREVERSION");

    // mandatory: TYPENAME, but optional if FEATUREID is specified
    String typeStrList = kvpParams.get("TYPENAME");
    TypeName[] typeNames = getTypeNames100(typeStrList);

    // optional: FEATUREID
    String featureIdStr = kvpParams.get("FEATUREID");
    String[] featureIds = null;
    if (featureIdStr != null) {
      featureIds = featureIdStr.split(",");
    }
    // optional: BBOX
    String bboxStr = kvpParams.get("BBOX");

    // optional: FILTER
    String filterStr = kvpParams.get("FILTER");

    // optional: SRSNAME (not specified in WFS 1.0.0, deegree extension)
    String srsName = kvpParams.get("SRSNAME");
    ICRS srs = null;
    if (srsName != null) {
      srs = CRSManager.getCRSRef(srsName);
    }

    List<Query> queries = new ArrayList<Query>();

    if ((featureIdStr != null && bboxStr != null)
        || (featureIdStr != null && filterStr != null)
        || (bboxStr != null && filterStr != null)) {
      // TODO make new exception
      throw new Exception("The FEATUREID, BBOX and FILTER keywords are mutually exclusive!");
    }

    if (featureIdStr != null) {
      if (typeStrList == null && propertyNames == null) {
        queries.add(new FeatureIdQuery(null, null, featureVersion, srs, null, null, featureIds));
      } else {
        for (int i = 0; i < featureIds.length; i++) {
          String[] fids = new String[] {featureIds[i]};
          TypeName[] typeName = new TypeName[0];
          if (typeStrList != null) {
            typeName = new TypeName[] {typeNames[i]};
          }
          PropertyName[] projectionClauses = null;
          if (propertyNames != null) {
            if (propertyNames.length > 1) {
              projectionClauses = propertyNames[i];
            } else {
              projectionClauses = propertyNames[0];
            }
          }
          queries.add(
              new FeatureIdQuery(
                  null, typeName, featureVersion, srs, projectionClauses, null, fids));
        }
      }
    } else if (bboxStr != null) {
      if (typeNames == null) {
        // TODO make new exception
        throw new Exception("The TYPENAME keyword is mandatory if BBOX is present!");
      }

      String[] coordList = bboxStr.split(",");
      ICRS bboxCrs = null;
      if (coordList.length % 2 == 1) {
        bboxCrs = CRSManager.getCRSRef(coordList[coordList.length - 1]);
      }

      Envelope bbox = createEnvelope(bboxStr, bboxCrs);
      for (int i = 0; i < typeNames.length; i++) {
        TypeName typeName = typeNames[i];
        PropertyName[] projectionClauses = null;
        if (propertyNames != null) {
          projectionClauses = propertyNames[i];
        }
        queries.add(
            new BBoxQuery(
                null,
                new TypeName[] {typeName},
                featureVersion,
                srs,
                projectionClauses,
                null,
                bbox));
      }
    } else if (filterStr != null || typeNames != null) {
      if (typeNames == null) {
        // TODO make new exception
        throw new Exception("The FILTER element requires the TYPENAME element");
      }

      int length = typeNames.length;

      String[] filters = getFilters(filterStr);

      for (int i = 0; i < length; i++) {
        Filter filter = null;
        if (filters != null) {

          StringReader sr = new StringReader(filters[i]);
          XMLAdapter adapter = new XMLAdapter(sr);
          XMLStreamReaderWrapper streamWrapper =
              new XMLStreamReaderWrapper(
                  adapter.getRootElement().getXMLStreamReaderWithoutCaching(),
                  adapter.getSystemId());
          try {
            streamWrapper.nextTag();
            filter = Filter100XMLDecoder.parse(streamWrapper);
          } catch (XMLParsingException e) {
            e.printStackTrace();
            // TODO raise exception
          } catch (XMLStreamException e) {
            e.printStackTrace();
            // TODO raise exception
          }
        }
        if (propertyNames != null) {
          queries.add(
              new FilterQuery(
                  null,
                  new TypeName[] {typeNames[i]},
                  featureVersion,
                  srs,
                  propertyNames[i],
                  null,
                  filter));
        } else {
          queries.add(
              new FilterQuery(
                  null, new TypeName[] {typeNames[i]}, featureVersion, srs, null, null, filter));
        }
      }
    }
    return new GetFeature(VERSION_100, null, presentationParams, null, queries);
  }