Exemplo n.º 1
0
  private NodeRef findOrCreateTree(final String treePath, final FeatureType type) {

    RevTree tree =
        context
            .command(FindOrCreateSubtree.class)
            .setChildPath(treePath)
            .setIndex(true)
            .setParent(workHead)
            .setParentPath(NodeRef.ROOT)
            .call();

    ObjectId metadataId = ObjectId.NULL;
    if (type != null) {
      RevFeatureType revFeatureType = RevFeatureTypeImpl.build(type);
      if (tree.isEmpty()) {
        indexDatabase.put(revFeatureType);
      }
      metadataId = revFeatureType.getId();
    }
    Envelope bounds = SpatialOps.boundsOf(tree);
    Node node =
        Node.create(NodeRef.nodeFromPath(treePath), tree.getId(), metadataId, TYPE.TREE, bounds);

    String parentPath = NodeRef.parentPath(treePath);
    return new NodeRef(node, parentPath, ObjectId.NULL);
  }
Exemplo n.º 2
0
  private RevTreeBuilder2 createBuilder(String treePath, FeatureType type) {

    final NodeRef treeRef = findOrCreateTree(treePath, type);
    final ObjectId treeId = treeRef.objectId();
    final RevTree origTree = indexDatabase.getTree(treeId);

    ObjectId defaultMetadataId = treeRef.getMetadataId();

    RevTreeBuilder2 builder;
    Platform platform = context.platform();
    builder =
        new RevTreeBuilder2(indexDatabase, origTree, defaultMetadataId, platform, executorService);
    return builder;
  }
 private ReferencedEnvelope createProjectedFilter(ObjectId metadataId) {
   final ReferencedEnvelope boundsFilter = this.boundsFilter;
   RevFeatureType featureType = ftypeSource.getFeatureType(metadataId);
   CoordinateReferenceSystem nativeCrs = featureType.type().getCoordinateReferenceSystem();
   if (null == nativeCrs || nativeCrs instanceof DefaultEngineeringCRS) {
     return boundsFilter;
   }
   ReferencedEnvelope transformedFilter;
   try {
     transformedFilter = boundsFilter.transform(nativeCrs, true);
   } catch (TransformException | FactoryException e) {
     throw Throwables.propagate(e);
   }
   return transformedFilter;
 }
Exemplo n.º 4
0
  /**
   * Executes the export operation using the parameters that have been specified.
   *
   * @return a FeatureCollection with the specified features
   */
  @Override
  protected SimpleFeatureStore _call() {
    final ObjectDatabase database = objectDatabase();
    if (filterFeatureTypeId != null) {
      RevObject filterType = database.getIfPresent(filterFeatureTypeId);
      checkArgument(
          filterType instanceof RevFeatureType, "Provided filter feature type is does not exist");
    }

    final SimpleFeatureStore targetStore = getTargetStore();

    final String refspec = resolveRefSpec();
    final String treePath = refspec.substring(refspec.indexOf(':') + 1);
    final RevTree rootTree = resolveRootTree(refspec);
    final NodeRef typeTreeRef = resolTypeTreeRef(refspec, treePath, rootTree);

    final ObjectId defaultMetadataId = typeTreeRef.getMetadataId();

    final RevTree typeTree = database.getTree(typeTreeRef.getObjectId());

    final ProgressListener progressListener = getProgressListener();

    progressListener.started();
    progressListener.setDescription(
        "Exporting from " + path + " to " + targetStore.getName().getLocalPart() + "... ");

    final Iterator<SimpleFeature> filtered;
    {
      final Iterator<SimpleFeature> plainFeatures =
          getFeatures(typeTree, database, defaultMetadataId, progressListener);

      Iterator<SimpleFeature> adaptedFeatures = adaptToArguments(plainFeatures, defaultMetadataId);

      Iterator<Optional<Feature>> transformed =
          Iterators.transform(adaptedFeatures, ExportOp.this.function);

      Iterator<SimpleFeature> result =
          Iterators.filter(
              Iterators.transform(
                  transformed,
                  new Function<Optional<Feature>, SimpleFeature>() {
                    @Override
                    public SimpleFeature apply(Optional<Feature> input) {
                      return (SimpleFeature) input.orNull();
                    }
                  }),
              Predicates.notNull());

      // check the resulting schema has something to contribute
      PeekingIterator<SimpleFeature> peekingIt = Iterators.peekingIterator(result);
      if (peekingIt.hasNext()) {
        Function<AttributeDescriptor, String> toString =
            new Function<AttributeDescriptor, String>() {
              @Override
              public String apply(AttributeDescriptor input) {
                return input.getLocalName();
              }
            };
        SimpleFeature peek = peekingIt.peek();
        Set<String> sourceAtts =
            new HashSet<String>(
                Lists.transform(peek.getFeatureType().getAttributeDescriptors(), toString));
        Set<String> targetAtts =
            new HashSet<String>(
                Lists.transform(targetStore.getSchema().getAttributeDescriptors(), toString));
        if (Sets.intersection(sourceAtts, targetAtts).isEmpty()) {
          throw new GeoToolsOpException(
              StatusCode.UNABLE_TO_ADD,
              "No common attributes between source and target feature types");
        }
      }

      filtered = peekingIt;
    }
    FeatureCollection<SimpleFeatureType, SimpleFeature> asFeatureCollection =
        new BaseFeatureCollection<SimpleFeatureType, SimpleFeature>() {

          @Override
          public FeatureIterator<SimpleFeature> features() {

            return new DelegateFeatureIterator<SimpleFeature>(filtered);
          }
        };

    // add the feature collection to the feature store
    final Transaction transaction;
    if (transactional) {
      transaction = new DefaultTransaction("create");
    } else {
      transaction = Transaction.AUTO_COMMIT;
    }
    try {
      targetStore.setTransaction(transaction);
      try {
        targetStore.addFeatures(asFeatureCollection);
        transaction.commit();
      } catch (final Exception e) {
        if (transactional) {
          transaction.rollback();
        }
        Throwables.propagateIfInstanceOf(e, GeoToolsOpException.class);
        throw new GeoToolsOpException(e, StatusCode.UNABLE_TO_ADD);
      } finally {
        transaction.close();
      }
    } catch (IOException e) {
      throw new GeoToolsOpException(e, StatusCode.UNABLE_TO_ADD);
    }

    progressListener.complete();

    return targetStore;
  }