Search in sources :

Example 1 with GeometryDescriptorImpl

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);
    }
}
Also used : GeometryDescriptorImpl(org.geotools.feature.type.GeometryDescriptorImpl) SimpleFeatureSource(org.geotools.data.simple.SimpleFeatureSource) AttributeDescriptor(org.opengis.feature.type.AttributeDescriptor) IOException(java.io.IOException) TableColumn(javax.swing.table.TableColumn)

Example 2 with GeometryDescriptorImpl

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;
}
Also used : GeometryDescriptorImpl(org.geotools.feature.type.GeometryDescriptorImpl) GeometryDescriptor(org.opengis.feature.type.GeometryDescriptor) GeometryType(org.opengis.feature.type.GeometryType) SimpleFeatureTypeBuilder(org.geotools.feature.simple.SimpleFeatureTypeBuilder) SimpleFeatureType(org.opengis.feature.simple.SimpleFeatureType) AttributeDescriptor(org.opengis.feature.type.AttributeDescriptor) GeometryTypeImpl(org.geotools.feature.type.GeometryTypeImpl)

Example 3 with GeometryDescriptorImpl

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);
}
Also used : GeometryDescriptorImpl(org.geotools.feature.type.GeometryDescriptorImpl) DataSourceAttributeData(com.sldeditor.datasource.attribute.DataSourceAttributeData) PropertyDescriptor(org.opengis.feature.type.PropertyDescriptor) DataSourceImpl(com.sldeditor.datasource.impl.DataSourceImpl) CreateDataSourceInterface(com.sldeditor.datasource.impl.CreateDataSourceInterface) ArrayList(java.util.ArrayList) IOException(java.io.IOException) SimpleFeature(org.opengis.feature.simple.SimpleFeature) DataSourceAttributeList(com.sldeditor.datasource.attribute.DataSourceAttributeList) CreateInternalDataSource(com.sldeditor.datasource.impl.CreateInternalDataSource) SimpleFeatureType(org.opengis.feature.simple.SimpleFeatureType) Test(org.junit.jupiter.api.Test)

Aggregations

GeometryDescriptorImpl (org.geotools.feature.type.GeometryDescriptorImpl)3 IOException (java.io.IOException)2 SimpleFeatureType (org.opengis.feature.simple.SimpleFeatureType)2 AttributeDescriptor (org.opengis.feature.type.AttributeDescriptor)2 DataSourceAttributeData (com.sldeditor.datasource.attribute.DataSourceAttributeData)1 DataSourceAttributeList (com.sldeditor.datasource.attribute.DataSourceAttributeList)1 CreateDataSourceInterface (com.sldeditor.datasource.impl.CreateDataSourceInterface)1 CreateInternalDataSource (com.sldeditor.datasource.impl.CreateInternalDataSource)1 DataSourceImpl (com.sldeditor.datasource.impl.DataSourceImpl)1 ArrayList (java.util.ArrayList)1 TableColumn (javax.swing.table.TableColumn)1 SimpleFeatureSource (org.geotools.data.simple.SimpleFeatureSource)1 SimpleFeatureTypeBuilder (org.geotools.feature.simple.SimpleFeatureTypeBuilder)1 GeometryTypeImpl (org.geotools.feature.type.GeometryTypeImpl)1 Test (org.junit.jupiter.api.Test)1 SimpleFeature (org.opengis.feature.simple.SimpleFeature)1 GeometryDescriptor (org.opengis.feature.type.GeometryDescriptor)1 GeometryType (org.opengis.feature.type.GeometryType)1 PropertyDescriptor (org.opengis.feature.type.PropertyDescriptor)1