Changeset 36074 in osm for applications/editors/josm


Ignore:
Timestamp:
2023-04-20T14:35:13+02:00 (19 months ago)
Author:
taylor.smock
Message:

GeotoolsConverter: Support converting LineString and Polygon into the JOSM data model

File:
1 edited

Legend:

Unmodified
Added
Removed
  • applications/editors/josm/plugins/opendata/src/org/openstreetmap/josm/plugins/opendata/core/io/geographic/GeotoolsConverter.java

    r36071 r36074  
    175175
    176176            Object geomObject = geometry.getValue();
    177             if (geomObject instanceof Point) {  // TODO: Support LineString and Polygon.
     177            if (geomObject instanceof Point) {
    178178                // Sure you could have a Set of 1 object and join these 2 branches of
    179179                // code, but I feel there would be a performance hit.
    180180                OsmPrimitive primitive = reader.createOrGetEmptyNode((Point) geomObject);
     181                readNonGeometricAttributes(feature, primitive);
     182            } else if (geomObject instanceof LineString) {
     183                OsmPrimitive primitive = reader.createOrGetWay((LineString) geomObject);
     184                readNonGeometricAttributes(feature, primitive);
     185            } else if (geomObject instanceof Polygon) {
     186                Polygon polygon = (Polygon) geomObject;
     187                Way outer = reader.createOrGetWay(polygon.getExteriorRing());
     188                Way[] inner = new Way[polygon.getNumInteriorRing()];
     189                for (int i = 0; i < inner.length; i++) {
     190                    inner[i] = reader.createOrGetWay(polygon.getInteriorRingN(i));
     191                }
     192                final OsmPrimitive primitive;
     193                if (inner.length == 0) {
     194                    primitive = outer;
     195                } else {
     196                    Relation relation = reader.createMultipolygon();
     197                    GeographicReader.addWayToMp(relation, "outer", outer);
     198                    for (Way iWay : inner) {
     199                        GeographicReader.addWayToMp(relation, "inner", iWay);
     200                    }
     201                    primitive = relation;
     202                }
    181203                readNonGeometricAttributes(feature, primitive);
    182204            } else if (geomObject instanceof GeometryCollection) { // Deals with both MultiLineString and MultiPolygon
     
    221243                    Way w = reader.createOrGetWay(p.getExteriorRing());
    222244                    if (r != null) {
    223                         reader.addWayToMp(r, "outer", w);
     245                        GeographicReader.addWayToMp(r, "outer", w);
    224246                        for (int j = 0; j < p.getNumInteriorRing(); j++) {
    225                             reader.addWayToMp(r, "inner", reader.createOrGetWay(p.getInteriorRingN(j)));
     247                            GeographicReader.addWayToMp(r, "inner", reader.createOrGetWay(p.getInteriorRingN(j)));
    226248                        }
    227249                    }
Note: See TracChangeset for help on using the changeset viewer.