use of org.geotools.data.simple.SimpleFeatureSource 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;
}
use of org.geotools.data.simple.SimpleFeatureSource in project sldeditor by robward-scisys.
the class DataSourceInfoTest method testGetFeatureStore.
/**
* Test method for {@link com.sldeditor.datasource.impl.DataSourceInfo#getFeatureStore()}. Test
* method for
* {@link com.sldeditor.datasource.impl.DataSourceInfo#setSchema(org.opengis.feature.type.FeatureType)}.
*/
@SuppressWarnings({ "unchecked", "rawtypes" })
@Test
public void testGetFeatureStore() {
URL url = SLDEditorFile.class.getClassLoader().getResource("point/sld/shp/sld_cookbook_point.shp");
Map map = new HashMap();
map.put("url", url);
DataStore dataStore;
try {
dataStore = DataStoreFinder.getDataStore(map);
DataSourceInfo dsInfo = new DataSourceInfo();
String typeName = dataStore.getTypeNames()[0];
dsInfo.setTypeName(typeName);
SimpleFeatureSource source = dataStore.getFeatureSource(typeName);
SimpleFeatureType schema = source.getSchema();
dsInfo.setSchema(schema);
assertNull(dsInfo.getFeatureStore());
dsInfo.setDataStore(dataStore);
FeatureStore<SimpleFeatureType, SimpleFeature> featureStore = dsInfo.getFeatureStore();
assertTrue(featureStore != null);
} catch (IOException e) {
e.printStackTrace();
fail(e.getMessage());
}
}
use of org.geotools.data.simple.SimpleFeatureSource in project sldeditor by robward-scisys.
the class DataSourceInfoTest method testGetPropertyDescriptorList.
/**
* Test method for
* {@link com.sldeditor.datasource.impl.DataSourceInfo#getPropertyDescriptorList()}.
*/
@SuppressWarnings({ "unchecked", "rawtypes" })
@Test
public void testGetPropertyDescriptorList() {
URL url = SLDEditorFile.class.getClassLoader().getResource("point/sld/shp/sld_cookbook_point.shp");
Map map = new HashMap();
map.put("url", url);
DataStore dataStore;
try {
dataStore = DataStoreFinder.getDataStore(map);
DataSourceInfo dsInfo = new DataSourceInfo();
String typeName = dataStore.getTypeNames()[0];
dsInfo.setTypeName(typeName);
SimpleFeatureSource source = dataStore.getFeatureSource(typeName);
SimpleFeatureType schema = source.getSchema();
assertNull(dsInfo.getPropertyDescriptorList());
dsInfo.setSchema(schema);
Collection<PropertyDescriptor> fieldList = dsInfo.getPropertyDescriptorList();
assertTrue(fieldList.size() == 3);
} catch (IOException e) {
e.printStackTrace();
fail(e.getMessage());
}
}
use of org.geotools.data.simple.SimpleFeatureSource in project mkgmap by openstreetmap.
the class PrecompSeaGenerator method createShapefileAccess.
private void createShapefileAccess() throws IOException {
Map<String, URL> map = new HashMap<String, URL>();
map.put("url", shapeFile.toURI().toURL());
DataStore dataStore = DataStoreFinder.getDataStore(map);
String typeName = dataStore.getTypeNames()[0];
SimpleFeatureSource source = dataStore.getFeatureSource(typeName);
shapeCollection = source.getFeatures();
}
use of org.geotools.data.simple.SimpleFeatureSource in project activityinfo by bedatadriven.
the class ImportView method updateGeometry.
private void updateGeometry(GeoAdminClient client, Map<ResourceId, ResourceId> idMap) throws IOException {
FeatureSourceStorageProvider catalog = new FeatureSourceStorageProvider();
FeatureSourceStorage formStorage = (FeatureSourceStorage) catalog.getForm(getModel().getSourceFormId().get()).get();
ResourceId targetFormId = getModel().getTargetFormId().get();
FieldProfile targetField = getTargetProfile().get().getGeometryField();
if (targetField == null) {
System.err.println("No geometry field to update.");
return;
}
int sourceIndex = formStorage.getGeometryAttributeIndex();
if (sourceIndex == -1) {
System.err.println("No source geometry field.");
return;
}
SimpleFeatureSource featureSource = formStorage.getFeatureSource();
GeometryType geometryType = (GeometryType) featureSource.getSchema().getDescriptor(sourceIndex).getType();
GeometryConverter converter = new GeometryConverter(geometryType);
SimpleFeatureIterator it = featureSource.getFeatures().features();
while (it.hasNext()) {
SimpleFeature feature = it.next();
ResourceId sourceId = ResourceId.valueOf(feature.getID());
ResourceId targetId = idMap.get(sourceId);
if (targetId != null) {
Geometry geometry = converter.toWgs84(feature.getAttribute(sourceIndex));
System.out.print("Updating geometry for " + targetId + " [" + geometry.getGeometryType() + "] ... ");
try {
client.updateGeometry(targetFormId, targetId, targetField.getId(), geometry);
System.out.println("OK");
} catch (Exception e) {
System.out.println("ERROR: " + e.getMessage());
}
}
}
}
Aggregations