Search in sources :

Example 31 with Coordinate

use of com.vividsolutions.jts.geom.Coordinate in project ddf by codice.

the class WfsFilterDelegate method createPolygon.

private JAXBElement<PolygonType> createPolygon(String wkt) {
    PolygonType polygon = new PolygonType();
    LinearRingType linearRing = new LinearRingType();
    Coordinate[] coordinates = getCoordinatesFromWkt(wkt);
    if (coordinates != null && coordinates.length > 0) {
        StringBuffer coordString = new StringBuffer();
        for (Coordinate coordinate : coordinates) {
            coordString.append(coordinate.x).append(",").append(coordinate.y).append(" ");
        }
        CoordinatesType coordinatesType = new CoordinatesType();
        coordinatesType.setValue(coordString.toString());
        coordinatesType.setDecimal(".");
        coordinatesType.setCs(",");
        coordinatesType.setTs(" ");
        linearRing.setCoordinates(coordinatesType);
        LinearRingMemberType member = new LinearRingMemberType();
        member.setGeometry(gmlObjectFactory.createLinearRing(linearRing));
        polygon.setOuterBoundaryIs(member);
        polygon.setSrsName(srsName);
        return gmlObjectFactory.createPolygon(polygon);
    } else {
        throw new IllegalArgumentException("Unable to parse Polygon coordinates from WKT String");
    }
}
Also used : Coordinate(com.vividsolutions.jts.geom.Coordinate) LinearRingType(ogc.schema.opengis.gml.v_2_1_2.LinearRingType) LinearRingMemberType(ogc.schema.opengis.gml.v_2_1_2.LinearRingMemberType) MultiPolygonType(ogc.schema.opengis.gml.v_2_1_2.MultiPolygonType) PolygonType(ogc.schema.opengis.gml.v_2_1_2.PolygonType) CoordinatesType(ogc.schema.opengis.gml.v_2_1_2.CoordinatesType)

Example 32 with Coordinate

use of com.vividsolutions.jts.geom.Coordinate in project ddf by codice.

the class WfsFilterDelegate method getCoordinatesFromWkt.

private Coordinate[] getCoordinatesFromWkt(String wkt) {
    Coordinate[] coordinates = null;
    try {
        Geometry geo = getGeometryFromWkt(wkt);
        coordinates = geo.getCoordinates();
    } catch (ParseException e) {
        throw new IllegalArgumentException("Unable to parse WKT String", e);
    }
    return coordinates;
}
Also used : Geometry(com.vividsolutions.jts.geom.Geometry) Coordinate(com.vividsolutions.jts.geom.Coordinate) ParseException(com.vividsolutions.jts.io.ParseException)

Example 33 with Coordinate

use of com.vividsolutions.jts.geom.Coordinate in project GeoGig by boundlessgeo.

the class GeogigSimpleFeature method getAttribute.

@Override
public Object getAttribute(int index) throws IndexOutOfBoundsException {
    if (node != null && index == defaultGeomIndex && defaultGeomIsPoint && (resolvedValues == null || resolvedValues instanceof ImmutableList)) {
        Envelope e = new Envelope();
        node.expand(e);
        if (e.isNull()) {
            return null;
        }
        return DEFAULT_GEOM_FACTORY.createPoint(new Coordinate(e.getMinX(), e.getMinY()));
    }
    return getValues().get(index).orNull();
}
Also used : Coordinate(com.vividsolutions.jts.geom.Coordinate) ImmutableList(com.google.common.collect.ImmutableList) ReferencedEnvelope(org.geotools.geometry.jts.ReferencedEnvelope) Envelope(com.vividsolutions.jts.geom.Envelope)

Example 34 with Coordinate

use of com.vividsolutions.jts.geom.Coordinate in project GeoGig by boundlessgeo.

the class OSMHookTest method testOSMHook.

