Search in sources :

Example 1 with DefaultProgressListener

use of org.locationtech.geogig.api.DefaultProgressListener in project GeoGig by boundlessgeo.

the class DiffBoundsTest method testReprojectToTargetBucketTree.

@Test
public void testReprojectToTargetBucketTree() throws Exception {
    final int leftCount = RevTree.NORMALIZED_SIZE_LIMIT * 2;
    final int rightCount = RevTree.NORMALIZED_SIZE_LIMIT * 3;
    WorkingTree workingTree = geogig.getRepository().workingTree();
    final String typeName = "newpoints";
    final DefaultProgressListener listener = new DefaultProgressListener();
    workingTree.insert(typeName, new TestFeatureIterator(typeName, leftCount), listener, null, null);
    geogig.command(AddOp.class).call();
    workingTree.insert(typeName, new TestFeatureIterator(typeName, rightCount), listener, null, null);
    {
        // sanity check
        long diffFeatures = geogig.command(DiffCount.class).setOldVersion("STAGE_HEAD").setNewVersion("WORK_HEAD").call().featureCount();
        assertEquals(rightCount - leftCount, diffFeatures);
    }
    DiffBounds cmd = geogig.command(DiffBounds.class).setOldVersion("STAGE_HEAD").setNewVersion("WORK_HEAD");
    final CoordinateReferenceSystem nativeCrs = CRS.decode("EPSG:3857");
    final DiffSummary<BoundingBox, BoundingBox> diffInNativeCrs = cmd.setCRS(nativeCrs).call();
    CoordinateReferenceSystem targetcrs = CRS.decode("EPSG:4326", true);
    cmd.setCRS(targetcrs);
    DiffSummary<BoundingBox, BoundingBox> reprojected = cmd.call();
    assertEquals(targetcrs, reprojected.getLeft().getCoordinateReferenceSystem());
    assertEquals(targetcrs, reprojected.getRight().getCoordinateReferenceSystem());
    assertEquals(targetcrs, reprojected.getMergedResult().get().getCoordinateReferenceSystem());
    ReferencedEnvelope e = new ReferencedEnvelope(diffInNativeCrs.getRight());
    ReferencedEnvelope expected = e.transform(targetcrs, true);
    BoundingBox actual = reprojected.getRight();
    assertEquals(expected, actual);
}
Also used : AddOp(org.locationtech.geogig.api.porcelain.AddOp) WorkingTree(org.locationtech.geogig.repository.WorkingTree) ReferencedEnvelope(org.geotools.geometry.jts.ReferencedEnvelope) BoundingBox(org.opengis.geometry.BoundingBox) DefaultProgressListener(org.locationtech.geogig.api.DefaultProgressListener) CoordinateReferenceSystem(org.opengis.referencing.crs.CoordinateReferenceSystem) Test(org.junit.Test)

Example 2 with DefaultProgressListener

use of org.locationtech.geogig.api.DefaultProgressListener in project GeoGig by boundlessgeo.

the class SilentProgressListener method runCommand.

/**
     * Runs a command on a given repository
     * 
     * @param folder the repository folder
     * @param args the args to run, including the command itself and additional parameters
     * @return
     * @throws IOException
     */
public int runCommand(String folder, String[] args) throws IOException {
    System.gc();
    GeogigCLI cli = new GeogigCLI(consoleReader) {

        @Override
        public synchronized ProgressListener getProgressListener() {
            if (super.progressListener == null) {
                super.progressListener = new DefaultProgressListener() {

                    @Override
                    public void setDescription(String s) {
                        GeogigPy4JEntryPoint.this.listener.setProgressText(s);
                    }

                    @Override
                    public synchronized void setProgress(float percent) {
                        GeogigPy4JEntryPoint.this.listener.setProgress(percent);
                    }
                };
            }
            return super.progressListener;
        }
    };
    DefaultPlatform platform = new DefaultPlatform();
    platform.setWorkingDir(new File(folder));
    cli.setPlatform(platform);
    String command = Joiner.on(" ").join(args);
    os.clear();
    pages = null;
    System.out.print("Running command: " + command);
    int ret = cli.execute(args);
    cli.close();
    if (ret == 0) {
        System.out.println(" [OK]");
    } else {
        System.out.println(" [Error]");
    }
    stream.flush();
    os.flush();
    return ret;
}
Also used : DefaultProgressListener(org.locationtech.geogig.api.DefaultProgressListener) DefaultPlatform(org.locationtech.geogig.api.DefaultPlatform) File(java.io.File)

Example 3 with DefaultProgressListener

use of org.locationtech.geogig.api.DefaultProgressListener in project GeoGig by boundlessgeo.

the class GeogigFeatureStore method addFeatures.

