Java Code Examples for org.opengis.feature.simple.SimpleFeature#getAttributes()

The following examples show how to use org.opengis.feature.simple.SimpleFeature#getAttributes() . You can vote up the ones you like or vote down the ones you don't like, and go to the original project or source file by following the links above each example. You may check out the related API usage on the sidebar.
Example 1
Source File: DataSourceImpl.java    From sldeditor with GNU General Public License v3.0 5 votes vote down vote up
/**
 * 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();
        if(iterator.hasNext())
        {
            SimpleFeature feature = iterator.next();

            List<Object> attributes = feature.getAttributes();
            for (int i = 0; i < attributes.size(); i++)
            {
                Name fieldName = fieldNameMap.get(i);

                DataSourceAttributeData data = new DataSourceAttributeData(fieldName,
                        fieldTypeMap.get(i),
                        attributes.get(i));

                valueMap.add(data);
            }
        }
    }

    attributeData.setData(valueMap);
}
 
Example 2
Source File: FeatureCentroidDistanceFn.java    From geowave with Apache License 2.0 5 votes vote down vote up
private Geometry getGeometry(final SimpleFeature x) {
  for (final Object attr : x.getAttributes()) {
    if (attr instanceof Geometry) {
      return (Geometry) attr;
    }
  }
  return (Geometry) x.getDefaultGeometry();
}
 
Example 3
Source File: FeatureDistanceFn.java    From geowave with Apache License 2.0 5 votes vote down vote up
private Geometry getGeometry(final SimpleFeature x) {
  for (final Object attr : x.getAttributes()) {
    if (attr instanceof Geometry) {
      return (Geometry) attr;
    }
  }
  return (Geometry) x.getDefaultGeometry();
}
 
Example 4
Source File: FeatureGeometryDistanceFn.java    From geowave with Apache License 2.0 5 votes vote down vote up
private Geometry getGeometry(final SimpleFeature x) {
  for (final Object attr : x.getAttributes()) {
    if (attr instanceof Geometry) {
      return (Geometry) attr;
    }
  }
  return (Geometry) x.getDefaultGeometry();
}
 
Example 5
Source File: InLineFeatureModel.java    From sldeditor with GNU General Public License v3.0 4 votes vote down vote up
/**
 * Removes the column.
 *
 * @param columnName the column name
 */
public void removeColumn(String columnName) {
    if (featureCollection != null) {
        if (columnList.contains(columnName)) {
            columnList.remove(columnName);

            // Find field name to remote
            SimpleFeatureTypeBuilder featureTypeBuilder = new SimpleFeatureTypeBuilder();
            featureTypeBuilder.init(featureCollection.getSchema());
            featureTypeBuilder.remove(columnName);

            SimpleFeatureType newFeatureType = featureTypeBuilder.buildFeatureType();

            int attributeToRemoveIndex = 0;
            for (AttributeDescriptor descriptor : newFeatureType.getAttributeDescriptors()) {
                if (descriptor.getLocalName().compareTo(columnName) == 0) {
                    break;
                }
                attributeToRemoveIndex++;
            }

            String typeName = userLayer.getInlineFeatureType().getTypeName();
            try {
                SimpleFeatureSource featureSource =
                        userLayer.getInlineFeatureDatastore().getFeatureSource(typeName);

                SimpleFeatureBuilder sfb = new SimpleFeatureBuilder(newFeatureType);

                ArrayList<SimpleFeature> featureList = new ArrayList<>();

                SimpleFeatureIterator it = featureSource.getFeatures().features();
                try {
                    while (it.hasNext()) {
                        SimpleFeature sf = it.next();
                        List<Object> attributes = sf.getAttributes();
                        attributes.remove(attributeToRemoveIndex);

                        sfb.addAll(attributes);
                        featureList.add(sfb.buildFeature(null));
                    }
                } finally {
                    it.close();
                }

                SimpleFeatureCollection collection =
                        new ListFeatureCollection(newFeatureType, featureList);

                featureCollection = collection;
                cachedFeature = null;
                lastRow = -1;
                DataStore dataStore = DataUtilities.dataStore(collection);
                userLayer.setInlineFeatureDatastore(dataStore);
                userLayer.setInlineFeatureType(newFeatureType);

            } catch (IOException e) {
                ConsoleManager.getInstance().exception(this, e);
            }

            this.fireTableStructureChanged();
            this.fireTableDataChanged();

            if (parentObj != null) {
                parentObj.inlineFeatureUpdated();
            }
        }
    }
}
 
Example 6
Source File: InLineFeatureModel.java    From sldeditor with GNU General Public License v3.0 4 votes vote down vote up
/**
 * Update CRS.
 *
 * @param selectedValue the selected value
 */
public void updateCRS(ValueComboBoxData selectedValue) {
    if (selectedValue != null) {
        String crsCode = selectedValue.getKey();

        CoordinateReferenceSystem newCRS = CoordManager.getInstance().getCRS(crsCode);

        SimpleFeatureType newFeatureType =
                SimpleFeatureTypeBuilder.retype(featureCollection.getSchema(), newCRS);

        String typeName = userLayer.getInlineFeatureType().getTypeName();
        try {
            SimpleFeatureSource featureSource =
                    userLayer.getInlineFeatureDatastore().getFeatureSource(typeName);

            SimpleFeatureBuilder sfb = new SimpleFeatureBuilder(newFeatureType);

            ArrayList<SimpleFeature> featureList = new ArrayList<>();

            SimpleFeatureIterator it = featureSource.getFeatures().features();
            try {
                while (it.hasNext()) {
                    SimpleFeature sf = it.next();
                    List<Object> attributeValueList = sf.getAttributes();
                    sfb.addAll(attributeValueList);
                    featureList.add(sfb.buildFeature(null));
                }
            } finally {
                it.close();
            }

            SimpleFeatureCollection collection =
                    new ListFeatureCollection(newFeatureType, featureList);

            featureCollection = collection;
            cachedFeature = null;
            lastRow = -1;
            DataStore dataStore = DataUtilities.dataStore(collection);
            userLayer.setInlineFeatureDatastore(dataStore);
            userLayer.setInlineFeatureType(newFeatureType);

        } catch (IOException e) {
            ConsoleManager.getInstance().exception(this, e);
        }

        this.fireTableStructureChanged();
        this.fireTableDataChanged();

        if (parentObj != null) {
            parentObj.inlineFeatureUpdated();
        }
    }
}
 
Example 7
Source File: InLineFeatureModel.java    From sldeditor with GNU General Public License v3.0 4 votes vote down vote up
/** Adds the new feature. */
public void addNewFeature() {
    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<>();

        SimpleFeatureIterator it = featureSource.getFeatures().features();
        try {
            while (it.hasNext()) {
                SimpleFeature sf = it.next();
                List<Object> attributeValueList = sf.getAttributes();
                sfb.addAll(attributeValueList);
                featureList.add(sfb.buildFeature(null));
            }
            // Add new feature
            String wktString = "wkt://POINT(0 0)";
            Geometry geometry =
                    WKTConversion.convertToGeometry(wktString, getSelectedCRSCode());
            sfb.add(geometry);
            featureList.add(sfb.buildFeature(null));
        } 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();
    }
}
 
Example 8
Source File: InLineFeatureModel.java    From sldeditor with GNU General Public License v3.0 4 votes vote down vote up
/**
 * 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<>();

        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();
    }
}