Search in sources :

Example 1 with ExamplePointInterface

use of com.sldeditor.datasource.example.ExamplePointInterface 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 ExamplePointInterface

use of com.sldeditor.datasource.example.ExamplePointInterface in project sldeditor by robward-scisys.

the class DataSourceFactoryTest method testCreateExamplePoint.

/**
 * Test method for
 * {@link com.sldeditor.datasource.impl.DataSourceFactory#createExamplePoint(java.lang.Object)}.
 */
@Test
public void testCreateExamplePoint() {
    ExamplePointInterface examplePoint = DataSourceFactory.createExamplePoint(null);
    assertEquals(ExamplePointImpl.class, examplePoint.getClass());
}
Also used : ExamplePointInterface(com.sldeditor.datasource.example.ExamplePointInterface) Test(org.junit.Test)

Aggregations

ExamplePointInterface (com.sldeditor.datasource.example.ExamplePointInterface)2 DataSourceAttributeData (com.sldeditor.datasource.attribute.DataSourceAttributeData)1 ExampleLineInterface (com.sldeditor.datasource.example.ExampleLineInterface)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 GeometryTypeImpl (org.geotools.feature.type.GeometryTypeImpl)1 Test (org.junit.Test)1 SimpleFeature (org.opengis.feature.simple.SimpleFeature)1 SimpleFeatureType (org.opengis.feature.simple.SimpleFeatureType)1 AttributeDescriptor (org.opengis.feature.type.AttributeDescriptor)1 AttributeType (org.opengis.feature.type.AttributeType)1