Search in sources :

Example 1 with DefaultExtendedData

use of org.geotoolkit.data.kml.model.DefaultExtendedData in project geotoolkit by Geomatys.

the class KmlFeatureUtilities method fillGeometryListFromFeature.

/**
 * recursive method on feature to find geometries
 * @param feature {@link org.opengis.feature.Feature} traveled to find geometry
 * @param geometries {@link List} where we add {@link Geometry}
 */
public static void fillGeometryListFromFeature(final Feature feature, final List<Map.Entry<Object, Map<String, String>>> geometries) {
    final Object geometry = feature.getPropertyValue("geometry");
    if (geometry != null) {
        // create map which have other data value
        final Map<String, String> values = new HashMap<>(0);
        // get feature name
        final String name = (String) feature.getPropertyValue("name");
        if (name != null) {
            values.put("name", name);
        }
        // get extendedData
        final DefaultExtendedData extendData = (DefaultExtendedData) feature.getPropertyValue("ExtendedData");
        if (extendData != null) {
            // loop on extendedSchemaData to find data
            final List<SchemaData> schemaDatas = extendData.getSchemaData();
            for (SchemaData schemaData : schemaDatas) {
                // get simples data to add it on values map
                final List<SimpleData> simpleDataList = schemaData.getSimpleDatas();
                for (SimpleData simpleData : simpleDataList) {
                    values.put(simpleData.getName(), simpleData.getContent());
                }
            }
        }
        // add geometry on list
        geometries.add(new AbstractMap.SimpleEntry<Object, Map<String, String>>(geometry, values));
    // it's a folder, go recursivly on childs
    } else {
        final Iterator<?> iterator = ((Iterable<?>) feature.getPropertyValue(KmlConstants.TAG_FEATURES)).iterator();
        while (iterator.hasNext()) {
            final Object object = iterator.next();
            if (object instanceof Feature) {
                final Feature candidat = (Feature) object;
                // recursive call
                fillGeometryListFromFeature(candidat, geometries);
            }
        }
    }
}
Also used : HashMap(java.util.HashMap) SchemaData(org.geotoolkit.data.kml.model.SchemaData) DefaultExtendedData(org.geotoolkit.data.kml.model.DefaultExtendedData) SimpleData(org.geotoolkit.data.kml.model.SimpleData) MultiLineString(org.locationtech.jts.geom.MultiLineString) LineString(org.locationtech.jts.geom.LineString) Feature(org.opengis.feature.Feature) AbstractMap(java.util.AbstractMap) Map(java.util.Map) HashMap(java.util.HashMap) AbstractMap(java.util.AbstractMap)

Aggregations

AbstractMap (java.util.AbstractMap)1 HashMap (java.util.HashMap)1 Map (java.util.Map)1 DefaultExtendedData (org.geotoolkit.data.kml.model.DefaultExtendedData)1 SchemaData (org.geotoolkit.data.kml.model.SchemaData)1 SimpleData (org.geotoolkit.data.kml.model.SimpleData)1 LineString (org.locationtech.jts.geom.LineString)1 MultiLineString (org.locationtech.jts.geom.MultiLineString)1 Feature (org.opengis.feature.Feature)1