Search in sources :

Example 1 with GeometryFactory

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

the class FeatureCollectionConverterWfs10 method getBounds.

private Geometry getBounds(List<Metacard> metacards) {
    if (metacards != null) {
        List<Geometry> geometries = new ArrayList<Geometry>();
        for (Metacard card : metacards) {
            if (null != card.getLocation()) {
                Geometry geo = XmlNode.readGeometry(card.getLocation());
                if (null != geo) {
                    geometries.add(geo);
                }
            }
        }
        Geometry allGeometry = new GeometryCollection(geometries.toArray(new Geometry[0]), new GeometryFactory());
        return allGeometry;
    } else {
        LOGGER.debug("List of metacards was null.");
        return null;
    }
}
Also used : Geometry(com.vividsolutions.jts.geom.Geometry) GeometryCollection(com.vividsolutions.jts.geom.GeometryCollection) Metacard(ddf.catalog.data.Metacard) GeometryFactory(com.vividsolutions.jts.geom.GeometryFactory) ArrayList(java.util.ArrayList)

Example 2 with GeometryFactory

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

the class TestXmlInputTransformer method testNormalTransform.

/*
        Tests a base XmlInputTransformer, CONTENT_TYPE is null because it is not in the base xmlToMetacard mapping
     */
@Test
public void testNormalTransform() throws FileNotFoundException, CatalogTransformerException {
    inputStream = new FileInputStream("src/test/resources/metacard2.xml");
    saxEventHandlerFactory = new XmlSaxEventHandlerFactoryImpl();
    saxEventHandler = saxEventHandlerFactory.getNewSaxEventHandler();
    assertThat(saxEventHandler.getSupportedAttributeDescriptors().size(), is(greaterThan(0)));
    GMLHandler gh = new GMLHandler(new GeometryFactory(), (ErrorHandler) null);
    gmlHandler = new GmlHandler(gh, gml3ToWkt);
    assertThat(gmlHandler.getSupportedAttributeDescriptors().size(), is(greaterThan(0)));
    saxEventHandlerDelegate = new SaxEventHandlerDelegate(Arrays.asList(saxEventHandler, gmlHandler));
    Metacard metacard = saxEventHandlerDelegate.read(inputStream).getMetacard(null);
    assertThat(metacard.getAttribute(Metacard.TITLE).getValues().size(), is(1));
    assertThat(metacard.getAttribute(Metacard.TITLE).getValues().get(0), is("Title!"));
    assertThat(metacard.getAttribute(Metacard.DESCRIPTION).getValues().size(), is(1));
    assertThat(metacard.getAttribute(Metacard.DESCRIPTION).getValues().get(0), is("Description!"));
    assertThat(metacard.getAttribute(Metacard.POINT_OF_CONTACT).getValues().size(), is(1));
    assertThat(metacard.getAttribute(Metacard.POINT_OF_CONTACT).getValues().get(0), is("POC!"));
    assertThat(metacard.getAttribute(Metacard.RESOURCE_URI).getValues().size(), is(1));
    assertThat(metacard.getAttribute(Metacard.RESOURCE_URI).getValues().get(0), is("foobar"));
    assertThat(metacard.getAttribute(Metacard.CONTENT_TYPE), is(nullValue()));
    assertThat(metacard.getAttribute(Metacard.GEOGRAPHY).getValues().size(), is(1));
    assertThat(metacard.getAttribute(Metacard.GEOGRAPHY).getValues().get(0), is("POINT (100 200)"));
}
Also used : SaxEventHandlerDelegate(org.codice.ddf.transformer.xml.streaming.lib.SaxEventHandlerDelegate) Metacard(ddf.catalog.data.Metacard) GeometryFactory(com.vividsolutions.jts.geom.GeometryFactory) GMLHandler(com.vividsolutions.jts.io.gml2.GMLHandler) FileInputStream(java.io.FileInputStream) Test(org.junit.Test)

Example 3 with GeometryFactory

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

the class TestCswRecordMapperFilterVisitor method testVisitBeyond.

