use of org.geotools.feature.type.GeometryDescriptorImpl in project sldeditor by robward-scisys.
the class InLineFeatureModel method populate.
/**
* Populate.
*
* @param userLayer the user layer
*/
public void populate(UserLayer userLayer) {
this.userLayer = userLayer;
featureCollection = null;
geometryFieldIndex = -1;
columnList.clear();
if ((userLayer != null) && (userLayer.getInlineFeatureType() != null)) {
String typeName = userLayer.getInlineFeatureType().getTypeName();
try {
SimpleFeatureSource featureSource = userLayer.getInlineFeatureDatastore().getFeatureSource(typeName);
if (featureSource != null) {
featureCollection = featureSource.getFeatures();
}
} catch (IOException e) {
ConsoleManager.getInstance().exception(this, e);
}
if (featureCollection != null) {
// Populate field names
List<AttributeDescriptor> descriptorList = featureCollection.getSchema().getAttributeDescriptors();
int index = 0;
for (AttributeDescriptor descriptor : descriptorList) {
if (descriptor instanceof GeometryDescriptorImpl) {
geometryFieldIndex = index;
}
columnList.add(descriptor.getLocalName());
index++;
}
}
}
this.fireTableStructureChanged();
this.fireTableDataChanged();
// Set up the editor to handle editing the table cells
InlineCellEditor editor = new InlineCellEditor(this);
if ((featureTable != null) && (featureTable.getColumnModel().getColumnCount() > 0)) {
TableColumn column = featureTable.getColumnModel().getColumn(0);
column.setCellEditor(editor);
featureTable.setCellEditor(editor);
}
}
use of org.geotools.feature.type.GeometryDescriptorImpl in project sldeditor by robward-scisys.
the class SLDEditorBufferedImageLegendGraphicBuilder method cloneWithDimensionality.
/**
* Clones the given schema, changing the geometry attribute to match the given dimensionality.
*
* @param schema schema to clone
* @param dimensionality dimensionality for the geometry 1= points, 2= lines, 3= polygons
*/
private FeatureType cloneWithDimensionality(FeatureType schema, int dimensionality) {
SimpleFeatureType simpleFt = (SimpleFeatureType) schema;
SimpleFeatureTypeBuilder builder = new SimpleFeatureTypeBuilder();
builder.setName(schema.getName());
builder.setCRS(schema.getCoordinateReferenceSystem());
for (AttributeDescriptor desc : simpleFt.getAttributeDescriptors()) {
if (isMixedGeometry(desc)) {
GeometryDescriptor geomDescriptor = (GeometryDescriptor) desc;
GeometryType geomType = geomDescriptor.getType();
Class<?> geometryClass = getGeometryForDimensionality(dimensionality);
GeometryType gt = new GeometryTypeImpl(geomType.getName(), geometryClass, geomType.getCoordinateReferenceSystem(), geomType.isIdentified(), geomType.isAbstract(), geomType.getRestrictions(), geomType.getSuper(), geomType.getDescription());
builder.add(new GeometryDescriptorImpl(gt, geomDescriptor.getName(), geomDescriptor.getMinOccurs(), geomDescriptor.getMaxOccurs(), geomDescriptor.isNillable(), geomDescriptor.getDefaultValue()));
} else {
builder.add(desc);
}
}
schema = builder.buildFeatureType();
return schema;
}
use of org.geotools.feature.type.GeometryDescriptorImpl in project sldeditor by robward-scisys.
the class DataSourceImplTest method testConnectToInternalDataSource.
/**
* Test method for {@link com.sldeditor.datasource.impl.DataSourceImpl#connect()}. Test method
* for {@link
* com.sldeditor.datasource.impl.DataSourceImpl#addListener(com.sldeditor.datasource.DataSourceUpdatedInterface)}.
*/
@Test
public void testConnectToInternalDataSource() {
DataSourceImpl ds = new DataSourceImpl();
DummyInternalSLDFile editorFile = new DummyInternalSLDFile();
DummyDataSourceUpdate dataSourceUpdateListener = new DummyDataSourceUpdate();
ds.addListener(dataSourceUpdateListener);
ds.addListener(dataSourceUpdateListener);
CreateDataSourceInterface internalDataSource = new CreateInternalDataSource();
CreateDataSourceInterface externalDataSource = new DummyCreateDataSource();
CreateDataSourceInterface inlineDataSource = new DummyCreateDataSource();
ds.setDataSourceCreation(internalDataSource, externalDataSource, inlineDataSource);
ds.connect("typeName", editorFile, null);
assertEquals(GeometryTypeEnum.POINT, dataSourceUpdateListener.geometryType);
assertFalse(dataSourceUpdateListener.isConnectedToDataSourceFlag);
Collection<PropertyDescriptor> fieldList = ds.getPropertyDescriptorList();
assertTrue(fieldList != null);
List<String> actualFieldnameList = new ArrayList<String>();
for (PropertyDescriptor field : fieldList) {
if (!(field instanceof GeometryDescriptorImpl)) {
actualFieldnameList.add(field.getName().getLocalPart());
}
}
// Check fields extracted ok
List<String> expectedFieldList = editorFile.getExpectedFieldList();
assertTrue(expectedFieldList.size() == actualFieldnameList.size());
// Not assuming fields are in the same order
int count = 0;
for (String fieldName : actualFieldnameList) {
if (expectedFieldList.contains(fieldName)) {
count++;
}
}
assertTrue(expectedFieldList.size() == count);
// Check for fields of certain types
assertFalse(ds.getAttributes(Integer.class).isEmpty());
assertFalse(ds.getAttributes(Double.class).isEmpty());
assertEquals(2, ds.getAttributes(String.class).size());
// Add new field
DataSourceAttributeData dataSourceField = new DataSourceAttributeData("bearing", Double.class, null);
ds.addField(dataSourceField);
assertTrue(ds.getAttributes(Double.class).size() == 2);
// Update field
DataSourceAttributeList attributeData = new DataSourceAttributeList();
ds.readAttributes(null);
ds.readAttributes(attributeData);
assertTrue(ds.getPropertyDescriptorList().size() == attributeData.getData().size());
List<DataSourceAttributeData> attributeDataList = attributeData.getData();
DataSourceAttributeData data = attributeDataList.remove(2);
data.setType(Integer.class);
attributeDataList.add(2, data);
ds.updateFields(null);
ds.updateFields(attributeData);
List<String> actualAttributes = ds.getAttributes(Integer.class);
assertTrue(actualAttributes.size() == 2);
FeatureSource<SimpleFeatureType, SimpleFeature> features = ds.getFeatureSource();
try {
assertEquals(1, features.getFeatures().size());
} catch (IOException e) {
e.printStackTrace();
fail(e.getMessage());
}
assertFalse(dataSourceUpdateListener.isConnectedToDataSourceFlag);
ds.removeListener(dataSourceUpdateListener);
assertFalse(dataSourceUpdateListener.isConnectedToDataSourceFlag);
}
Aggregations