Search in sources :

Example 1 with GeometryAttribute

use of org.opengis.feature.GeometryAttribute in project GeoGig by boundlessgeo.

the class GeogigSimpleFeature method getDefaultGeometryProperty.

@Override
public GeometryAttribute getDefaultGeometryProperty() {
    GeometryDescriptor geometryDescriptor = featureType.getGeometryDescriptor();
    GeometryAttribute geometryAttribute = null;
    if (geometryDescriptor != null) {
        Object defaultGeometry = getDefaultGeometry();
        geometryAttribute = new GeometryAttributeImpl(defaultGeometry, geometryDescriptor, null);
    }
    return geometryAttribute;
}
Also used : GeometryDescriptor(org.opengis.feature.type.GeometryDescriptor) GeometryAttribute(org.opengis.feature.GeometryAttribute) GeometryAttributeImpl(org.geotools.feature.GeometryAttributeImpl)

Example 2 with GeometryAttribute

use of org.opengis.feature.GeometryAttribute 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)

Example 3 with GeometryAttribute

use of org.opengis.feature.GeometryAttribute in project ddf by codice.

the class TestPubSubOgcFilter method generateSampleFeature.

private SimpleFeature generateSampleFeature() {
    SimpleFeatureTypeBuilder b = new SimpleFeatureTypeBuilder();
    b.setName("PubSubFeature");
    // add properties
    b.add("name", String.class);
    b.add("classification", Integer.class);
    b.add("height", Double.class);
    com.vividsolutions.jts.geom.GeometryFactory geoFactory = JTSFactoryFinder.getGeometryFactory(null);
    // add geo
    b.setCRS(DefaultGeographicCRS.WGS84);
    b.add("geo", Point.class);
    final SimpleFeatureType pubSubFeature = b.buildFeatureType();
    SimpleFeatureBuilder featureBuilder = new SimpleFeatureBuilder(pubSubFeature);
    featureBuilder.set("name", "FirstFeature");
    featureBuilder.set("classification", 10);
    featureBuilder.set("height", 5.8);
    com.vividsolutions.jts.geom.Point point = geoFactory.createPoint(new Coordinate(-112, 28));
    featureBuilder.set("geo", point);
    SimpleFeature feature = featureBuilder.buildFeature("f1");
    // it looks like if I add an attribute into the feature that is of geometry type, it
    // automatically
    // becomes the default geo property. If no geo is specified, getDefaultGeometryProperty
    // returns null
    GeometryAttribute defaultGeo = feature.getDefaultGeometryProperty();
    LOGGER.debug("geo name: {}", defaultGeo.getName());
    LOGGER.debug("geo: {}", defaultGeo);
    return feature;
}
Also used : SimpleFeatureTypeBuilder(org.geotools.feature.simple.SimpleFeatureTypeBuilder) SimpleFeatureType(org.opengis.feature.simple.SimpleFeatureType) Coordinate(com.vividsolutions.jts.geom.Coordinate) GeometryAttribute(org.opengis.feature.GeometryAttribute) Point(com.vividsolutions.jts.geom.Point) SimpleFeature(org.opengis.feature.simple.SimpleFeature) SimpleFeatureBuilder(org.geotools.feature.simple.SimpleFeatureBuilder)

Example 4 with GeometryAttribute

use of org.opengis.feature.GeometryAttribute in project GeoGig by boundlessgeo.

the class ShpExport method getTransformingFunction.

private Function<Feature, Optional<Feature>> getTransformingFunction(final SimpleFeatureType featureType) {
    Function<Feature, Optional<Feature>> function = new Function<Feature, Optional<Feature>>() {

        @Override
        @Nullable
        public Optional<Feature> apply(@Nullable Feature feature) {
            SimpleFeatureBuilder builder = new SimpleFeatureBuilder(featureType);
            for (Property property : feature.getProperties()) {
                if (property instanceof GeometryAttribute) {
                    builder.set(featureType.getGeometryDescriptor().getName(), property.getValue());
                } else {
                    String name = property.getName().getLocalPart();
                    if (name.length() > 10) {
                        name = name.substring(0, 10);
                    }
                    builder.set(name, property.getValue());
                }
            }
            Feature modifiedFeature = builder.buildFeature(feature.getIdentifier().getID());
            return Optional.fromNullable(modifiedFeature);
        }
    };
    return function;
}
Also used : Function(com.google.common.base.Function) Optional(com.google.common.base.Optional) GeometryAttribute(org.opengis.feature.GeometryAttribute) Feature(org.opengis.feature.Feature) Property(org.opengis.feature.Property) Nullable(javax.annotation.Nullable) SimpleFeatureBuilder(org.geotools.feature.simple.SimpleFeatureBuilder)

Example 5 with GeometryAttribute

use of org.opengis.feature.GeometryAttribute in project GeoGig by boundlessgeo.

the class ShpExportDiff method getTransformingFunction.

private Function<Feature, Optional<Feature>> getTransformingFunction(final SimpleFeatureType featureType) {
    Function<Feature, Optional<Feature>> function = new Function<Feature, Optional<Feature>>() {

        @Override
        @Nullable
        public Optional<Feature> apply(@Nullable Feature feature) {
            SimpleFeatureBuilder builder = new SimpleFeatureBuilder(featureType);
            for (Property property : feature.getProperties()) {
                if (property instanceof GeometryAttribute) {
                    builder.set(featureType.getGeometryDescriptor().getName(), property.getValue());
                } else {
                    builder.set(property.getName(), property.getValue());
                }
            }
            Feature modifiedFeature = builder.buildFeature(feature.getIdentifier().getID());
            return Optional.fromNullable(modifiedFeature);
        }
    };
    return function;
}
Also used : Function(com.google.common.base.Function) Optional(com.google.common.base.Optional) GeometryAttribute(org.opengis.feature.GeometryAttribute) Feature(org.opengis.feature.Feature) Property(org.opengis.feature.Property) Nullable(javax.annotation.Nullable) SimpleFeatureBuilder(org.geotools.feature.simple.SimpleFeatureBuilder)

Aggregations

GeometryAttribute (org.opengis.feature.GeometryAttribute)7 Feature (org.opengis.feature.Feature)4 SimpleFeatureBuilder (org.geotools.feature.simple.SimpleFeatureBuilder)3 Property (org.opengis.feature.Property)3 Function (com.google.common.base.Function)2 Optional (com.google.common.base.Optional)2 Coordinate (com.vividsolutions.jts.geom.Coordinate)2 Geometry (com.vividsolutions.jts.geom.Geometry)2 IOException (java.io.IOException)2 ArrayList (java.util.ArrayList)2 Nullable (javax.annotation.Nullable)2 SimpleFeature (org.opengis.feature.simple.SimpleFeature)2 Point (com.vividsolutions.jts.geom.Point)1 Polygon (com.vividsolutions.jts.geom.Polygon)1 Area (java.awt.geom.Area)1 FileNotFoundException (java.io.FileNotFoundException)1 URISyntaxException (java.net.URISyntaxException)1 CountDownLatch (java.util.concurrent.CountDownLatch)1 GeometryAttributeImpl (org.geotools.feature.GeometryAttributeImpl)1 SimpleFeatureTypeBuilder (org.geotools.feature.simple.SimpleFeatureTypeBuilder)1