Search in sources :

Example 11 with AttributeDescriptor

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

the class ExportDiffOp method addFidAttribute.

private static SimpleFeatureType addFidAttribute(RevFeatureType revFType) {
    SimpleFeatureType featureType = (SimpleFeatureType) revFType.type();
    SimpleFeatureTypeBuilder builder = new SimpleFeatureTypeBuilder();
    builder.add("geogig_fid", String.class);
    for (AttributeDescriptor descriptor : featureType.getAttributeDescriptors()) {
        builder.add(descriptor);
    }
    builder.setName(featureType.getName());
    builder.setCRS(featureType.getCoordinateReferenceSystem());
    featureType = builder.buildFeatureType();
    return featureType;
}
Also used : SimpleFeatureTypeBuilder(org.geotools.feature.simple.SimpleFeatureTypeBuilder) SimpleFeatureType(org.opengis.feature.simple.SimpleFeatureType) AttributeDescriptor(org.opengis.feature.type.AttributeDescriptor)

Example 12 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 13 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)

Aggregations

AttributeDescriptor (org.opengis.feature.type.AttributeDescriptor)13 SimpleFeatureType (org.opengis.feature.simple.SimpleFeatureType)8 SimpleFeatureTypeBuilder (org.geotools.feature.simple.SimpleFeatureTypeBuilder)6 SimpleFeatureSource (org.geotools.data.simple.SimpleFeatureSource)3 SimpleFeatureStore (org.geotools.data.simple.SimpleFeatureStore)3 CommandFailedException (org.locationtech.geogig.cli.CommandFailedException)3 InvalidParameterException (org.locationtech.geogig.cli.InvalidParameterException)3 GeoToolsOpException (org.locationtech.geogig.geotools.plumbing.GeoToolsOpException)3 Feature (org.opengis.feature.Feature)3 Point (com.vividsolutions.jts.geom.Point)2 ArrayList (java.util.ArrayList)2 DataStore (org.geotools.data.DataStore)2 MemoryDataStore (org.geotools.data.memory.MemoryDataStore)2 SimpleFeatureCollection (org.geotools.data.simple.SimpleFeatureCollection)2 SimpleFeatureIterator (org.geotools.data.simple.SimpleFeatureIterator)2 Test (org.junit.Test)2 ProgressListener (org.locationtech.geogig.api.ProgressListener)2 RevCommit (org.locationtech.geogig.api.RevCommit)2 RevFeatureType (org.locationtech.geogig.api.RevFeatureType)2 RevFeatureTypeImpl (org.locationtech.geogig.api.RevFeatureTypeImpl)2