Search in sources :

Example 36 with Geometry

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

the class WfsFilterDelegate method bufferGeometry.

private String bufferGeometry(String wkt, double distance) {
    LOGGER.debug("Buffering WKT {} by distance {} meter(s).", wkt, distance);
    String bufferedWkt = null;
    try {
        Geometry geometry = getGeometryFromWkt(wkt);
        double bufferInDegrees = metersToDegrees(distance);
        LOGGER.debug("Buffering {} by {} degree(s).", geometry.getClass().getSimpleName(), bufferInDegrees);
        Geometry bufferedGeometry = geometry.buffer(bufferInDegrees);
        bufferedWkt = new WKTWriter().write(bufferedGeometry);
        LOGGER.debug("Buffered WKT: {}.", bufferedWkt);
    } catch (ParseException e) {
        throw new IllegalArgumentException("Unable to parse WKT String", e);
    }
    return bufferedWkt;
}
Also used : Geometry(com.vividsolutions.jts.geom.Geometry) WKTWriter(com.vividsolutions.jts.io.WKTWriter) LineString(com.vividsolutions.jts.geom.LineString) MultiLineString(com.vividsolutions.jts.geom.MultiLineString) ParseException(com.vividsolutions.jts.io.ParseException)

Example 37 with Geometry

use of com.vividsolutions.jts.geom.Geometry 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 38 with Geometry

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

the class GeometrySerializer method write.

@Override
public void write(Object obj, final DataOutput out) throws IOException {
    final Geometry geom = (Geometry) obj;
    final int geometryType = getGeometryType(geom);
    final int typeAndMasks = geometryType;
    writeUnsignedVarInt(typeAndMasks, out);
    geom.apply(new EncodingSequenceFilter(out, true));
}
Also used : Geometry(com.vividsolutions.jts.geom.Geometry) Point(com.vividsolutions.jts.geom.Point) MultiPoint(com.vividsolutions.jts.geom.MultiPoint)

Example 39 with Geometry

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

the class ResponseWriter method writeMerged.

/**
     * Writes the response for a set of merged features while also supplying the geometry.
     * 
     * @param geogig - a CommandLocator to call commands from
     * @param features - a FeatureInfo iterator to build the response from
     * @throws XMLStreamException
     */
public void writeMerged(final Context geogig, Iterator<FeatureInfo> features) throws XMLStreamException {
    Iterator<GeometryChange> changeIterator = Iterators.transform(features, new Function<FeatureInfo, GeometryChange>() {

        @Override
        public GeometryChange apply(FeatureInfo input) {
            GeometryChange change = null;
            RevFeature revFeature = RevFeatureBuilder.build(input.getFeature());
            RevFeatureType featureType = input.getFeatureType();
            Collection<PropertyDescriptor> attribs = featureType.type().getDescriptors();
            String crsCode = null;
            for (PropertyDescriptor attrib : attribs) {
                PropertyType attrType = attrib.getType();
                if (attrType instanceof GeometryType) {
                    GeometryType gt = (GeometryType) attrType;
                    CoordinateReferenceSystem crs = gt.getCoordinateReferenceSystem();
                    if (crs != null) {
                        try {
                            crsCode = CRS.lookupIdentifier(Citations.EPSG, crs, false);
                        } catch (FactoryException e) {
                            crsCode = null;
                        }
                        if (crsCode != null) {
                            crsCode = "EPSG:" + crsCode;
                        }
                    }
                    break;
                }
            }
            FeatureBuilder builder = new FeatureBuilder(featureType);
            GeogigSimpleFeature simpleFeature = (GeogigSimpleFeature) builder.build(revFeature.getId().toString(), revFeature);
            change = new GeometryChange(simpleFeature, ChangeType.MODIFIED, input.getPath(), crsCode);
            return change;
        }
    });
    while (changeIterator.hasNext()) {
        GeometryChange next = changeIterator.next();
        if (next != null) {
            GeogigSimpleFeature feature = next.getFeature();
            out.writeStartElement("Feature");
            writeElement("change", "MERGED");
            writeElement("id", next.getPath());
            List<Object> attributes = feature.getAttributes();
            for (Object attribute : attributes) {
                if (attribute instanceof Geometry) {
                    writeElement("geometry", ((Geometry) attribute).toText());
                    break;
                }
            }
            if (next.getCRS() != null) {
                writeElement("crs", next.getCRS());
            }
            out.writeEndElement();
        }
    }
}
Also used : FeatureBuilder(org.locationtech.geogig.api.FeatureBuilder) RevFeatureBuilder(org.locationtech.geogig.api.RevFeatureBuilder) PropertyDescriptor(org.opengis.feature.type.PropertyDescriptor) FactoryException(org.opengis.referencing.FactoryException) FeatureInfo(org.locationtech.geogig.api.FeatureInfo) PropertyType(org.opengis.feature.type.PropertyType) Geometry(com.vividsolutions.jts.geom.Geometry) GeometryType(org.opengis.feature.type.GeometryType) RevFeature(org.locationtech.geogig.api.RevFeature) Collection(java.util.Collection) RevObject(org.locationtech.geogig.api.RevObject) CoordinateReferenceSystem(org.opengis.referencing.crs.CoordinateReferenceSystem) GeogigSimpleFeature(org.locationtech.geogig.api.GeogigSimpleFeature) RevFeatureType(org.locationtech.geogig.api.RevFeatureType)

Example 40 with Geometry

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

Geometry (com.vividsolutions.jts.geom.Geometry)125 WKTReader (com.vividsolutions.jts.io.WKTReader)35 Test (org.junit.Test)31 Coordinate (com.vividsolutions.jts.geom.Coordinate)24 Point (com.vividsolutions.jts.geom.Point)21 ParseException (com.vividsolutions.jts.io.ParseException)19 GeometryFactory (com.vividsolutions.jts.geom.GeometryFactory)14 CoordinateReferenceSystem (org.opengis.referencing.crs.CoordinateReferenceSystem)14 Envelope (com.vividsolutions.jts.geom.Envelope)13 WKTWriter (com.vividsolutions.jts.io.WKTWriter)13 ArrayList (java.util.ArrayList)13 LineString (com.vividsolutions.jts.geom.LineString)10 MultiPoint (com.vividsolutions.jts.geom.MultiPoint)9 Metacard (ddf.catalog.data.Metacard)9 SimpleFeature (org.opengis.feature.simple.SimpleFeature)7 Optional (com.google.common.base.Optional)6 IOException (java.io.IOException)6 RevFeature (org.locationtech.geogig.api.RevFeature)6 JtsGeometry (org.locationtech.spatial4j.shape.jts.JtsGeometry)6 GeometryCollection (com.vividsolutions.jts.geom.GeometryCollection)5