use of org.opengis.feature.type.GeometryType in project activityinfo by bedatadriven.
the class ImportView method updateGeometry.
private void updateGeometry(GeoAdminClient client, Map<ResourceId, ResourceId> idMap) throws IOException {
FeatureSourceStorageProvider catalog = new FeatureSourceStorageProvider();
FeatureSourceStorage formStorage = (FeatureSourceStorage) catalog.getForm(getModel().getSourceFormId().get()).get();
ResourceId targetFormId = getModel().getTargetFormId().get();
FieldProfile targetField = getTargetProfile().get().getGeometryField();
if (targetField == null) {
System.err.println("No geometry field to update.");
return;
}
int sourceIndex = formStorage.getGeometryAttributeIndex();
if (sourceIndex == -1) {
System.err.println("No source geometry field.");
return;
}
SimpleFeatureSource featureSource = formStorage.getFeatureSource();
GeometryType geometryType = (GeometryType) featureSource.getSchema().getDescriptor(sourceIndex).getType();
GeometryConverter converter = new GeometryConverter(geometryType);
SimpleFeatureIterator it = featureSource.getFeatures().features();
while (it.hasNext()) {
SimpleFeature feature = it.next();
ResourceId sourceId = ResourceId.valueOf(feature.getID());
ResourceId targetId = idMap.get(sourceId);
if (targetId != null) {
Geometry geometry = converter.toWgs84(feature.getAttribute(sourceIndex));
System.out.print("Updating geometry for " + targetId + " [" + geometry.getGeometryType() + "] ... ");
try {
client.updateGeometry(targetFormId, targetId, targetField.getId(), geometry);
System.out.println("OK");
} catch (Exception e) {
System.out.println("ERROR: " + e.getMessage());
}
}
}
}
use of org.opengis.feature.type.GeometryType in project sldeditor by robward-scisys.
the class ExtendedSimpleFeatureTypeBuilder method createAttributeDescriptor.
/**
* Creates the attribute descriptor.
*
* @param name the name
* @param binding the binding
* @return the attribute descriptor
*/
public AttributeDescriptor createAttributeDescriptor(String name, Class<?> binding) {
AttributeDescriptor descriptor = null;
attributeBuilder.setBinding(binding);
attributeBuilder.setName(name);
//
if ((defaultGeometry != null && defaultGeometry.equals(name)) || Geometry.class.isAssignableFrom(binding)) {
// if no crs was set, set to defaultCRS
if (!attributeBuilder.isCRSSet()) {
if (defaultCrs == null && !defaultCrsSet) {
String message = String.format("Creating %s with null CoordinateReferenceSystem - did you mean to setCRS?", name);
LOGGER.fine(message);
}
attributeBuilder.setCRS(defaultCrs);
}
GeometryType type = attributeBuilder.buildGeometryType();
descriptor = attributeBuilder.buildDescriptor(name, type);
} else {
AttributeType type = attributeBuilder.buildType();
descriptor = attributeBuilder.buildDescriptor(name, type);
}
return (descriptor);
}
use of org.opengis.feature.type.GeometryType in project sldeditor by robward-scisys.
the class SLDEditorBufferedImageLegendGraphicBuilder method cloneWithDimensionality.
/**
* Clones the given schema, changing the geometry attribute to match the given dimensionality.
*
* @param schema schema to clone
* @param dimensionality dimensionality for the geometry 1= points, 2= lines, 3= polygons
*/
private FeatureType cloneWithDimensionality(FeatureType schema, int dimensionality) {
SimpleFeatureType simpleFt = (SimpleFeatureType) schema;
SimpleFeatureTypeBuilder builder = new SimpleFeatureTypeBuilder();
builder.setName(schema.getName());
builder.setCRS(schema.getCoordinateReferenceSystem());
for (AttributeDescriptor desc : simpleFt.getAttributeDescriptors()) {
if (isMixedGeometry(desc)) {
GeometryDescriptor geomDescriptor = (GeometryDescriptor) desc;
GeometryType geomType = geomDescriptor.getType();
Class<?> geometryClass = getGeometryForDimensionality(dimensionality);
GeometryType gt = new GeometryTypeImpl(geomType.getName(), geometryClass, geomType.getCoordinateReferenceSystem(), geomType.isIdentified(), geomType.isAbstract(), geomType.getRestrictions(), geomType.getSuper(), geomType.getDescription());
builder.add(new GeometryDescriptorImpl(gt, geomDescriptor.getName(), geomDescriptor.getMinOccurs(), geomDescriptor.getMaxOccurs(), geomDescriptor.isNillable(), geomDescriptor.getDefaultValue()));
} else {
builder.add(desc);
}
}
schema = builder.buildFeatureType();
return schema;
}
use of org.opengis.feature.type.GeometryType in project sldeditor by robward-scisys.
the class DataSourceInfo method getPropertyDescriptorList.
/**
* Gets the property descriptor list.
*
* @return the property descriptor list
*/
public Collection<PropertyDescriptor> getPropertyDescriptorList() {
if (schema != null) {
return schema.getDescriptors();
} else {
if (geometryType == GeometryTypeEnum.RASTER) {
if (rasterPropertyDescriptorList == null) {
rasterPropertyDescriptorList = new ArrayList<>();
CoordinateReferenceSystem crs = null;
boolean isIdentifiable = false;
boolean isAbstract = false;
List<Filter> restrictions = null;
AttributeType superType = null;
InternationalString description = null;
GeometryType type = featureTypeFactory.createGeometryType(new NameImpl(RASTER_GEOMETRY_FIELD), GridCoverage2D.class, crs, isIdentifiable, isAbstract, restrictions, superType, description);
GeometryDescriptor descriptor = featureTypeFactory.createGeometryDescriptor(type, new NameImpl(RASTER_GEOMETRY_FIELD), 0, 1, false, null);
rasterPropertyDescriptorList.add(descriptor);
}
return rasterPropertyDescriptorList;
}
}
return null;
}
use of org.opengis.feature.type.GeometryType in project sldeditor by robward-scisys.
the class VectorReader method createSLDData.
/**
* Creates the SLD data.
*
* @param map the map
* @return the styled layer descriptor
*/
private StyledLayerDescriptor createSLDData(Map<String, Object> map, String featureClass) {
StyledLayerDescriptor sld = null;
DataStore dataStore = null;
try {
dataStore = DataStoreFinder.getDataStore(map);
} catch (IOException e) {
ConsoleManager.getInstance().exception(this, e);
return null;
}
if (dataStore != null) {
// Try connecting to a vector data source
String typeName;
GeometryTypeEnum geometryTypeEnum = GeometryTypeEnum.UNKNOWN;
try {
if (featureClass == null) {
typeName = dataStore.getTypeNames()[0];
} else {
typeName = featureClass;
}
SimpleFeatureSource source = dataStore.getFeatureSource(typeName);
SimpleFeatureType schema = source.getSchema();
GeometryType geometryType = schema.getGeometryDescriptor().getType();
Class<?> bindingType = geometryType.getBinding();
geometryTypeEnum = GeometryTypeMapping.getGeometryType(bindingType);
} catch (IOException e) {
ConsoleManager.getInstance().exception(this, e);
return null;
} finally {
dataStore.dispose();
}
switch(geometryTypeEnum) {
case POINT:
sld = DefaultSymbols.createNewPoint();
break;
case LINE:
sld = DefaultSymbols.createNewLine();
break;
case POLYGON:
sld = DefaultSymbols.createNewPolygon();
break;
default:
break;
}
}
return sld;
}
Aggregations