use of org.opengis.feature.type.AttributeDescriptor in project polymap4-core by Polymap4.
the class UnitOfWork method isFeatureModified.
private boolean isFeatureModified(Feature feature, Feature original) throws IOException {
// XXX complex features
SimpleFeatureType schema = ((SimpleFeature) original).getType();
for (AttributeDescriptor attribute : schema.getAttributeDescriptors()) {
Object value1 = ((SimpleFeature) feature).getAttribute(attribute.getName());
Object value2 = ((SimpleFeature) original).getAttribute(attribute.getName());
if (isPropertyModified(value1, value2)) {
return true;
}
}
return false;
}
use of org.opengis.feature.type.AttributeDescriptor in project coastal-hazards by USGS-CIDA.
the class FeatureCollectionExport method writeToShapefile.
public boolean writeToShapefile() throws MalformedURLException, IOException {
boolean success = false;
// SimpleFeatureIterator features = simpleFeatureCollection.features();
SimpleFeatureType type = buildFeatureType();
FileDataStoreFactorySpi factory = FileDataStoreFinder.getDataStoreFactory("shp");
File shpFile = checkAndCreateFile();
Map datastoreConfig = new HashMap<>();
datastoreConfig.put("url", shpFile.toURI().toURL());
ShapefileDataStore shpfileDataStore = (ShapefileDataStore) factory.createNewDataStore(datastoreConfig);
shpfileDataStore.createSchema(type);
shpfileDataStore.forceSchemaCRS(this.crs);
// DataStore dataStore = factory.createNewDataStore(datastoreConfig);
SimpleFeatureStore featureStore = (SimpleFeatureStore) shpfileDataStore.getFeatureSource(type.getName());
Transaction t = new DefaultTransaction();
SimpleFeatureIterator fi = null;
try {
// Copied directly from Import process
featureStore.setTransaction(t);
fi = simpleFeatureCollection.features();
SimpleFeatureBuilder fb = new SimpleFeatureBuilder(type);
while (fi.hasNext()) {
SimpleFeature source = fi.next();
fb.reset();
for (AttributeDescriptor desc : type.getAttributeDescriptors()) {
Name attributeName = desc.getName();
Object attributeValue = source.getAttribute(attributeName);
if (null == attributeValue) {
attributeValue = NULL_PLACEHOLDER;
}
fb.set(attributeName, attributeValue);
}
SimpleFeature target = fb.buildFeature(null);
featureStore.addFeatures(DataUtilities.collection(target));
}
// successful if it made it this far
success = true;
} finally {
t.commit();
t.close();
IOUtils.closeQuietly(fi);
}
return success;
}
use of org.opengis.feature.type.AttributeDescriptor in project coastal-hazards by USGS-CIDA.
the class FeatureCollectionExport method buildFeatureType.
private SimpleFeatureType buildFeatureType() {
SimpleFeatureType featureType = null;
SimpleFeatureTypeBuilder builder = new SimpleFeatureTypeBuilder();
builder.setName(namePrefix);
builder.setCRS(this.crs);
builder.add(getGeometryDescriptor());
if (downloadAll) {
SimpleFeatureType unwrapped = GMLStreamingFeatureCollection.unwrapSchema(simpleFeatureCollection.getSchema());
List<AttributeDescriptor> attributeDescriptors = unwrapped.getAttributeDescriptors();
for (AttributeDescriptor attrDesc : attributeDescriptors) {
if (attrDesc != null && !IGNORE_LENGTH.equalsIgnoreCase(attrDesc.getLocalName())) {
builder.add(attrDesc);
}
}
} else {
for (String name : attributes) {
AttributeDescriptor descriptor = getDescriptorFromPrototype(name);
if (descriptor != null) {
builder.add(descriptor);
}
}
}
featureType = builder.buildFeatureType();
return featureType;
}
use of org.opengis.feature.type.AttributeDescriptor in project coastal-hazards by USGS-CIDA.
the class GMLStreamingFeatureCollection method unwrapSchema.
public static SimpleFeatureType unwrapSchema(SimpleFeatureType wrappedFeatureType) {
List<AttributeDescriptor> allowable = new ArrayList<>();
List<String> disallowed = new ArrayList<>();
disallowed.add("metaDataProperty");
disallowed.add("boundedBy");
disallowed.add("name");
disallowed.add("location");
disallowed.add("description");
disallowed.add("descriptio");
for (AttributeDescriptor desc : wrappedFeatureType.getAttributeDescriptors()) {
if (!disallowed.contains(desc.getLocalName())) {
allowable.add(desc);
}
}
SimpleFeatureType unwrapped = new SimpleFeatureTypeImpl(wrappedFeatureType.getName(), allowable, wrappedFeatureType.getGeometryDescriptor(), wrappedFeatureType.isAbstract(), wrappedFeatureType.getRestrictions(), wrappedFeatureType.getSuper(), wrappedFeatureType.getDescription());
return unwrapped;
}
use of org.opengis.feature.type.AttributeDescriptor in project coastal-hazards by USGS-CIDA.
the class FeatureCollectionExportTest method testHttpComponentsGetter.
@Test
@Ignore
public void testHttpComponentsGetter() throws Exception {
HttpComponentsWFSClient wfs = new HttpComponentsWFSClient();
wfs.setupDatastoreFromEndpoint("http://cida-wiwsc-cchdev:8081/geoserver/wfs");
// FilterFactory filterFactory = CommonFactoryFinder.getFilterFactory(GeoTools.getDefaultHints());
SimpleFeatureCollection featureCollection = wfs.getFeatureCollection("proxied:atl_cvi", null);
SimpleFeatureType schema = GMLStreamingFeatureCollection.unwrapSchema(featureCollection.getSchema());
FileDataStoreFactorySpi factory = FileDataStoreFinder.getDataStoreFactory("shp");
Map datastoreConfig = new HashMap<>();
datastoreConfig.put("url", FileUtils.getFile(FileUtils.getTempDirectory(), "test3.shp").toURI().toURL());
ShapefileDataStore shpfileDataStore = (ShapefileDataStore) factory.createNewDataStore(datastoreConfig);
shpfileDataStore.createSchema(schema);
shpfileDataStore.forceSchemaCRS(DefaultGeographicCRS.WGS84);
SimpleFeatureStore featureStore = (SimpleFeatureStore) shpfileDataStore.getFeatureSource();
Transaction t = new DefaultTransaction();
// Copied directly from Import process
featureStore.setTransaction(t);
Query query = new Query();
query.setCoordinateSystem(DefaultGeographicCRS.WGS84);
SimpleFeatureIterator fi = featureCollection.features();
SimpleFeatureBuilder fb = new SimpleFeatureBuilder(schema);
while (fi.hasNext()) {
SimpleFeature source = fi.next();
fb.reset();
for (AttributeDescriptor desc : schema.getAttributeDescriptors()) {
fb.set(desc.getName(), source.getAttribute(desc.getName()));
}
SimpleFeature target = fb.buildFeature(null);
target.setDefaultGeometry(source.getDefaultGeometry());
featureStore.addFeatures(DataUtilities.collection(target));
}
t.commit();
t.close();
}
Aggregations