Search in sources :

Example 1 with GeometryTypeEnum

use of com.sldeditor.datasource.impl.GeometryTypeEnum in project sldeditor by robward-scisys.

the class DataSourceInfoTest method testSetGeometryType.

/**
 * Test method for {@link
 * com.sldeditor.datasource.impl.DataSourceInfo#setGeometryType(com.sldeditor.datasource.impl.GeometryTypeEnum)}.
 * Test method for {@link com.sldeditor.datasource.impl.DataSourceInfo#getGeometryType()}.
 */
@Test
public void testSetGeometryType() {
    DataSourceInfo ds = new DataSourceInfo();
    GeometryTypeEnum expectedGeometry = GeometryTypeEnum.POLYGON;
    ds.setGeometryType(expectedGeometry);
    assertEquals(expectedGeometry, ds.getGeometryType());
    ds.reset();
    assertEquals(GeometryTypeEnum.UNKNOWN, ds.getGeometryType());
}
Also used : DataSourceInfo(com.sldeditor.datasource.impl.DataSourceInfo) GeometryTypeEnum(com.sldeditor.datasource.impl.GeometryTypeEnum) Test(org.junit.jupiter.api.Test)

Example 2 with GeometryTypeEnum

use of com.sldeditor.datasource.impl.GeometryTypeEnum in project sldeditor by robward-scisys.

the class InlineFeatureUtils method determineGeometryType.

/**
 * Determine geometry type.
 *
 * @param geometryDescriptor the geometry descriptor
 * @param simpleFeatureCollection the simple feature collection
 * @return the geometry type enum
 */
public static GeometryTypeEnum determineGeometryType(GeometryDescriptor geometryDescriptor, SimpleFeatureCollection simpleFeatureCollection) {
    if (geometryDescriptor == null) {
        return GeometryTypeEnum.UNKNOWN;
    }
    if (simpleFeatureCollection == null) {
        return GeometryTypeEnum.UNKNOWN;
    }
    Class<?> bindingType = geometryDescriptor.getType().getBinding();
    if (bindingType == Geometry.class) {
        Name geometryName = geometryDescriptor.getName();
        SimpleFeatureIterator iterator = simpleFeatureCollection.features();
        List<GeometryTypeEnum> geometryFeatures = new ArrayList<>();
        while (iterator.hasNext()) {
            SimpleFeature feature = iterator.next();
            Object value = feature.getAttribute(geometryName);
            if (value != null) {
                GeometryTypeEnum geometryType = GeometryTypeMapping.getGeometryType(value.getClass());
                if (!geometryFeatures.contains(geometryType)) {
                    geometryFeatures.add(geometryType);
                }
            }
        }
        return (combineGeometryType(geometryFeatures));
    } else {
        return GeometryTypeMapping.getGeometryType(bindingType);
    }
}
Also used : SimpleFeatureIterator(org.geotools.data.simple.SimpleFeatureIterator) ArrayList(java.util.ArrayList) GeometryTypeEnum(com.sldeditor.datasource.impl.GeometryTypeEnum) SimpleFeature(org.opengis.feature.simple.SimpleFeature) Name(org.opengis.feature.type.Name)

Example 3 with GeometryTypeEnum

use of com.sldeditor.datasource.impl.GeometryTypeEnum 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;
}
Also used : GeometryType(org.opengis.feature.type.GeometryType) StyledLayerDescriptor(org.geotools.styling.StyledLayerDescriptor) SimpleFeatureType(org.opengis.feature.simple.SimpleFeatureType) SimpleFeatureSource(org.geotools.data.simple.SimpleFeatureSource) DataStore(org.geotools.data.DataStore) IOException(java.io.IOException) GeometryTypeEnum(com.sldeditor.datasource.impl.GeometryTypeEnum)

Aggregations

GeometryTypeEnum (com.sldeditor.datasource.impl.GeometryTypeEnum)3 DataSourceInfo (com.sldeditor.datasource.impl.DataSourceInfo)1 IOException (java.io.IOException)1 ArrayList (java.util.ArrayList)1 DataStore (org.geotools.data.DataStore)1 SimpleFeatureIterator (org.geotools.data.simple.SimpleFeatureIterator)1 SimpleFeatureSource (org.geotools.data.simple.SimpleFeatureSource)1 StyledLayerDescriptor (org.geotools.styling.StyledLayerDescriptor)1 Test (org.junit.jupiter.api.Test)1 SimpleFeature (org.opengis.feature.simple.SimpleFeature)1 SimpleFeatureType (org.opengis.feature.simple.SimpleFeatureType)1 GeometryType (org.opengis.feature.type.GeometryType)1 Name (org.opengis.feature.type.Name)1