use of org.opengis.feature.simple.SimpleFeatureType in project sldeditor by robward-scisys.
the class CreateInternalDataSource method connect.
/**
* Creates the.
*
* @param typeName the type name
* @param geometryFieldName the geometry field name
* @param editorFile the editor file
* @return the list of datastores
*/
@Override
public List<DataSourceInfo> connect(String typeName, String geometryFieldName, SLDEditorFileInterface editorFile) {
List<DataSourceInfo> dataSourceInfoList = new ArrayList<DataSourceInfo>();
dataSourceInfoList.add(dsInfo);
dsInfo.reset();
if (editorFile != null) {
StyledLayerDescriptor sld = editorFile.getSLD();
determineGeometryType(sld);
ExtendedSimpleFeatureTypeBuilder b = new ExtendedSimpleFeatureTypeBuilder();
// set the name
typeName = INTERNAL_SCHEMA_NAME;
dsInfo.setTypeName(typeName);
b.setName(typeName);
String namespace = null;
b.setNamespaceURI(namespace);
// add a geometry property
// set crs first
b.setCRS(DefaultGeographicCRS.WGS84);
SLDDataInterface sldData = editorFile.getSLDData();
List<DataSourceAttributeData> fieldList = sldData.getFieldList();
// Set the geometry field by default
geometryField.reset();
if (geometryFieldName != null) {
geometryField.setGeometryFieldName(geometryFieldName);
}
List<AttributeDescriptor> attrDescList = new ArrayList<AttributeDescriptor>();
if ((fieldList == null) || fieldList.isEmpty()) {
// Read the fields from the SLD
ExtractAttributes extract = new ExtractAttributes();
extract.extractDefaultFields(sld);
fieldList = extract.getFields();
// Add non-geometry fields to the feature type builder
for (DataSourceAttributeData dsAttribute : fieldList) {
if (dsAttribute.getName() != null) {
b.add(dsAttribute.getName(), dsAttribute.getType());
}
}
List<String> geometryFields = extract.getGeometryFields();
for (String localGeometryFieldName : geometryFields) {
geometryField.setGeometryFieldName(localGeometryFieldName);
}
} else {
addFields(attrDescList, b, fieldList);
}
attrDescList.add(addGeometryField(b, geometryField.getGeometryFieldName()));
b.addAll(attrDescList);
// Store the fields
sldData.setFieldList(fieldList);
// Build the feature type
SimpleFeatureType schema = b.buildFeatureType();
dsInfo.setSchema(schema);
CreateSampleData sampleData = new CreateSampleData();
sampleData.create(schema, fieldList);
MemoryDataStore dataStore = sampleData.getDataStore();
dsInfo.setDataStore(dataStore);
dsInfo.populateFieldMap();
}
return dataSourceInfoList;
}
use of org.opengis.feature.simple.SimpleFeatureType 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);
}
use of org.opengis.feature.simple.SimpleFeatureType in project sldeditor by robward-scisys.
the class DataSourceImpl method getUserLayerFeatureSource.
/*
* (non-Javadoc)
*
* @see com.sldeditor.datasource.DataSourceInterface#getUserLayerFeatureSource()
*/
@Override
public // CHECKSTYLE:OFF
Map<UserLayer, FeatureSource<SimpleFeatureType, SimpleFeature>> getUserLayerFeatureSource() {
// CHECKSTYLE:ON
Map<UserLayer, FeatureSource<SimpleFeatureType, SimpleFeature>> map = new HashMap<UserLayer, FeatureSource<SimpleFeatureType, SimpleFeature>>();
for (DataSourceInfo dsInfo : userLayerDataSourceInfo) {
FeatureSource<SimpleFeatureType, SimpleFeature> features = dsInfo.getFeatures();
UserLayer userLayer = dsInfo.getUserLayer();
map.put(userLayer, features);
}
return map;
}
use of org.opengis.feature.simple.SimpleFeatureType in project sldeditor by robward-scisys.
the class ExtractValidFieldTypes method fieldTypesUpdated.
/**
* Evaluate fields types.
*
* @return true, field types updated
*/
public static boolean fieldTypesUpdated() {
boolean fieldsUpdated = false;
SLDStyleFactory styleFactory = new SLDStyleFactory();
StyledLayerDescriptor sld = SelectedSymbol.getInstance().getSld();
if (sld != null) {
List<StyledLayer> styledLayerList = sld.layers();
for (StyledLayer styledLayer : styledLayerList) {
List<org.geotools.styling.Style> styleList = null;
if (styledLayer instanceof NamedLayerImpl) {
NamedLayerImpl namedLayerImpl = (NamedLayerImpl) styledLayer;
styleList = namedLayerImpl.styles();
} else if (styledLayer instanceof UserLayerImpl) {
UserLayerImpl userLayerImpl = (UserLayerImpl) styledLayer;
styleList = userLayerImpl.userStyles();
}
if (styleList != null) {
for (Style style : styleList) {
for (FeatureTypeStyle fts : style.featureTypeStyles()) {
for (Rule rule : fts.rules()) {
for (Symbolizer symbolizer : rule.symbolizers()) {
FeatureSource<SimpleFeatureType, SimpleFeature> featureList = DataSourceFactory.getDataSource().getFeatureSource();
if (featureList != null) {
Object drawMe = null;
try {
drawMe = featureList.getFeatures().features().next();
} catch (NoSuchElementException e) {
e.printStackTrace();
} catch (IOException e) {
e.printStackTrace();
}
try {
styleFactory.createStyle(drawMe, symbolizer);
} catch (IllegalArgumentException e) {
String message = e.getMessage();
if (message.startsWith(UNABLE_TO_DECODE_PREFIX) && message.endsWith(UNABLE_TO_DECODE_SUFFIX)) {
String fieldName = message.substring(UNABLE_TO_DECODE_PREFIX.length(), message.length() - UNABLE_TO_DECODE_SUFFIX.length());
DataSourceFactory.getDataSource().updateFieldType(fieldName, Long.class);
fieldsUpdated = true;
} else {
ConsoleManager.getInstance().exception(ExtractValidFieldTypes.class, e);
}
}
}
}
}
}
}
}
}
}
return fieldsUpdated;
}
use of org.opengis.feature.simple.SimpleFeatureType in project sldeditor by robward-scisys.
the class InLineFeatureModel method removeFeature.
/**
* Removes the feature.
*
* @param selectedRow the selected row
*/
public void removeFeature(int selectedRow) {
if ((selectedRow < 0) || (selectedRow >= getRowCount())) {
return;
}
SimpleFeatureType featureType = userLayer.getInlineFeatureType();
String typeName = userLayer.getInlineFeatureType().getTypeName();
try {
SimpleFeatureSource featureSource = userLayer.getInlineFeatureDatastore().getFeatureSource(typeName);
SimpleFeatureBuilder sfb = new SimpleFeatureBuilder(featureType);
ArrayList<SimpleFeature> featureList = new ArrayList<SimpleFeature>();
SimpleFeatureIterator it = featureSource.getFeatures().features();
try {
int index = 0;
while (it.hasNext()) {
SimpleFeature sf = it.next();
if (index != selectedRow) {
List<Object> attributeValueList = sf.getAttributes();
sfb.addAll(attributeValueList);
featureList.add(sfb.buildFeature(null));
}
index++;
}
} finally {
it.close();
}
SimpleFeatureCollection collection = new ListFeatureCollection(featureType, featureList);
featureCollection = collection;
cachedFeature = null;
lastRow = -1;
DataStore dataStore = DataUtilities.dataStore(collection);
userLayer.setInlineFeatureDatastore(dataStore);
} catch (IOException e) {
ConsoleManager.getInstance().exception(this, e);
}
this.fireTableStructureChanged();
this.fireTableDataChanged();
if (parentObj != null) {
parentObj.inlineFeatureUpdated();
}
}
Aggregations