use of com.sldeditor.datasource.attribute.DataSourceAttributeData 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 com.sldeditor.datasource.attribute.DataSourceAttributeData 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 com.sldeditor.datasource.attribute.DataSourceAttributeData in project sldeditor by robward-scisys.
the class DataSourceImpl method readAttributes.
/**
* Read attributes.
*
* @param attributeData the attribute data
*/
/*
* (non-Javadoc)
*
* @see com.sldeditor.datasource.DataSourceInterface#updateAttributes(com.sldeditor.render.iface. RenderAttributeDataInterface)
*/
@Override
public void readAttributes(DataSourceAttributeListInterface attributeData) {
if (attributeData == null) {
return;
}
List<DataSourceAttributeData> valueMap = new ArrayList<DataSourceAttributeData>();
SimpleFeatureCollection featureCollection = dataSourceInfo.getFeatureCollection();
if (featureCollection != null) {
SimpleFeatureIterator iterator = featureCollection.features();
Map<Integer, Name> fieldNameMap = dataSourceInfo.getFieldNameMap();
Map<Integer, Class<?>> fieldTypeMap = dataSourceInfo.getFieldTypeMap();
if (iterator.hasNext()) {
SimpleFeature feature = iterator.next();
List<Object> attributes = feature.getAttributes();
for (int i = 0; i < attributes.size(); i++) {
Name name = fieldNameMap.get(i);
if (name != null) {
String fieldName = name.getLocalPart();
Class<?> fieldType = fieldTypeMap.get(i);
if (fieldType == Geometry.class) {
Object value = feature.getAttribute(fieldName);
fieldType = value.getClass();
}
Object value = CreateSampleData.getFieldTypeValue(i, fieldName, fieldType, attributes.get(i));
DataSourceAttributeData data = new DataSourceAttributeData(fieldName, fieldType, value);
valueMap.add(data);
}
}
}
iterator.close();
}
attributeData.setData(valueMap);
}
use of com.sldeditor.datasource.attribute.DataSourceAttributeData in project sldeditor by robward-scisys.
the class DataSourceImpl method updateFields.
/**
* Update fields.
*
* @param attributeData the attribute data
*/
/*
* (non-Javadoc)
*
* @see com.sldeditor.datasource.DataSourceInterface#updateFields(com.sldeditor.render.iface. RenderAttributeDataInterface)
*/
@Override
public void updateFields(DataSourceAttributeListInterface attributeData) {
if (attributeData != null) {
List<DataSourceAttributeData> attributeDataList = attributeData.getData();
if (this.editorFileInterface != null) {
this.dataSourceProperties = editorFileInterface.getDataSource();
SLDDataInterface sldData = this.editorFileInterface.getSLDData();
if (sldData != null) {
sldData.setFieldList(attributeDataList);
}
}
this.connectedToDataSourceFlag = false;
createInternalDataSource();
notifyDataSourceLoaded();
}
}
use of com.sldeditor.datasource.attribute.DataSourceAttributeData in project sldeditor by robward-scisys.
the class DataSourceImpl method addField.
/**
* Adds the field.
*
* @param dataSourceField the data source field
*/
@Override
public void addField(DataSourceAttributeData dataSourceField) {
if (dataSourceField != null) {
if (connectedToDataSourceFlag == false) {
SLDDataInterface sldData = this.editorFileInterface.getSLDData();
List<DataSourceAttributeData> fieldList = sldData.getFieldList();
if (fieldList == null) {
fieldList = new ArrayList<DataSourceAttributeData>();
sldData.setFieldList(fieldList);
}
fieldList.add(dataSourceField);
createInternalDataSource();
notifyDataSourceLoaded();
}
}
}
Aggregations