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