Search in sources :

Example 21 with AttributeDescriptor

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

the class FormatCommonV1 method readFeatureType.

public static RevFeatureType readFeatureType(ObjectId id, DataInput in, FeatureTypeFactory typeFactory) throws IOException {
    Name name = readName(in);
    int propertyCount = in.readInt();
    List<AttributeDescriptor> attributes = new ArrayList<AttributeDescriptor>();
    for (int i = 0; i < propertyCount; i++) {
        attributes.add(readAttributeDescriptor(in, typeFactory));
    }
    SimpleFeatureType ftype = typeFactory.createSimpleFeatureType(name, attributes, null, false, Collections.<Filter>emptyList(), BasicFeatureTypes.FEATURE, null);
    return new RevFeatureTypeImpl(id, ftype);
}
Also used : RevFeatureTypeImpl(org.locationtech.geogig.api.RevFeatureTypeImpl) SimpleFeatureType(org.opengis.feature.simple.SimpleFeatureType) ArrayList(java.util.ArrayList) AttributeDescriptor(org.opengis.feature.type.AttributeDescriptor) Name(org.opengis.feature.type.Name)

Example 22 with AttributeDescriptor

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

the class MappingRule method apply.

/**
     * Returns the feature resulting from transforming a given feature using this rule. This method
     * takes a collection of tags, so there is no need to compute them from the 'tags' attribute.
     * This is meant as a faster alternative to the apply(Feature) method, in case the mapping
     * object calling this has already computed the tags, to avoid recomputing them
     * 
     * @param feature
     * @param tags
     * @return
     */
public Optional<Feature> apply(Feature feature, Collection<Tag> tags) {
    if (!canBeApplied(feature, tags)) {
        return Optional.absent();
    }
    for (AttributeDescriptor attribute : getFeatureType().getAttributeDescriptors()) {
        String attrName = attribute.getName().toString();
        Class<?> clazz = attribute.getType().getBinding();
        if (Geometry.class.isAssignableFrom(clazz)) {
            Geometry geom = prepareGeometry((Geometry) feature.getDefaultGeometryProperty().getValue());
            if (geom == null) {
                return Optional.absent();
            }
            featureBuilder.set(attrName, geom);
        } else {
            Object value = null;
            for (Tag tag : tags) {
                if (fields.containsKey(tag.getKey())) {
                    if (fields.get(tag.getKey()).getName().equals(attrName)) {
                        FieldType type = FieldType.forBinding(clazz);
                        value = getAttributeValue(tag.getValue(), type);
                        break;
                    }
                }
            }
            featureBuilder.set(attribute.getName(), value);
        }
    }
    String id = feature.getIdentifier().getID();
    featureBuilder.set("id", id);
    if (defaultFields != null) {
        for (DefaultField df : defaultFields) {
            featureBuilder.set(df.name(), feature.getProperty(df.name()).getValue());
        }
    }
    if (!featureType.getGeometryDescriptor().getType().getBinding().equals(Point.class)) {
        featureBuilder.set("nodes", feature.getProperty("nodes").getValue());
    }
    return Optional.of((Feature) featureBuilder.buildFeature(id));
}
Also used : Geometry(com.vividsolutions.jts.geom.Geometry) AttributeDescriptor(org.opengis.feature.type.AttributeDescriptor) Tag(org.openstreetmap.osmosis.core.domain.v0_6.Tag) Point(com.vividsolutions.jts.geom.Point) FieldType(org.locationtech.geogig.storage.FieldType)

Example 23 with AttributeDescriptor

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

the class FeatureSourceStorage method getFormClass.

@Override
public FormClass getFormClass() {
    FormClass formClass = new FormClass(resourceId);
    formClass.setLabel(featureSource.getName().getLocalPart());
    List<AttributeDescriptor> attributes = featureSource.getSchema().getAttributeDescriptors();
    for (int i = 0; i < attributes.size(); i++) {
        AttributeDescriptor attribute = attributes.get(i);
        formClass.addElement(toField(i, attribute));
    }
    return formClass;
}
Also used : FormClass(org.activityinfo.model.form.FormClass) AttributeDescriptor(org.opengis.feature.type.AttributeDescriptor)

Example 24 with AttributeDescriptor

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

Example 25 with AttributeDescriptor

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

the class UnitOfWork method checkSubmitModified.