@Override
public final List<FeatureId> addFeatures(FeatureCollection<SimpleFeatureType, SimpleFeature> featureCollection) throws IOException {
    if (Transaction.AUTO_COMMIT.equals(getTransaction())) {
        throw new UnsupportedOperationException("GeoGIG does not support AUTO_COMMIT");
    }
    Preconditions.checkState(getDataStore().isAllowTransactions(), "Transactions not supported; head is not a local branch");
    final WorkingTree workingTree = delegate.getWorkingTree();
    final String path = delegate.getTypeTreePath();
    ProgressListener listener = new DefaultProgressListener();
    final List<FeatureId> insertedFids = Lists.newArrayList();
    List<Node> deferringTarget = new AbstractList<Node>() {

        @Override
        public boolean add(Node node) {
            String fid = node.getName();
            String version = node.getObjectId().toString();
            insertedFids.add(new FeatureIdVersionedImpl(fid, version));
            return true;
        }

        @Override
        public Node get(int index) {
            throw new UnsupportedOperationException();
        }

        @Override
        public int size() {
            return 0;
        }
    };
    Integer count = (Integer) null;
    FeatureIterator<SimpleFeature> featureIterator = featureCollection.features();
    try {
        Iterator<SimpleFeature> features;
        features = new FeatureIteratorIterator<SimpleFeature>(featureIterator);
        /*
             * Make sure to transform the incoming features to the native schema to avoid situations
             * where geogig would change the metadataId of the RevFeature nodes due to small
             * differences in the default and incoming schema such as namespace or missing
             * properties
             */
        final SimpleFeatureType nativeSchema = delegate.getNativeType();
        features = Iterators.transform(features, new SchemaInforcer(nativeSchema));
        workingTree.insert(path, features, listener, deferringTarget, count);
    } catch (Exception e) {
        throw new IOException(e);
    } finally {
        featureIterator.close();
    }
    return insertedFids;
}
Also used : AbstractList(java.util.AbstractList) Node(org.locationtech.geogig.api.Node) DefaultProgressListener(org.locationtech.geogig.api.DefaultProgressListener) IOException(java.io.IOException) SimpleFeature(org.opengis.feature.simple.SimpleFeature) IOException(java.io.IOException) FeatureId(org.opengis.filter.identity.FeatureId) WorkingTree(org.locationtech.geogig.repository.WorkingTree) DefaultProgressListener(org.locationtech.geogig.api.DefaultProgressListener) ProgressListener(org.locationtech.geogig.api.ProgressListener) SimpleFeatureType(org.opengis.feature.simple.SimpleFeatureType) FeatureIdVersionedImpl(org.geotools.filter.identity.FeatureIdVersionedImpl)

Example 4 with DefaultProgressListener

use of org.locationtech.geogig.api.DefaultProgressListener in project GeoGig by boundlessgeo.

the class GeogigFeatureStore method modifyFeatures.

@Override
public void modifyFeatures(Name[] names, Object[] values, Filter filter) throws IOException {
    Preconditions.checkState(getDataStore().isAllowTransactions(), "Transactions not supported; head is not a local branch");
    final WorkingTree workingTree = delegate.getWorkingTree();
    final String path = delegate.getTypeTreePath();
    Iterator<SimpleFeature> features = modifyingFeatureIterator(names, values, filter);
    /*
         * Make sure to transform the incoming features to the native schema to avoid situations
         * where geogig would change the metadataId of the RevFeature nodes due to small differences
         * in the default and incoming schema such as namespace or missing properties
         */
    final SimpleFeatureType nativeSchema = delegate.getNativeType();
    features = Iterators.transform(features, new SchemaInforcer(nativeSchema));
    try {
        ProgressListener listener = new DefaultProgressListener();
        Integer count = (Integer) null;
        List<Node> target = (List<Node>) null;
        workingTree.insert(path, features, listener, target, count);
    } catch (Exception e) {
        throw new IOException(e);
    }
}
Also used : Node(org.locationtech.geogig.api.Node) DefaultProgressListener(org.locationtech.geogig.api.DefaultProgressListener) IOException(java.io.IOException) SimpleFeature(org.opengis.feature.simple.SimpleFeature) IOException(java.io.IOException) WorkingTree(org.locationtech.geogig.repository.WorkingTree) SimpleFeatureType(org.opengis.feature.simple.SimpleFeatureType) DefaultProgressListener(org.locationtech.geogig.api.DefaultProgressListener) ProgressListener(org.locationtech.geogig.api.ProgressListener) AbstractList(java.util.AbstractList) List(java.util.List)

Example 5 with DefaultProgressListener

use of org.locationtech.geogig.api.DefaultProgressListener in project GeoGig by boundlessgeo.

the class OSMHistoryImport method insertChanges.

