use of com.vividsolutions.jts.geom.Coordinate in project GeoGig by boundlessgeo.
the class TestHelper method createFactoryWithGetFeatureSourceException.
public static AbstractDataStoreFactory createFactoryWithGetFeatureSourceException() throws Exception {
SimpleFeatureTypeBuilder builder = new SimpleFeatureTypeBuilder();
builder.setCRS(CRS.decode("EPSG:4326"));
builder.add("geom", Point.class);
builder.add("label", String.class);
builder.setName("table1");
SimpleFeatureType type = builder.buildFeatureType();
SimpleFeatureTypeBuilder builder2 = new SimpleFeatureTypeBuilder();
builder2.setCRS(CRS.decode("EPSG:4326"));
builder2.add("geom", Point.class);
builder2.add("name", String.class);
builder2.setName("table2");
SimpleFeatureType type2 = builder2.buildFeatureType();
GeometryFactory gf = new GeometryFactory();
SimpleFeature f1 = SimpleFeatureBuilder.build(type, new Object[] { gf.createPoint(new Coordinate(5, 8)), "feature1" }, null);
SimpleFeature f2 = SimpleFeatureBuilder.build(type, new Object[] { gf.createPoint(new Coordinate(5, 4)), "feature2" }, null);
SimpleFeature f3 = SimpleFeatureBuilder.build(type2, new Object[] { gf.createPoint(new Coordinate(3, 2)), "feature3" }, null);
MemoryDataStore testDataStore = new MemoryDataStore();
testDataStore.addFeature(f1);
testDataStore.addFeature(f2);
testDataStore.addFeature(f3);
MemoryDataStore spyDataStore = spy(testDataStore);
when(spyDataStore.getFeatureSource("table1")).thenThrow(new IOException("Exception"));
final AbstractDataStoreFactory factory = mock(AbstractDataStoreFactory.class);
when(factory.createDataStore(anyMapOf(String.class, Serializable.class))).thenReturn(spyDataStore);
when(factory.canProcess(anyMapOf(String.class, Serializable.class))).thenReturn(true);
return factory;
}
use of com.vividsolutions.jts.geom.Coordinate in project GeoGig by boundlessgeo.
the class GeometryDiffTest method testModifiedMultiPolygon.
@Test
public void testModifiedMultiPolygon() throws Exception {
int NUM_COORDS = 10;
Random rand = new Random();
List<Coordinate> list = Lists.newArrayList();
for (int i = 0; i < NUM_COORDS; i++) {
list.add(new Coordinate(rand.nextInt(), rand.nextInt()));
}
Geometry oldGeom = new WKTReader().read("MULTIPOLYGON (((40 40, 20 45, 45 30, 40 40)),((20 35, 45 10, 30 5, 10 30, 20 35),(30 20, 20 25, 20 15, 30 20)))");
Geometry newGeom = new WKTReader().read("MULTIPOLYGON (((40 40, 20 45, 45 30, 40 40)),((20 35, 45 20, 30 5, 10 10, 10 30, 20 35)))");
LCSGeometryDiffImpl diff = new LCSGeometryDiffImpl(Optional.of(oldGeom), Optional.of(newGeom));
LCSGeometryDiffImpl deserializedDiff = new LCSGeometryDiffImpl(diff.asText());
assertEquals(diff, deserializedDiff);
assertEquals("4 point(s) deleted, 1 new point(s) added, 1 point(s) moved", diff.toString());
Optional<Geometry> resultingGeom = diff.applyOn(Optional.of(oldGeom));
assertEquals(newGeom, resultingGeom.get());
}
use of com.vividsolutions.jts.geom.Coordinate in project GeoGig by boundlessgeo.
the class ImportOpTest method testImportAllWithDifferentFeatureTypesAndDestPathAndAdd.
@Test
public void testImportAllWithDifferentFeatureTypesAndDestPathAndAdd() throws Exception {
SimpleFeatureTypeBuilder builder = new SimpleFeatureTypeBuilder();
builder.setCRS(CRS.decode("EPSG:4326"));
builder.add("geom", Point.class);
builder.add("label", String.class);
builder.setName("dest");
SimpleFeatureType type = builder.buildFeatureType();
GeometryFactory gf = new GeometryFactory();
SimpleFeature feature = SimpleFeatureBuilder.build(type, new Object[] { gf.createPoint(new Coordinate(0, 0)), "feature0" }, "feature");
geogig.getRepository().workingTree().insert("dest", feature);
ImportOp importOp = geogig.command(ImportOp.class);
importOp.setDataStore(TestHelper.createTestFactory().createDataStore(null));
importOp.setAll(true);
importOp.setOverwrite(false);
importOp.setDestinationPath("dest");
importOp.setAdaptToDefaultFeatureType(false);
importOp.call();
Iterator<NodeRef> features = geogig.command(LsTreeOp.class).setStrategy(Strategy.DEPTHFIRST_ONLY_FEATURES).call();
ArrayList<NodeRef> list = Lists.newArrayList(features);
assertEquals(5, list.size());
TreeSet<ObjectId> set = Sets.newTreeSet();
ArrayList<RevFeatureType> ftlist = new ArrayList<RevFeatureType>();
for (NodeRef node : list) {
Optional<RevFeatureType> ft = geogig.command(RevObjectParse.class).setObjectId(node.getMetadataId()).call(RevFeatureType.class);
assertTrue(ft.isPresent());
ftlist.add(ft.get());
set.add(node.getMetadataId());
}
assertEquals(4, set.size());
}
use of com.vividsolutions.jts.geom.Coordinate in project graphhopper by graphhopper.
the class OSMShapeFileReader method processRoads.
@Override
void processRoads() {
DataStore dataStore = null;
FeatureIterator<SimpleFeature> roads = null;
try {
dataStore = openShapefileDataStore(roadsFile, encoding);
roads = getFeatureIterator(dataStore);
while (roads.hasNext()) {
SimpleFeature road = roads.next();
for (Coordinate[] points : getCoords(road.getDefaultGeometry())) {
// Parse all points in the geometry, splitting into
// individual graphhopper edges
// whenever we find a node in the list of points
Coordinate startTowerPnt = null;
List<Coordinate> pillars = new ArrayList<Coordinate>();
for (Coordinate point : points) {
if (startTowerPnt == null) {
startTowerPnt = point;
} else {
int state = coordState.get(point);
if (state >= FIRST_NODE_ID) {
int fromTowerNodeId = coordState.get(startTowerPnt);
int toTowerNodeId = state;
// get distance and estimated centres
double distance = getWayLength(startTowerPnt, pillars, point);
GHPoint estmCentre = new GHPoint(0.5 * (lat(startTowerPnt) + lat(point)), 0.5 * (lng(startTowerPnt) + lng(point)));
PointList pillarNodes = new PointList(pillars.size(), false);
for (Coordinate pillar : pillars) {
pillarNodes.add(lat(pillar), lng(pillar));
}
addEdge(fromTowerNodeId, toTowerNodeId, road, distance, estmCentre, pillarNodes);
startTowerPnt = point;
pillars.clear();
} else {
pillars.add(point);
}
}
}
}
}
} finally {
if (roads != null) {
roads.close();
}
if (dataStore != null) {
dataStore.dispose();
}
}
}
use of com.vividsolutions.jts.geom.Coordinate in project graphhopper by graphhopper.
the class OSMShapeFileReader method processJunctions.
@Override
void processJunctions() {
DataStore dataStore = null;
FeatureIterator<SimpleFeature> roads = null;
try {
dataStore = openShapefileDataStore(roadsFile, encoding);
roads = getFeatureIterator(dataStore);
HashSet<Coordinate> tmpSet = new HashSet<>();
while (roads.hasNext()) {
SimpleFeature road = roads.next();
for (Coordinate[] points : getCoords(road.getDefaultGeometry())) {
tmpSet.clear();
for (int i = 0; i < points.length; i++) {
Coordinate c = points[i];
// duplicate coords or a road which forms a circle (e.g. roundabout)
if (tmpSet.contains(c))
continue;
tmpSet.add(c);
// skip if its already a node
int state = coordState.get(c);
if (state >= FIRST_NODE_ID) {
continue;
}
if (i == 0 || i == points.length - 1 || state == COORD_STATE_PILLAR) {
// turn into a node if its the first or last
// point, or already appeared in another edge
int nodeId = nextNodeId++;
coordState.put(c, nodeId);
saveTowerPosition(nodeId, c);
} else if (state == COORD_STATE_UNKNOWN) {
// mark it as a pillar (which may get upgraded
// to an edge later)
coordState.put(c, COORD_STATE_PILLAR);
}
}
}
}
} finally {
if (roads != null) {
roads.close();
}
if (dataStore != null) {
dataStore.dispose();
}
}
if (nextNodeId == FIRST_NODE_ID)
throw new IllegalArgumentException("No data found for roads file " + roadsFile);
LOGGER.info("Number of junction points : " + (nextNodeId - FIRST_NODE_ID));
}
Aggregations