// public void revert( IProgressMonitor monitor ) {
// revert( Filter.INCLUDE, monitor );
// }
// 
// 
// /**
// *
// * @param filter Specifies what features to revert. null for all features.
// * @param monitor
// */
// public void revert( Filter filter, IProgressMonitor monitor ) {
// assert filter != null;
// monitor.beginTask( getLabel() + " revert", modified.size() );
// 
// List<Feature> reverted = new ArrayList( modified.size() );
// 
// for (FeatureBufferState buffered : modified.values()) {
// if (filter.evaluate( buffered.original() )) {
// buffer.unregisterFeatures( Collections.singletonList( buffered.feature() ) );
// reverted.add( buffered.feature() );
// }
// monitor.worked( 1 );
// }
// fireFeatureChangeEvent( FeatureChangeEvent.Type.FLUSHED, reverted );
// 
// monitor.done();
// }
/**
 * Check concurrent modifications with the store.
 */
protected void checkSubmitModified(FeatureBufferState buffered) throws ConcurrentModificationException, IOException {
    FeatureId fid = buffered.feature().getIdentifier();
    Id fidFilter = ff.id(Collections.singleton(fid));
    // check concurrent modification
    Feature[] stored = (Feature[]) fs.getFeatures(fidFilter).toArray(new Feature[1]);
    if (stored.length == 0) {
        throw new ConcurrentModificationException("Feature has been removed concurrently: " + fid);
    } else if (stored.length > 1) {
        throw new IllegalStateException("More than one feature for id: " + fid + "!?");
    }
    if (isFeatureModified(stored[0], buffered.original())) {
        throw new ConcurrentModificationException("Objekt wurde von einem anderen Nutzer gleichzeitig ge�ndert: " + fid);
    }
    // write down
    AttributeDescriptor[] type = {};
    Object[] value = {};
    for (Property origProp : buffered.original().getProperties()) {
        if (origProp.getDescriptor() instanceof AttributeDescriptor) {
            Property newProp = buffered.feature().getProperty(origProp.getName());
            if (isPropertyModified(origProp.getValue(), newProp.getValue())) {
                type = (AttributeDescriptor[]) ArrayUtils.add(type, origProp.getDescriptor());
                value = ArrayUtils.add(value, newProp.getValue());
                log.info("Attribute modified: " + origProp.getDescriptor().getName() + " = " + newProp.getValue() + " (" + fid.getID() + ")");
            }
        }
    }
    fs.modifyFeatures(type, value, fidFilter);
}
Also used : FeatureId(org.opengis.filter.identity.FeatureId) ConcurrentModificationException(java.util.ConcurrentModificationException) AttributeDescriptor(org.opengis.feature.type.AttributeDescriptor) FeatureId(org.opengis.filter.identity.FeatureId) Id(org.opengis.filter.Id) SimpleFeature(org.opengis.feature.simple.SimpleFeature) Feature(org.opengis.feature.Feature) Property(org.opengis.feature.Property)

Aggregations

AttributeDescriptor (org.opengis.feature.type.AttributeDescriptor)40 SimpleFeatureType (org.opengis.feature.simple.SimpleFeatureType)22 SimpleFeature (org.opengis.feature.simple.SimpleFeature)10 SimpleFeatureTypeBuilder (org.geotools.feature.simple.SimpleFeatureTypeBuilder)9 ArrayList (java.util.ArrayList)8 SimpleFeatureIterator (org.geotools.data.simple.SimpleFeatureIterator)8 SimpleFeatureStore (org.geotools.data.simple.SimpleFeatureStore)7 HashMap (java.util.HashMap)6 ShapefileDataStore (org.geotools.data.shapefile.ShapefileDataStore)6 SimpleFeatureCollection (org.geotools.data.simple.SimpleFeatureCollection)6 SimpleFeatureSource (org.geotools.data.simple.SimpleFeatureSource)6 IOException (java.io.IOException)5 SimpleFeatureBuilder (org.geotools.feature.simple.SimpleFeatureBuilder)5 Test (org.junit.Test)5 File (java.io.File)4 Map (java.util.Map)4 DefaultTransaction (org.geotools.data.DefaultTransaction)4 FileDataStoreFactorySpi (org.geotools.data.FileDataStoreFactorySpi)4 Transaction (org.geotools.data.Transaction)4 GeometryDescriptor (org.opengis.feature.type.GeometryDescriptor)4