@Test
public void testOSMHook() throws Exception {
    // set the hook that will trigger an unmapping when something is imported to the busstops
    // tree
    CharSequence commitPreHookCode = "var diffs = geogig.getFeaturesToCommit(\"busstops\", false);\n" + "if (diffs.length > 0){\n" + "\tvar params = {\"path\" : \"busstops\"};\n" + "\tgeogig.run(\"org.locationtech.geogig.osm.internal.OSMUnmapOp\", params)\n}";
    File hooksFolder = new File(geogig.getPlatform().pwd(), ".geogig/hooks");
    File commitPreHookFile = new File(hooksFolder, "pre_commit.js");
    Files.write(commitPreHookCode, commitPreHookFile, Charsets.UTF_8);
    // Import
    String filename = OSMImportOp.class.getResource("nodes.xml").getFile();
    File file = new File(filename);
    geogig.command(OSMImportOp.class).setDataSource(file.getAbsolutePath()).call();
    // Map
    Map<String, AttributeDefinition> fields = Maps.newHashMap();
    Map<String, List<String>> mappings = Maps.newHashMap();
    mappings.put("highway", Lists.newArrayList("bus_stop"));
    fields.put("geom", new AttributeDefinition("geom", FieldType.POINT));
    fields.put("name", new AttributeDefinition("name", FieldType.STRING));
    MappingRule mappingRule = new MappingRule("busstops", mappings, null, fields, null);
    List<MappingRule> mappingRules = Lists.newArrayList();
    mappingRules.add(mappingRule);
    Mapping mapping = new Mapping(mappingRules);
    geogig.command(AddOp.class).call();
    geogig.command(CommitOp.class).setMessage("msg").call();
    geogig.command(OSMMapOp.class).setMapping(mapping).call();
    Optional<RevFeature> revFeature = geogig.command(RevObjectParse.class).setRefSpec("HEAD:busstops/507464799").call(RevFeature.class);
    assertTrue(revFeature.isPresent());
    Optional<RevFeatureType> featureType = geogig.command(ResolveFeatureType.class).setRefSpec("HEAD:busstops/507464799").call();
    assertTrue(featureType.isPresent());
    ImmutableList<Optional<Object>> values = revFeature.get().getValues();
    assertEquals(3, values.size());
    String wkt = "POINT (7.1959361 50.739397)";
    assertEquals(wkt, values.get(2).get().toString());
    assertEquals(507464799l, values.get(0).get());
    // Modify a node
    GeometryFactory gf = new GeometryFactory();
    SimpleFeatureBuilder fb = new SimpleFeatureBuilder((SimpleFeatureType) featureType.get().type());
    fb.set("geom", gf.createPoint(new Coordinate(0, 1)));
    fb.set("name", "newname");
    fb.set("id", 507464799l);
    SimpleFeature newFeature = fb.buildFeature("507464799");
    geogig.getRepository().workingTree().insert("busstops", newFeature);
    geogig.command(AddOp.class).call();
    // this should trigger the hook
    geogig.command(CommitOp.class).setMessage("msg").call();
    // check that the unmapping has been triggered and the unmapped node has the changes we
    // introduced
    Optional<RevFeature> unmapped = geogig.command(RevObjectParse.class).setRefSpec("WORK_HEAD:node/507464799").call(RevFeature.class);
    assertTrue(unmapped.isPresent());
    values = unmapped.get().getValues();
    assertEquals("POINT (0 1)", values.get(6).get().toString());
    assertEquals("bus:yes|public_transport:platform|highway:bus_stop|VRS:ortsteil:Hoholz|name:newname|VRS:ref:68566|VRS:gemeinde:BONN", values.get(3).get().toString());
    // check that unchanged nodes keep their attributes
    Optional<RevFeature> unchanged = geogig.command(RevObjectParse.class).setRefSpec("WORK_HEAD:node/1633594723").call(RevFeature.class);
    values = unchanged.get().getValues();
    assertEquals("14220478", values.get(4).get().toString());
    assertEquals("1355097351000", values.get(2).get().toString());
    assertEquals("2", values.get(1).get().toString());
}
Also used : AddOp(org.locationtech.geogig.api.porcelain.AddOp) GeometryFactory(com.vividsolutions.jts.geom.GeometryFactory) Optional(com.google.common.base.Optional) SimpleFeature(org.opengis.feature.simple.SimpleFeature) Coordinate(com.vividsolutions.jts.geom.Coordinate) RevFeature(org.locationtech.geogig.api.RevFeature) ImmutableList(com.google.common.collect.ImmutableList) List(java.util.List) File(java.io.File) RevFeatureType(org.locationtech.geogig.api.RevFeatureType) SimpleFeatureBuilder(org.geotools.feature.simple.SimpleFeatureBuilder) Test(org.junit.Test)

Example 35 with Coordinate

use of com.vividsolutions.jts.geom.Coordinate in project GeoGig by boundlessgeo.

the class MappingRule method hasCompatibleGeometryType.

private boolean hasCompatibleGeometryType(Feature feature) {
    getFeatureType();
    GeomRestriction restriction = getGeomRestriction();
    GeometryAttribute property = feature.getDefaultGeometryProperty();
    Geometry geom = (Geometry) property.getValue();
    if (geom.getClass().equals(Point.class)) {
        return geometryType == Point.class;
    } else {
        if (geometryType.equals(Point.class)) {
            return false;
        }
        Coordinate[] coords = geom.getCoordinates();
        if (geometryType.equals(Polygon.class) && coords.length < 3) {
            return false;
        }
        boolean isClosed = coords[0].equals(coords[coords.length - 1]);
        if (isClosed && restriction.equals(GeomRestriction.ONLY_OPEN_LINES)) {
            return false;
        }
        if (!isClosed && restriction.equals(GeomRestriction.ONLY_CLOSED_LINES)) {
            return false;
        }
        return true;
    }
}
Also used : Geometry(com.vividsolutions.jts.geom.Geometry) Coordinate(com.vividsolutions.jts.geom.Coordinate) GeometryAttribute(org.opengis.feature.GeometryAttribute) Polygon(com.vividsolutions.jts.geom.Polygon)

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