Search in sources :

Example 16 with GeometryDescriptor

use of org.opengis.feature.type.GeometryDescriptor in project GeoGig by boundlessgeo.

the class FeatureTypeAdapterFeatureSource method getFeatures.

@Override
public FeatureCollection<T, F> getFeatures(Query query) throws IOException {
    final FeatureCollection<T, F> features = super.getFeatures(query);
    return new ForwardingFeatureCollection<T, F>(features) {

        @Override
        public FeatureIterator<F> features() {
            if (delegate.getSchema().getDescriptors().size() != featureType.getDescriptors().size()) {
                throw new GeoToolsOpException(GeoToolsOpException.StatusCode.INCOMPATIBLE_FEATURE_TYPE);
            }
            GeometryDescriptor geomDescriptorOrg = delegate.getSchema().getGeometryDescriptor();
            GeometryDescriptor geomDescriptorDest = featureType.getGeometryDescriptor();
            if (!geomDescriptorOrg.getType().getBinding().equals(geomDescriptorDest.getType().getBinding()) || !geomDescriptorOrg.getType().getCoordinateReferenceSystem().equals(geomDescriptorDest.getType().getCoordinateReferenceSystem())) {
                throw new GeoToolsOpException(GeoToolsOpException.StatusCode.INCOMPATIBLE_FEATURE_TYPE);
            }
            FeatureIterator<F> iterator = delegate.features();
            SimpleFeatureBuilder builder = new SimpleFeatureBuilder((SimpleFeatureType) featureType);
            return new FeatureTypeConverterIterator<F>(iterator, (SimpleFeatureBuilder) builder);
        }

        @Override
        public T getSchema() {
            return featureType;
        }
    };
}
Also used : GeometryDescriptor(org.opengis.feature.type.GeometryDescriptor) ForwardingFeatureCollection(org.locationtech.geogig.api.data.ForwardingFeatureCollection) SimpleFeatureBuilder(org.geotools.feature.simple.SimpleFeatureBuilder)

Example 17 with GeometryDescriptor

use of org.opengis.feature.type.GeometryDescriptor in project GeoGig by boundlessgeo.

the class HashObjectTest method feature.

protected Feature feature(SimpleFeatureType type, String id, Object... values) throws ParseException {
    SimpleFeatureBuilder builder = new SimpleFeatureBuilder(type);
    for (int i = 0; i < values.length; i++) {
        Object value = values[i];
        if (type.getDescriptor(i) instanceof GeometryDescriptor) {
            if (value instanceof String) {
                value = new WKTReader2().read((String) value);
            }
        }
        builder.set(i, value);
    }
    return builder.buildFeature(id);
}
Also used : GeometryDescriptor(org.opengis.feature.type.GeometryDescriptor) WKTReader2(org.geotools.geometry.jts.WKTReader2) SimpleFeatureBuilder(org.geotools.feature.simple.SimpleFeatureBuilder)

Example 18 with GeometryDescriptor

use of org.opengis.feature.type.GeometryDescriptor in project GeoGig by boundlessgeo.

the class OSMExportSL method getOriginTreesFromOutputFeatureType.

private String getOriginTreesFromOutputFeatureType(SimpleFeatureType featureType) {
    GeometryDescriptor descriptor = featureType.getGeometryDescriptor();
    Class<?> clazz = descriptor.getType().getBinding();
    if (clazz.equals(Point.class)) {
        return "node";
    } else {
        return "way";
    }
}
Also used : GeometryDescriptor(org.opengis.feature.type.GeometryDescriptor)

Example 19 with GeometryDescriptor

use of org.opengis.feature.type.GeometryDescriptor in project activityinfo by bedatadriven.

the class ImportSource method createTransform.

