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);
}
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;
}
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;
}
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);
}
}
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;
}
Aggregations