@Test
public void testVisitBeyond() {
    GeometryFactory geoFactory = new GeometryFactory();
    double val = 30;
    Expression pt1 = factory.literal(geoFactory.createPoint(new Coordinate(4, 5)));
    Expression pt2 = factory.literal(geoFactory.createPoint(new Coordinate(6, 7)));
    Beyond filter = factory.beyond(pt1, pt2, val, "kilometers");
    Beyond duplicate = (Beyond) visitor.visit(filter, null);
    assertThat(duplicate.getExpression1(), is(pt1));
    assertThat(duplicate.getExpression2(), is(pt2));
    assertThat(duplicate.getDistanceUnits(), is(UomOgcMapping.METRE.name()));
    assertThat(duplicate.getDistance(), is(1000 * val));
}
Also used : GeometryFactory(com.vividsolutions.jts.geom.GeometryFactory) Expression(org.opengis.filter.expression.Expression) Coordinate(com.vividsolutions.jts.geom.Coordinate) Beyond(org.opengis.filter.spatial.Beyond) CswQueryFactoryTest(org.codice.ddf.spatial.ogc.csw.catalog.endpoint.CswQueryFactoryTest) Test(org.junit.Test)

Example 4 with GeometryFactory

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

the class TestCswRecordMapperFilterVisitor method testIntersectsUtm.

@Test
public void testIntersectsUtm() throws FactoryException, TransformException {
    double lon = 33.45;
    double lat = 25.22;
    double easting = 545328.48;
    double northing = 2789384.24;
    CoordinateReferenceSystem sourceCRS = CRS.decode("EPSG:32636");
    GeometryFactory geoFactory = new GeometryFactory();
    Geometry utmPoint = geoFactory.createPoint(new Coordinate(easting, northing));
    utmPoint.setUserData(sourceCRS);
    Expression pt1 = factory.literal(geoFactory.createPoint(new Coordinate(1, 2)));
    Expression pt2 = factory.literal(utmPoint);
    Intersects filter = factory.intersects(pt1, pt2);
    visitor.visit(filter, null);
    assertThat(pt2, instanceOf(Literal.class));
    Literal literalExpression = (Literal) pt2;
    assertThat(literalExpression.getValue(), instanceOf(Geometry.class));
    Geometry geometry = (Geometry) literalExpression.getValue();
    assertThat(geometry.getCoordinates()[0].x, closeTo(lon, .00001));
    assertThat(geometry.getCoordinates()[0].y, closeTo(lat, .00001));
}
Also used : Geometry(com.vividsolutions.jts.geom.Geometry) GeometryFactory(com.vividsolutions.jts.geom.GeometryFactory) Coordinate(com.vividsolutions.jts.geom.Coordinate) Expression(org.opengis.filter.expression.Expression) Intersects(org.opengis.filter.spatial.Intersects) Literal(org.opengis.filter.expression.Literal) CoordinateReferenceSystem(org.opengis.referencing.crs.CoordinateReferenceSystem) CswQueryFactoryTest(org.codice.ddf.spatial.ogc.csw.catalog.endpoint.CswQueryFactoryTest) Test(org.junit.Test)

Example 5 with GeometryFactory

use of com.vividsolutions.jts.geom.GeometryFactory 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)

Aggregations

GeometryFactory (com.vividsolutions.jts.geom.GeometryFactory)72 Coordinate (com.vividsolutions.jts.geom.Coordinate)47 Test (org.junit.Test)25 Geometry (com.vividsolutions.jts.geom.Geometry)22 ArrayList (java.util.ArrayList)22 LineString (com.vividsolutions.jts.geom.LineString)17 SimpleFeature (org.opengis.feature.simple.SimpleFeature)13 File (java.io.File)10 IntersectionVertex (org.opentripplanner.routing.vertextype.IntersectionVertex)10 Point (com.vividsolutions.jts.geom.Point)9 LinearRing (com.vividsolutions.jts.geom.LinearRing)8 List (java.util.List)8 SimpleFeatureBuilder (org.geotools.feature.simple.SimpleFeatureBuilder)8 RevFeatureType (org.locationtech.geogig.api.RevFeatureType)8 Optional (com.google.common.base.Optional)7 Polygon (com.vividsolutions.jts.geom.Polygon)7 Metacard (ddf.catalog.data.Metacard)7 RevFeature (org.locationtech.geogig.api.RevFeature)7 ImmutableList (com.google.common.collect.ImmutableList)6 GeometryOperator (org.codice.alliance.libs.klv.GeometryOperator)6