private MathTransform createTransform() throws Exception {
    GeometryDescriptor geometryType = featureSource.getSchema().getGeometryDescriptor();
    CoordinateReferenceSystem sourceCrs = geometryType.getCoordinateReferenceSystem();
    if (sourceCrs == null) {
        // if it's not WGS84, we'll soon find out as we check the geometry against the
        // country bounds
        sourceCrs = DefaultGeographicCRS.WGS84;
    }
    CoordinateReferenceSystem geoCRS = DefaultGeographicCRS.WGS84;
    // allow for some error due to different datums
    boolean lenient = true;
    return CRS.findMathTransform(sourceCrs, geoCRS, lenient);
}
Also used : GeometryDescriptor(org.opengis.feature.type.GeometryDescriptor) CoordinateReferenceSystem(org.opengis.referencing.crs.CoordinateReferenceSystem)

Example 20 with GeometryDescriptor

use of org.opengis.feature.type.GeometryDescriptor in project polymap4-core by Polymap4.

the class FilterUtils method createBBoxFilters.

/**
 * Creates the bounding box filters (one for each geometric attribute)
 * needed to query a <code>MapLayer</code>'s feature source to return just
 * the features for the target rendering extent
 *
 * @param schema the layer's feature source schema
 * @param attributes set of needed attributes or null.
 * @param bbox the expression holding the target rendering bounding box
 * @return an or'ed list of bbox filters, one for each geometric attribute
 *         in <code>attributes</code>. If there are just one geometric
 *         attribute, just returns its corresponding
 *         <code>GeometryFilter</code>.
 * @throws IllegalFilterException if something goes wrong creating the
 *         filter
 */
public static Filter createBBoxFilters(SimpleFeatureType schema, String[] attributes, Envelope bbox) throws IllegalFilterException {
    if (attributes == null) {
        List<AttributeDescriptor> ats = schema.getAttributeDescriptors();
        int length = ats.size();
        attributes = new String[length];
        for (int t = 0; t < length; t++) {
            attributes[t] = ats.get(t).getLocalName();
        }
    }
    Filter filter = Filter.INCLUDE;
    for (int j = 0; j < attributes.length; j++) {
        AttributeDescriptor attType = schema.getDescriptor(attributes[j]);
        if (attType == null) {
            throw new IllegalFilterException(new StringBuffer("Could not find '").append(attributes[j] + "' in the FeatureType (").append(schema.getTypeName()).append(")").toString());
        }
        if (attType instanceof GeometryDescriptor) {
            BBOX gfilter = filterFactory.bbox(attType.getLocalName(), bbox.getMinX(), bbox.getMinY(), bbox.getMaxX(), bbox.getMaxY(), null);
            if (filter == Filter.INCLUDE) {
                filter = gfilter;
            } else {
                filter = filterFactory.or(filter, gfilter);
            }
        }
    }
    return filter;
}
Also used : GeometryDescriptor(org.opengis.feature.type.GeometryDescriptor) Filter(org.opengis.filter.Filter) BBOX(org.opengis.filter.spatial.BBOX) AttributeDescriptor(org.opengis.feature.type.AttributeDescriptor) IllegalFilterException(org.geotools.filter.IllegalFilterException)

Aggregations

GeometryDescriptor (org.opengis.feature.type.GeometryDescriptor)24 SimpleFeatureBuilder (org.geotools.feature.simple.SimpleFeatureBuilder)6 WKTReader2 (org.geotools.geometry.jts.WKTReader2)5 AttributeDescriptor (org.opengis.feature.type.AttributeDescriptor)5 PropertyDescriptor (org.opengis.feature.type.PropertyDescriptor)5 IOException (java.io.IOException)4 ArrayList (java.util.ArrayList)3 HashMap (java.util.HashMap)3 Test (org.junit.jupiter.api.Test)3 Filter (org.opengis.filter.Filter)3 SLDEditorMain (com.sldeditor.SLDEditorMain)2 DataSourceInterface (com.sldeditor.datasource.DataSourceInterface)2 SLDEditorFile (com.sldeditor.datasource.SLDEditorFile)2 CheckAttributeInterface (com.sldeditor.datasource.checks.CheckAttributeInterface)2 WindowEvent (java.awt.event.WindowEvent)2 File (java.io.File)2 FileInputStream (java.io.FileInputStream)2 FileNotFoundException (java.io.FileNotFoundException)2 InputStream (java.io.InputStream)2 Path (java.nio.file.Path)2