/**
     * @param cli
     * @param changes
     * @param featureFilter
     * @throws IOException
     */
private long insertChanges(GeogigCLI cli, final Iterator<Change> changes, @Nullable Envelope featureFilter) throws IOException {
    final GeoGIG geogig = cli.getGeogig();
    final Repository repository = geogig.getRepository();
    final WorkingTree workTree = repository.workingTree();
    Map<Long, Coordinate> thisChangePointCache = new LinkedHashMap<Long, Coordinate>() {

        /** serialVersionUID */
        private static final long serialVersionUID = 1277795218777240552L;

        @Override
        protected boolean removeEldestEntry(Map.Entry<Long, Coordinate> eldest) {
            return size() == 10000;
        }
    };
    long cnt = 0;
    Set<String> deletes = Sets.newHashSet();
    Multimap<String, SimpleFeature> insertsByParent = HashMultimap.create();
    while (changes.hasNext()) {
        Change change = changes.next();
        final String featurePath = featurePath(change);
        if (featurePath == null) {
            // ignores relations
            continue;
        }
        final String parentPath = NodeRef.parentPath(featurePath);
        if (Change.Type.delete.equals(change.getType())) {
            cnt++;
            deletes.add(featurePath);
        } else {
            final Primitive primitive = change.getNode().isPresent() ? change.getNode().get() : change.getWay().get();
            final Geometry geom = parseGeometry(geogig, primitive, thisChangePointCache);
            if (geom instanceof Point) {
                thisChangePointCache.put(Long.valueOf(primitive.getId()), ((Point) geom).getCoordinate());
            }
            SimpleFeature feature = toFeature(primitive, geom);
            if (featureFilter == null || featureFilter.intersects((Envelope) feature.getBounds())) {
                insertsByParent.put(parentPath, feature);
                cnt++;
            }
        }
    }
    for (String parentPath : insertsByParent.keySet()) {
        Collection<SimpleFeature> features = insertsByParent.get(parentPath);
        if (features.isEmpty()) {
            continue;
        }
        Iterator<? extends Feature> iterator = features.iterator();
        ProgressListener listener = new DefaultProgressListener();
        List<org.locationtech.geogig.api.Node> insertedTarget = null;
        Integer collectionSize = Integer.valueOf(features.size());
        workTree.insert(parentPath, iterator, listener, insertedTarget, collectionSize);
    }
    if (!deletes.isEmpty()) {
        workTree.delete(deletes.iterator());
    }
    return cnt;
}
Also used : Node(org.locationtech.geogig.osm.internal.history.Node) Envelope(com.vividsolutions.jts.geom.Envelope) LinkedHashMap(java.util.LinkedHashMap) WorkingTree(org.locationtech.geogig.repository.WorkingTree) Entry(java.util.Map.Entry) Primitive(org.locationtech.geogig.osm.internal.history.Primitive) DefaultProgressListener(org.locationtech.geogig.api.DefaultProgressListener) Change(org.locationtech.geogig.osm.internal.history.Change) Point(com.vividsolutions.jts.geom.Point) SimpleFeature(org.opengis.feature.simple.SimpleFeature) Geometry(com.vividsolutions.jts.geom.Geometry) Repository(org.locationtech.geogig.repository.Repository) ProgressListener(org.locationtech.geogig.api.ProgressListener) DefaultProgressListener(org.locationtech.geogig.api.DefaultProgressListener) Coordinate(com.vividsolutions.jts.geom.Coordinate) GeoGIG(org.locationtech.geogig.api.GeoGIG)

Aggregations

DefaultProgressListener (org.locationtech.geogig.api.DefaultProgressListener)6 ProgressListener (org.locationtech.geogig.api.ProgressListener)4 WorkingTree (org.locationtech.geogig.repository.WorkingTree)4 SimpleFeature (org.opengis.feature.simple.SimpleFeature)4 IOException (java.io.IOException)2 AbstractList (java.util.AbstractList)2 Node (org.locationtech.geogig.api.Node)2 SimpleFeatureType (org.opengis.feature.simple.SimpleFeatureType)2 Coordinate (com.vividsolutions.jts.geom.Coordinate)1 Envelope (com.vividsolutions.jts.geom.Envelope)1 Geometry (com.vividsolutions.jts.geom.Geometry)1 Point (com.vividsolutions.jts.geom.Point)1 File (java.io.File)1 LinkedHashMap (java.util.LinkedHashMap)1 List (java.util.List)1 Entry (java.util.Map.Entry)1 FeatureIdVersionedImpl (org.geotools.filter.identity.FeatureIdVersionedImpl)1 ReferencedEnvelope (org.geotools.geometry.jts.ReferencedEnvelope)1 Test (org.junit.Test)1 DefaultPlatform (org.locationtech.geogig.api.DefaultPlatform)1