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());
}
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);
}
}
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;
}
Aggregations