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;
}
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);
}
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));
}
Aggregations