Search in sources :

Example 16 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 17 with GeometryFactory

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

the class GeoUtilTest method testTransformEpsg4326EpsgMatch.

@Test
public void testTransformEpsg4326EpsgMatch() throws FactoryException, TransformException, GeoFormatException {
    double lon = 33.45;
    double lat = 25.22;
    CoordinateReferenceSystem sourceCRS = CRS.decode("EPSG:4326");
    GeometryFactory geometryFactory = new GeometryFactory();
    Coordinate coordinate = new Coordinate(lon, lat);
    Point utmPoint = geometryFactory.createPoint(coordinate);
    Envelope envelope = JTS.toEnvelope(utmPoint);
    Geometry utmGeometry = JTS.toGeometry(envelope);
    Geometry lonLatGeom = GeospatialUtil.transformToEPSG4326LonLatFormat(utmGeometry, sourceCRS);
    assertThat(lonLatGeom.getCoordinates()[0].x, closeTo(lon, .00001));
    assertThat(lonLatGeom.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) CoordinateReferenceSystem(org.opengis.referencing.crs.CoordinateReferenceSystem) Point(com.vividsolutions.jts.geom.Point) Envelope(com.vividsolutions.jts.geom.Envelope) Test(org.junit.Test)

Example 18 with GeometryFactory

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

the class GeoUtilTest method testTransformEpsg4326LonLat.

@Test
public void testTransformEpsg4326LonLat() throws GeoFormatException {
    GeometryFactory gf = new GeometryFactory();
    Coordinate coord = new Coordinate(25.22, 33.45);
    Point point = gf.createPoint(coord);
    Geometry convertedGeometry = GeospatialUtil.transformToEPSG4326LonLatFormat(point, GeospatialUtil.EPSG_4326);
    assertThat(convertedGeometry.getCoordinates()[0].x, is(33.45));
    assertThat(convertedGeometry.getCoordinates()[0].y, is(25.22));
}
Also used : Geometry(com.vividsolutions.jts.geom.Geometry) GeometryFactory(com.vividsolutions.jts.geom.GeometryFactory) Coordinate(com.vividsolutions.jts.geom.Coordinate) Point(com.vividsolutions.jts.geom.Point) Test(org.junit.Test)

Example 19 with GeometryFactory

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

the class CswMarshallHelper method writeBoundingBox.

static void writeBoundingBox(HierarchicalStreamWriter writer, MarshallingContext context, Metacard metacard) {
    Set<AttributeDescriptor> attrDescs = metacard.getMetacardType().getAttributeDescriptors();
    List<Geometry> geometries = new LinkedList<>();
    for (AttributeDescriptor ad : attrDescs) {
        if (ad.getType() != null && AttributeType.AttributeFormat.GEOMETRY.equals(ad.getType().getAttributeFormat())) {
            Attribute attr = metacard.getAttribute(ad.getName());
            if (attr != null) {
                if (ad.isMultiValued()) {
                    for (Serializable value : attr.getValues()) {
                        geometries.add(XmlNode.readGeometry((String) value));
                    }
                } else {
                    geometries.add(XmlNode.readGeometry((String) attr.getValue()));
                }
            }
        }
    }
    Geometry allGeometry = new GeometryCollection(geometries.toArray(new Geometry[geometries.size()]), new GeometryFactory());
    Envelope bounds = allGeometry.getEnvelopeInternal();
    if (!bounds.isNull()) {
        String bbox = CswConstants.OWS_NAMESPACE_PREFIX + CswConstants.NAMESPACE_DELIMITER + CswConstants.OWS_BOUNDING_BOX;
        String lower = CswConstants.OWS_NAMESPACE_PREFIX + CswConstants.NAMESPACE_DELIMITER + CswConstants.OWS_LOWER_CORNER;
        String upper = CswConstants.OWS_NAMESPACE_PREFIX + CswConstants.NAMESPACE_DELIMITER + CswConstants.OWS_UPPER_CORNER;
        writer.startNode(bbox);
        writer.addAttribute(CswConstants.CRS, CswConstants.SRS_URL);
        writer.startNode(lower);
        writer.setValue(bounds.getMinX() + " " + bounds.getMinY());
        writer.endNode();
        writer.startNode(upper);
        writer.setValue(bounds.getMaxX() + " " + bounds.getMaxY());
        writer.endNode();
        writer.endNode();
    }
}
Also used : Geometry(com.vividsolutions.jts.geom.Geometry) GeometryCollection(com.vividsolutions.jts.geom.GeometryCollection) Serializable(java.io.Serializable) GeometryFactory(com.vividsolutions.jts.geom.GeometryFactory) Attribute(ddf.catalog.data.Attribute) AttributeDescriptor(ddf.catalog.data.AttributeDescriptor) Envelope(com.vividsolutions.jts.geom.Envelope) LinkedList(java.util.LinkedList)

Example 20 with GeometryFactory

use of com.vividsolutions.jts.geom.GeometryFactory in project graphhopper by graphhopper.

the class Utils method toWKT.

public static String toWKT(PointList list) {
    int n = list.size();
    GeometryFactory factory = new GeometryFactory();
    Coordinate[] coords = new Coordinate[n];
    for (int i = 0; i < coords.length; i++) {
        coords[i] = new Coordinate(list.getLon(i), list.getLat(i));
    }
    return factory.createLineString(coords).toText();
}
Also used : GeometryFactory(com.vividsolutions.jts.geom.GeometryFactory) Coordinate(com.vividsolutions.jts.geom.Coordinate)

Aggregations

GeometryFactory (com.vividsolutions.jts.geom.GeometryFactory)33 Coordinate (com.vividsolutions.jts.geom.Coordinate)27 Test (org.junit.Test)21 Geometry (com.vividsolutions.jts.geom.Geometry)13 SimpleFeature (org.opengis.feature.simple.SimpleFeature)12 ArrayList (java.util.ArrayList)10 Point (com.vividsolutions.jts.geom.Point)9 File (java.io.File)9 RevFeatureType (org.locationtech.geogig.api.RevFeatureType)8 Optional (com.google.common.base.Optional)7 SimpleFeatureBuilder (org.geotools.feature.simple.SimpleFeatureBuilder)7 RevFeature (org.locationtech.geogig.api.RevFeature)7 ImmutableList (com.google.common.collect.ImmutableList)6 List (java.util.List)6 AddOp (org.locationtech.geogig.api.porcelain.AddOp)6 SimpleFeatureType (org.opengis.feature.simple.SimpleFeatureType)5 CoordinateReferenceSystem (org.opengis.referencing.crs.CoordinateReferenceSystem)5 Envelope (com.vividsolutions.jts.geom.Envelope)4 IOException (java.io.IOException)4 Serializable (java.io.Serializable)4