use of org.geotools.feature.type.GeometryTypeImpl in project sldeditor by robward-scisys.
the class CreateSampleData method create.
/**
* Creates the sample data from the supplied schema.
*
* @param schema the schema
* @param fieldList the field list
*/
public void create(FeatureType schema, List<DataSourceAttributeData> fieldList) {
if (schema == null) {
return;
}
// Put fields into map for speed
Map<String, DataSourceAttributeData> fieldMap = new HashMap<String, DataSourceAttributeData>();
if (fieldList != null) {
for (DataSourceAttributeData attributeData : fieldList) {
fieldMap.put(attributeData.getName(), attributeData);
}
}
SimpleFeatureType featureType = (SimpleFeatureType) schema;
memory = new MemoryDataStore();
try {
memory.createSchema(featureType);
} catch (IOException e) {
ConsoleManager.getInstance().exception(this, e);
memory = null;
return;
}
SimpleFeatureBuilder builder = new SimpleFeatureBuilder(featureType);
SimpleFeature feature = DataUtilities.template(featureType);
builder.init((SimpleFeature) feature);
int index = 0;
for (AttributeDescriptor descriptor : featureType.getAttributeDescriptors()) {
AttributeType attributeType = descriptor.getType();
Object value = null;
Class<?> fieldType = attributeType.getBinding();
if (attributeType instanceof GeometryTypeImpl) {
geometryType = GeometryTypeMapping.getGeometryType(fieldType);
switch(geometryType) {
case POLYGON:
ExamplePolygonInterface examplePolygon = DataSourceFactory.createExamplePolygon(null);
value = examplePolygon.getPolygon();
break;
case LINE:
ExampleLineInterface exampleLine = DataSourceFactory.createExampleLine(null);
value = exampleLine.getLine();
break;
case POINT:
default:
ExamplePointInterface examplePoint = DataSourceFactory.createExamplePoint(null);
value = examplePoint.getPoint();
break;
}
} else {
if ((fieldList != null) && (index < fieldList.size())) {
DataSourceAttributeData attrData = fieldMap.get(descriptor.getLocalName());
if (attrData != null) {
value = attrData.getValue();
}
}
value = getFieldTypeValue(index, attributeType.getName().getLocalPart(), fieldType, value);
}
builder.add(value);
index++;
}
SimpleFeature newFeature = builder.buildFeature("1234");
memory.addFeature(newFeature);
}
use of org.geotools.feature.type.GeometryTypeImpl 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;
}
Aggregations