| 118 | | OsmPrimitive primitive = null; |
| 119 | | |
| 120 | | if (geometry.getValue() instanceof Point) { |
| 121 | | primitive = createOrGetEmptyNode((Point) geometry.getValue()); |
| 122 | | |
| 123 | | } else if (geometry.getValue() instanceof GeometryCollection) { // Deals with both MultiLineString and MultiPolygon |
| 124 | | GeometryCollection mp = (GeometryCollection) geometry.getValue(); |
| 125 | | int nGeometries = mp.getNumGeometries(); |
| 126 | | if (nGeometries < 1) { |
| 127 | | Logging.error("empty geometry collection found"); |
| 128 | | } else { |
| 129 | | Relation r = null; |
| 130 | | Way w = null; |
| 131 | | |
| 132 | | for (int i = 0; i < nGeometries; i++) { |
| 133 | | Geometry g = mp.getGeometryN(i); |
| 134 | | if (g instanceof Polygon) { |
| 135 | | Polygon p = (Polygon) g; |
| 136 | | // Do not create relation if there's only one polygon without interior ring |
| 137 | | // except if handler prefers it |
| 138 | | if (r == null && (nGeometries > 1 || p.getNumInteriorRing() > 0 || |
| 139 | | (handler != null && handler.preferMultipolygonToSimpleWay()))) { |
| 140 | | r = createMultipolygon(); |
| 141 | | } |
| 142 | | w = createOrGetWay(p.getExteriorRing()); |
| 143 | | if (r != null) { |
| 144 | | addWayToMp(r, "outer", w); |
| 145 | | for (int j = 0; j < p.getNumInteriorRing(); j++) { |
| 146 | | addWayToMp(r, "inner", createOrGetWay(p.getInteriorRingN(j))); |
| 147 | | } |
| 148 | | } |
| 149 | | } else if (g instanceof LineString) { |
| 150 | | w = createOrGetWay((LineString) g); |
| 151 | | } else if (g instanceof Point) { |
| 152 | | // Some belgian data sets hold points into collections ?! |
| 153 | | readNonGeometricAttributes(feature, createOrGetNode((Point) g)); |
| 154 | | } else { |
| 155 | | Logging.error("unsupported geometry : "+g); |
| 156 | | } |
| 157 | | } |
| 158 | | primitive = r != null ? r : w; |
| | 118 | Object geomObject = geometry.getValue(); |
| | 119 | if (geomObject instanceof Point) { // TODO: Support LineString and Polygon. |
| | 120 | // Sure you could have a Set of 1 object and join these 2 branches of |
| | 121 | // code, but I feel there would be a performance hit. |
| | 122 | OsmPrimitive primitive = createOrGetEmptyNode((Point) geomObject); |
| | 123 | readNonGeometricAttributes(feature, primitive); |
| | 124 | } else if (geomObject instanceof GeometryCollection) { // Deals with both MultiLineString and MultiPolygon |
| | 125 | Set<OsmPrimitive> primitives = processGeometryCollection((GeometryCollection) geomObject); |
| | 126 | for (OsmPrimitive prim : primitives) { |
| | 127 | readNonGeometricAttributes(feature, prim); |
| 171 | | if (primitive != null) { |
| 172 | | // Read primitive non geometric attributes |
| 173 | | readNonGeometricAttributes(feature, primitive); |
| | 142 | protected Set<OsmPrimitive> processGeometryCollection(GeometryCollection gc) throws TransformException { |
| | 143 | // A feture may be a collection. This set holds the items of the collection. |
| | 144 | Set<OsmPrimitive> primitives = new HashSet<>(); |
| | 145 | int nGeometries = gc.getNumGeometries(); |
| | 146 | if (nGeometries < 1) { |
| | 147 | Logging.error("empty geometry collection found"); |
| | 148 | } else { |
| | 149 | // Create the primitive "op" and add it to the set of primitives. |
| | 150 | for (int i = 0; i < nGeometries; i++) { |
| | 151 | OsmPrimitive op = null; |
| | 152 | Geometry g = gc.getGeometryN(i); |
| | 153 | if (g instanceof Polygon) { |
| | 154 | Relation r = (Relation) op; |
| | 155 | Polygon p = (Polygon) g; |
| | 156 | // Do not create relation if there's only one polygon without interior ring |
| | 157 | // except if handler prefers it |
| | 158 | if (r == null && (nGeometries > 1 || p.getNumInteriorRing() > 0 || |
| | 159 | (handler != null && handler.preferMultipolygonToSimpleWay()))) { |
| | 160 | r = createMultipolygon(); |
| | 161 | } |
| | 162 | if (r != null) { |
| | 163 | addWayToMp(r, "outer", createOrGetWay(p.getExteriorRing())); |
| | 164 | for (int j = 0; j < p.getNumInteriorRing(); j++) { |
| | 165 | addWayToMp(r, "inner", createOrGetWay(p.getInteriorRingN(j))); |
| | 166 | } |
| | 167 | } |
| | 168 | } else if (g instanceof LineString) { |
| | 169 | op = createOrGetWay((LineString) g); |
| | 170 | } else if (g instanceof Point) { |
| | 171 | op = createOrGetNode((Point) g); |
| | 172 | } else { |
| | 173 | Logging.error("unsupported geometry : "+g); |
| | 174 | } |
| | 175 | primitives.add(op); |