Ticket #20658: 20658.patch
File 20658.patch, 5.1 KB (added by , 4 years ago) |
---|
-
src/org/openstreetmap/josm/data/osm/DataSet.java
61 61 import org.openstreetmap.josm.spi.preferences.Config; 62 62 import org.openstreetmap.josm.tools.ListenerList; 63 63 import org.openstreetmap.josm.tools.Logging; 64 import org.openstreetmap.josm.tools.Stopwatch; 64 65 import org.openstreetmap.josm.tools.SubclassFilteredCollection; 65 66 66 67 /** … … 191 192 // Transparently register as projection change listener. No need to explicitly remove 192 193 // the listener, projection change listeners are managed as WeakReferences. 193 194 ProjectionRegistry.addProjectionChangeListener(this); 195 spatialIndexFilled = false; 194 196 } 195 197 196 198 /** … … 359 361 */ 360 362 private final Map<String, String> changeSetTags = new HashMap<>(); 361 363 364 private boolean spatialIndexFilled; 365 362 366 /** 363 367 * Replies the set of changeset tags to be applied when or if this is ever uploaded. 364 368 * @return the set of changeset tags … … 392 396 public List<Node> searchNodes(BBox bbox) { 393 397 lock.readLock().lock(); 394 398 try { 399 assertIndexFilled(); 395 400 return store.searchNodes(bbox); 396 401 } finally { 397 402 lock.readLock().unlock(); … … 407 412 public List<Way> searchWays(BBox bbox) { 408 413 lock.readLock().lock(); 409 414 try { 415 assertIndexFilled(); 410 416 return store.searchWays(bbox); 411 417 } finally { 412 418 lock.readLock().unlock(); … … 417 423 public List<Relation> searchRelations(BBox bbox) { 418 424 lock.readLock().lock(); 419 425 try { 426 assertIndexFilled(); 420 427 return store.searchRelations(bbox); 421 428 } finally { 422 429 lock.readLock().unlock(); … … 423 430 } 424 431 } 425 432 433 private void assertIndexFilled() { 434 if (!spatialIndexFilled) { 435 Stopwatch stopwatch = Stopwatch.createStarted(); 436 allPrimitives.forEach(p -> { 437 p.updatePosition(); 438 store.addPrimitive(p); 439 }); 440 spatialIndexFilled = true; 441 Logging.info(stopwatch.toString("Creation of spatial index for " + allPrimitives.size() + " objects")); 442 } 443 } 444 426 445 /** 427 446 * Searches for all primitives in the given bounding box 428 447 * … … 453 472 */ 454 473 @Override 455 474 public boolean containsNode(Node n) { 475 assertIndexFilled(); 456 476 return store.containsNode(n); 457 477 } 458 478 … … 466 486 */ 467 487 @Override 468 488 public boolean containsWay(Way w) { 489 assertIndexFilled(); 469 490 return store.containsWay(w); 470 491 } 471 492 … … 479 500 */ 480 501 @Override 481 502 public boolean containsRelation(Relation r) { 503 assertIndexFilled(); 482 504 return store.containsRelation(r); 483 505 } 484 506 … … 500 522 501 523 allPrimitives.add(primitive); 502 524 primitive.setDataset(this); 503 primitive.updatePosition(); // Set cached bbox for way and relation (required for reindexWay and reindexRelation to work properly) 504 store.addPrimitive(primitive); 525 if (spatialIndexFilled) { 526 primitive.updatePosition(); // Set cached bbox for way and relation (required for reindexWay and reindexRelation to work properly) 527 store.addPrimitive(primitive); 528 } 505 529 firePrimitivesAdded(Collections.singletonList(primitive), false); 506 530 }); 507 531 } … … 532 556 if (primitive.isSelected()) { 533 557 throw new DataIntegrityProblemException("Primitive was re-selected by a selection listener: " + primitive); 534 558 } 535 store.removePrimitive(primitive); 559 if (spatialIndexFilled) { 560 store.removePrimitive(primitive); 561 } 536 562 allPrimitives.remove(primitive); 537 563 primitive.setDataset(null); 538 564 } … … 1025 1051 } 1026 1052 1027 1053 void fireRelationMembersChanged(Relation r) { 1028 store.reindexRelation(r, Relation::updatePosition); 1054 if (spatialIndexFilled) { 1055 store.reindexRelation(r, Relation::updatePosition); 1056 } 1029 1057 fireEvent(new RelationMembersChangedEvent(this, r)); 1030 1058 } 1031 1059 1032 1060 void fireNodeMoved(Node node, LatLon newCoor, EastNorth eastNorth) { 1033 store.reindexNode(node, n -> n.setCoorInternal(newCoor, eastNorth), Way::updatePosition, Relation::updatePosition); 1061 if (spatialIndexFilled) { 1062 store.reindexNode(node, n -> n.setCoorInternal(newCoor, eastNorth), Way::updatePosition, Relation::updatePosition); 1063 } else { 1064 node.setCoorInternal(newCoor, eastNorth); 1065 } 1034 1066 fireEvent(new NodeMovedEvent(this, node)); 1035 1067 } 1036 1068 1037 1069 void fireWayNodesChanged(Way way) { 1038 if ( !way.isEmpty()) {1070 if (spatialIndexFilled && !way.isEmpty() ) { 1039 1071 store.reindexWay(way, Way::updatePosition, Relation::updatePosition); 1040 1072 } 1041 1073 fireEvent(new WayNodesChangedEvent(this, way));