Search in sources :

Example 36 with Coordinate

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;
}
Also used : AbstractDataStoreFactory(org.geotools.data.AbstractDataStoreFactory) Serializable(java.io.Serializable) SimpleFeatureTypeBuilder(org.geotools.feature.simple.SimpleFeatureTypeBuilder) GeometryFactory(com.vividsolutions.jts.geom.GeometryFactory) SimpleFeatureType(org.opengis.feature.simple.SimpleFeatureType) Coordinate(com.vividsolutions.jts.geom.Coordinate) MemoryDataStore(org.geotools.data.memory.MemoryDataStore) IOException(java.io.IOException) Matchers.anyString(org.mockito.Matchers.anyString) SimpleFeature(org.opengis.feature.simple.SimpleFeature)

Example 37 with Coordinate

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());
}
Also used : Geometry(com.vividsolutions.jts.geom.Geometry) Random(java.util.Random) Coordinate(com.vividsolutions.jts.geom.Coordinate) WKTReader(com.vividsolutions.jts.io.WKTReader) Test(org.junit.Test)

Example 38 with Coordinate

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());
}
Also used : SimpleFeatureTypeBuilder(org.geotools.feature.simple.SimpleFeatureTypeBuilder) GeometryFactory(com.vividsolutions.jts.geom.GeometryFactory) ObjectId(org.locationtech.geogig.api.ObjectId) ArrayList(java.util.ArrayList) SimpleFeature(org.opengis.feature.simple.SimpleFeature) NodeRef(org.locationtech.geogig.api.NodeRef) SimpleFeatureType(org.opengis.feature.simple.SimpleFeatureType) Coordinate(com.vividsolutions.jts.geom.Coordinate) RevFeatureType(org.locationtech.geogig.api.RevFeatureType) Test(org.junit.Test)

Example 39 with Coordinate

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();
        }
    }
}
Also used : PointList(com.graphhopper.util.PointList) Coordinate(com.vividsolutions.jts.geom.Coordinate) DataStore(org.geotools.data.DataStore) ArrayList(java.util.ArrayList) GHPoint(com.graphhopper.util.shapes.GHPoint) SimpleFeature(org.opengis.feature.simple.SimpleFeature) GHPoint(com.graphhopper.util.shapes.GHPoint)

Example 40 with Coordinate

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));
}
Also used : Coordinate(com.vividsolutions.jts.geom.Coordinate) DataStore(org.geotools.data.DataStore) SimpleFeature(org.opengis.feature.simple.SimpleFeature) GHPoint(com.graphhopper.util.shapes.GHPoint) HashSet(java.util.HashSet)

Aggregations

Coordinate (com.vividsolutions.jts.geom.Coordinate)336 LineString (com.vividsolutions.jts.geom.LineString)70 Geometry (com.vividsolutions.jts.geom.Geometry)67 ArrayList (java.util.ArrayList)65 Test (org.junit.Test)60 Point (com.vividsolutions.jts.geom.Point)52 GeometryFactory (com.vividsolutions.jts.geom.GeometryFactory)48 Polygon (com.vividsolutions.jts.geom.Polygon)30 StreetEdge (org.opentripplanner.routing.edgetype.StreetEdge)27 SimpleFeature (org.opengis.feature.simple.SimpleFeature)23 LinearRing (com.vividsolutions.jts.geom.LinearRing)22 Vertex (org.opentripplanner.routing.graph.Vertex)22 Envelope (com.vividsolutions.jts.geom.Envelope)21 MultiLineString (com.vividsolutions.jts.geom.MultiLineString)20 Edge (org.opentripplanner.routing.graph.Edge)19 IntersectionVertex (org.opentripplanner.routing.vertextype.IntersectionVertex)19 CoordinateSequence (com.vividsolutions.jts.geom.CoordinateSequence)14 TransitStop (org.opentripplanner.routing.vertextype.TransitStop)13 File (java.io.File)11 XContentBuilder (org.elasticsearch.common.xcontent.XContentBuilder)11