Search in sources :

Example 1 with GeometryTypeImpl

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);
}
Also used : DataSourceAttributeData(com.sldeditor.datasource.attribute.DataSourceAttributeData) HashMap(java.util.HashMap) MemoryDataStore(org.geotools.data.memory.MemoryDataStore) AttributeDescriptor(org.opengis.feature.type.AttributeDescriptor) IOException(java.io.IOException) SimpleFeature(org.opengis.feature.simple.SimpleFeature) ExamplePointInterface(com.sldeditor.datasource.example.ExamplePointInterface) GeometryTypeImpl(org.geotools.feature.type.GeometryTypeImpl) SimpleFeatureType(org.opengis.feature.simple.SimpleFeatureType) AttributeType(org.opengis.feature.type.AttributeType) ExampleLineInterface(com.sldeditor.datasource.example.ExampleLineInterface) SimpleFeatureBuilder(org.geotools.feature.simple.SimpleFeatureBuilder) ExamplePolygonInterface(com.sldeditor.datasource.example.ExamplePolygonInterface)

Example 2 with GeometryTypeImpl

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;
}
Also used : GeometryDescriptorImpl(org.geotools.feature.type.GeometryDescriptorImpl) GeometryDescriptor(org.opengis.feature.type.GeometryDescriptor) GeometryType(org.opengis.feature.type.GeometryType) SimpleFeatureTypeBuilder(org.geotools.feature.simple.SimpleFeatureTypeBuilder) SimpleFeatureType(org.opengis.feature.simple.SimpleFeatureType) AttributeDescriptor(org.opengis.feature.type.AttributeDescriptor) GeometryTypeImpl(org.geotools.feature.type.GeometryTypeImpl)

Aggregations

GeometryTypeImpl (org.geotools.feature.type.GeometryTypeImpl)2 SimpleFeatureType (org.opengis.feature.simple.SimpleFeatureType)2 AttributeDescriptor (org.opengis.feature.type.AttributeDescriptor)2 DataSourceAttributeData (com.sldeditor.datasource.attribute.DataSourceAttributeData)1 ExampleLineInterface (com.sldeditor.datasource.example.ExampleLineInterface)1 ExamplePointInterface (com.sldeditor.datasource.example.ExamplePointInterface)1 ExamplePolygonInterface (com.sldeditor.datasource.example.ExamplePolygonInterface)1 IOException (java.io.IOException)1 HashMap (java.util.HashMap)1 MemoryDataStore (org.geotools.data.memory.MemoryDataStore)1 SimpleFeatureBuilder (org.geotools.feature.simple.SimpleFeatureBuilder)1 SimpleFeatureTypeBuilder (org.geotools.feature.simple.SimpleFeatureTypeBuilder)1 GeometryDescriptorImpl (org.geotools.feature.type.GeometryDescriptorImpl)1 SimpleFeature (org.opengis.feature.simple.SimpleFeature)1 AttributeType (org.opengis.feature.type.AttributeType)1 GeometryDescriptor (org.opengis.feature.type.GeometryDescriptor)1 GeometryType (org.opengis.feature.type.GeometryType)1