Changeset 18478 in josm for trunk/src/org/openstreetmap/josm/data
- Timestamp:
- 2022-06-08T22:20:53+02:00 (3 years ago)
- Location:
- trunk/src/org/openstreetmap/josm/data
- Files:
-
- 2 edited
Legend:
- Unmodified
- Added
- Removed
-
trunk/src/org/openstreetmap/josm/data/imagery/vectortile/mapbox/MVTTile.java
r18473 r18478 5 5 import java.io.IOException; 6 6 import java.io.InputStream; 7 import java.util.ArrayList; 7 8 import java.util.Collection; 8 import java.util.HashSet;9 9 import java.util.List; 10 10 import java.util.Objects; … … 53 53 ProtobufParser parser = new ProtobufParser(inputStream); 54 54 Collection<ProtobufRecord> protobufRecords = parser.allRecords(); 55 this.layers = new HashSet<>(protobufRecords.size());55 this.layers = new ArrayList<>(protobufRecords.size()); 56 56 for (ProtobufRecord protoBufRecord : protobufRecords) { 57 57 if (protoBufRecord.getField() == Layer.LAYER_FIELD) { … … 66 66 } 67 67 } 68 this.layers = new HashSet<>(this.layers);68 this.layers = new ArrayList<>(this.layers); 69 69 70 70 this.extent = layers.stream().filter(Objects::nonNull).mapToInt(Layer::getExtent).max().orElse(Layer.DEFAULT_EXTENT); -
trunk/src/org/openstreetmap/josm/data/vector/VectorDataStore.java
r18477 r18478 13 13 import java.util.Collection; 14 14 import java.util.Collections; 15 import java.util.HashMap;16 15 import java.util.List; 17 16 import java.util.Map; … … 22 21 import org.openstreetmap.gui.jmapviewer.interfaces.ICoordinate; 23 22 import org.openstreetmap.josm.data.IQuadBucketType; 24 import org.openstreetmap.josm.data.coor.ILatLon;25 23 import org.openstreetmap.josm.data.coor.LatLon; 26 24 import org.openstreetmap.josm.data.imagery.vectortile.VectorTile; … … 163 161 164 162 private synchronized <T extends Tile & VectorTile> VectorNode pointToNode(T tile, Layer layer, 165 Collection<VectorPrimitive> featureObjects, int x, int y , final Map<ILatLon, VectorNode> nodeMap) {163 Collection<VectorPrimitive> featureObjects, int x, int y) { 166 164 final BBox tileBbox; 167 165 if (tile instanceof IQuadBucketType) { … … 179 177 tileBbox.getMinLon() + (tileBbox.getMaxLon() - tileBbox.getMinLon()) * x / layerExtent 180 178 ); 181 if (nodeMap.containsKey(coords)) {182 return nodeMap.get(coords);183 }184 179 final Collection<VectorNode> nodes = this.store 185 180 .searchNodes(new BBox(coords.lon(), coords.lat(), VectorDataSet.DUPE_NODE_DISTANCE)); … … 212 207 node.setCoor(coords); 213 208 featureObjects.add(node); 214 nodeMap.put(node.getCoor(), node);215 209 return node; 216 210 } 217 211 218 212 private <T extends Tile & VectorTile> List<VectorWay> pathToWay(T tile, Layer layer, 219 Collection<VectorPrimitive> featureObjects, Path2D shape , Map<ILatLon, VectorNode> nodeMap) {213 Collection<VectorPrimitive> featureObjects, Path2D shape) { 220 214 final PathIterator pathIterator = shape.getPathIterator(null); 221 215 final List<VectorWay> ways = new ArrayList<>( 222 Utils.filteredCollection(pathIteratorToObjects(tile, layer, featureObjects, pathIterator , nodeMap), VectorWay.class));216 Utils.filteredCollection(pathIteratorToObjects(tile, layer, featureObjects, pathIterator), VectorWay.class)); 223 217 // These nodes technically do not exist, so we shouldn't show them 224 218 for (VectorWay way : ways) { … … 234 228 235 229 private <T extends Tile & VectorTile> List<VectorPrimitive> pathIteratorToObjects(T tile, Layer layer, 236 Collection<VectorPrimitive> featureObjects, PathIterator pathIterator , Map<ILatLon, VectorNode> nodeMap) {230 Collection<VectorPrimitive> featureObjects, PathIterator pathIterator) { 237 231 final List<VectorNode> nodes = new ArrayList<>(); 238 232 final double[] coords = new double[6]; … … 255 249 } 256 250 if (PathIterator.SEG_MOVETO == type || PathIterator.SEG_LINETO == type) { 257 final VectorNode node = pointToNode(tile, layer, featureObjects, (int) coords[0], (int) coords[1] , nodeMap);251 final VectorNode node = pointToNode(tile, layer, featureObjects, (int) coords[0], (int) coords[1]); 258 252 nodes.add(node); 259 253 } else if (PathIterator.SEG_CLOSE != type) { … … 272 266 273 267 private <T extends Tile & VectorTile> VectorRelation areaToRelation(T tile, Layer layer, 274 Collection<VectorPrimitive> featureObjects, Area area , Map<ILatLon, VectorNode> nodeMap) {268 Collection<VectorPrimitive> featureObjects, Area area) { 275 269 VectorRelation vectorRelation = new VectorRelation(layer.getName()); 276 for (VectorPrimitive member : pathIteratorToObjects(tile, layer, featureObjects, area.getPathIterator(null) , nodeMap)) {270 for (VectorPrimitive member : pathIteratorToObjects(tile, layer, featureObjects, area.getPathIterator(null))) { 277 271 final String role; 278 272 if (member instanceof VectorWay && ((VectorWay) member).isClosed()) { … … 294 288 // Using a map reduces the cost of addFeatureData from 2,715,158,632 bytes to 235,042,184 bytes (-91.3%) 295 289 // This was somewhat variant, with some runs being closer to ~560 MB (still -80%). 296 final Map<ILatLon, VectorNode> nodeMap = new HashMap<>();297 290 for (Layer layer : tile.getLayers()) { 298 291 Map<GeometryTypes, List<Feature>> grouped = layer.getFeatures().stream().collect(Collectors.groupingBy(Feature::getGeometryType)); … … 300 293 for (GeometryTypes type : GeometryTypes.values()) { 301 294 if (grouped.containsKey(type)) { 302 addFeatureData(tile, layer, grouped.get(type) , nodeMap);295 addFeatureData(tile, layer, grouped.get(type)); 303 296 } 304 297 } … … 313 306 } 314 307 315 private <T extends Tile & VectorTile> void addFeatureData(T tile, Layer layer, Collection<Feature> features , Map<ILatLon, VectorNode> nodeMap) {308 private <T extends Tile & VectorTile> void addFeatureData(T tile, Layer layer, Collection<Feature> features) { 316 309 for (Feature feature : features) { 317 310 try { 318 addFeatureData(tile, layer, feature , nodeMap);311 addFeatureData(tile, layer, feature); 319 312 } catch (IllegalArgumentException e) { 320 313 Logging.error("Cannot add vector data for feature {0} of tile {1}: {2}", feature, tile, e.getMessage()); … … 324 317 } 325 318 326 private <T extends Tile & VectorTile> void addFeatureData(T tile, Layer layer, Feature feature , Map<ILatLon, VectorNode> nodeMap) {319 private <T extends Tile & VectorTile> void addFeatureData(T tile, Layer layer, Feature feature) { 327 320 // This will typically be larger than primaryFeatureObjects, but this at least avoids quite a few ArrayList#grow calls 328 321 List<VectorPrimitive> featureObjects = new ArrayList<>(feature.getGeometryObject().getShapes().size()); 329 322 List<VectorPrimitive> primaryFeatureObjects = new ArrayList<>(feature.getGeometryObject().getShapes().size()); 330 323 for (Shape shape : feature.getGeometryObject().getShapes()) { 331 primaryFeatureObjects.add(shapeToPrimaryFeatureObject(tile, layer, shape, featureObjects , nodeMap));324 primaryFeatureObjects.add(shapeToPrimaryFeatureObject(tile, layer, shape, featureObjects)); 332 325 } 333 326 final VectorPrimitive primitive; … … 374 367 375 368 private <T extends Tile & VectorTile> VectorPrimitive shapeToPrimaryFeatureObject( 376 T tile, Layer layer, Shape shape, List<VectorPrimitive> featureObjects , Map<ILatLon, VectorNode> nodeMap) {369 T tile, Layer layer, Shape shape, List<VectorPrimitive> featureObjects) { 377 370 final VectorPrimitive primitive; 378 371 if (shape instanceof Ellipse2D) { 379 372 primitive = pointToNode(tile, layer, featureObjects, 380 (int) ((Ellipse2D) shape).getCenterX(), (int) ((Ellipse2D) shape).getCenterY() , nodeMap);373 (int) ((Ellipse2D) shape).getCenterX(), (int) ((Ellipse2D) shape).getCenterY()); 381 374 } else if (shape instanceof Path2D) { 382 primitive = pathToWay(tile, layer, featureObjects, (Path2D) shape , nodeMap).stream().findFirst().orElse(null);375 primitive = pathToWay(tile, layer, featureObjects, (Path2D) shape).stream().findFirst().orElse(null); 383 376 } else if (shape instanceof Area) { 384 primitive = areaToRelation(tile, layer, featureObjects, (Area) shape , nodeMap);377 primitive = areaToRelation(tile, layer, featureObjects, (Area) shape); 385 378 primitive.put(RELATION_TYPE, MULTIPOLYGON_TYPE); 386 379 } else {
Note:
See TracChangeset
for help on using the changeset viewer.