Ticket #6886: patch.diff
File patch.diff, 59.1 KB (added by , 13 years ago) |
---|
-
src/org/openstreetmap/josm/actions/ExtensionFileFilter.java
40 40 String[] importerNames = { 41 41 "org.openstreetmap.josm.io.OsmImporter", 42 42 "org.openstreetmap.josm.io.OsmGzipImporter", 43 "org.openstreetmap.josm.io.PbfImporter", 43 44 "org.openstreetmap.josm.io.GpxImporter", 44 45 "org.openstreetmap.josm.io.NMEAImporter", 45 46 "org.openstreetmap.josm.io.OsmBzip2Importer", -
src/org/openstreetmap/josm/data/coor/LatLon.java
63 63 public static boolean isValidLon(double lon) { 64 64 return lon >= -180d && lon <= 180d; 65 65 } 66 67 /** 68 * Replies true if lat is in the range [-90,90] and lon is in the range [-180,180] 69 * 70 * @return true if lat is in the range [-90,90] and lon is in the range [-180,180] 71 */ 72 public boolean isValid() { 73 return isValidLat(lat()) && isValidLon(lon()); 74 } 66 75 67 76 /** 68 77 * Replies the coordinate in degrees/minutes/seconds format -
src/org/openstreetmap/josm/data/osm/AbstractPrimitive.java
86 86 * 0 if it wasn't uploaded to a changeset yet of if the changeset 87 87 * id isn't known. 88 88 */ 89 protected intchangesetId;89 protected long changesetId; 90 90 91 91 protected int timestamp; 92 92 … … 233 233 * @return the id of the changeset this primitive was last uploaded to. 234 234 */ 235 235 @Override 236 public intgetChangesetId() {236 public long getChangesetId() { 237 237 return changesetId; 238 238 } 239 239 … … 246 246 * @throws IllegalArgumentException thrown if id < 0 247 247 */ 248 248 @Override 249 public void setChangesetId( intchangesetId) throws IllegalStateException, IllegalArgumentException {249 public void setChangesetId(long changesetId) throws IllegalStateException, IllegalArgumentException { 250 250 if (this.changesetId == changesetId) 251 251 return; 252 252 if (changesetId < 0) … … 254 254 if (isNew() && changesetId > 0) 255 255 throw new IllegalStateException(tr("Cannot assign a changesetId > 0 to a new primitive. Value of changesetId is {0}", changesetId)); 256 256 257 intold = this.changesetId;257 long old = this.changesetId; 258 258 this.changesetId = changesetId; 259 259 } 260 260 -
src/org/openstreetmap/josm/data/osm/Changeset.java
17 17 */ 18 18 public final class Changeset implements Tagged { 19 19 /** the changeset id */ 20 private intid;20 private long id; 21 21 /** the user who owns the changeset */ 22 22 private User user; 23 23 /** date this changeset was created at */ … … 52 52 * 53 53 * @param id the id 54 54 */ 55 public Changeset( intid) {55 public Changeset(long id) { 56 56 this.id = id; 57 57 this.incomplete = id > 0; 58 58 this.tags = new HashMap<String, String>(); … … 83 83 } 84 84 85 85 public int compareTo(Changeset other) { 86 return Integer.valueOf(getId()).compareTo(other.getId());86 return Long.valueOf(getId()).compareTo(other.getId()); 87 87 } 88 88 89 89 public String getName() { … … 95 95 return formatter.format(this); 96 96 } 97 97 98 public intgetId() {98 public long getId() { 99 99 return id; 100 100 } 101 101 102 public void setId( intid) {102 public void setId(long id) { 103 103 this.id = id; 104 104 } 105 105 … … 228 228 return false; 229 229 return true; 230 230 } 231 231 232 /* (non-Javadoc) 233 * @see java.lang.Object#hashCode() 234 */ 232 235 @Override 233 236 public int hashCode() { 234 if (id > 0) 235 return id; 236 else 237 if (id > 0) { 238 final int prime = 31; 239 int result = 1; 240 result = prime * result + (int) (id ^ (id >>> 32)); 241 return result; 242 } else { 237 243 return super.hashCode(); 244 } 238 245 } 239 246 240 247 @Override -
src/org/openstreetmap/josm/data/osm/ChangesetCache.java
46 46 } 47 47 48 48 /** the cached changesets */ 49 private final Map< Integer, Changeset> cache = new HashMap<Integer, Changeset>();49 private final Map<Long, Changeset> cache = new HashMap<Long, Changeset>(); 50 50 51 51 private final CopyOnWriteArrayList<ChangesetCacheListener> listeners = 52 52 new CopyOnWriteArrayList<ChangesetCacheListener>(); … … 106 106 fireChangesetCacheEvent(e); 107 107 } 108 108 109 public boolean contains( intid) {109 public boolean contains(long id) { 110 110 if (id <=0) return false; 111 111 return cache.get(id) != null; 112 112 } … … 117 117 return contains(cs.getId()); 118 118 } 119 119 120 public Changeset get( intid) {120 public Changeset get(long id) { 121 121 return cache.get(id); 122 122 } 123 123 … … 125 125 return new HashSet<Changeset>(cache.values()); 126 126 } 127 127 128 protected void remove( intid, DefaultChangesetCacheEvent e) {128 protected void remove(long id, DefaultChangesetCacheEvent e) { 129 129 if (id <= 0) return; 130 130 Changeset cs = cache.get(id); 131 131 if (cs == null) return; … … 133 133 e.rememberRemovedChangeset(cs); 134 134 } 135 135 136 public void remove( intid) {136 public void remove(long id) { 137 137 DefaultChangesetCacheEvent e = new DefaultChangesetCacheEvent(this); 138 138 remove(id, e); 139 139 if (! e.isEmpty()) { -
src/org/openstreetmap/josm/data/osm/DataSet.java
1058 1058 fireEvent(new WayNodesChangedEvent(this, way)); 1059 1059 } 1060 1060 1061 void fireChangesetIdChanged(OsmPrimitive primitive, int oldChangesetId, intnewChangesetId) {1061 void fireChangesetIdChanged(OsmPrimitive primitive, long oldChangesetId, long newChangesetId) { 1062 1062 fireEvent(new ChangesetIdChangedEvent(this, Collections.singletonList(primitive), oldChangesetId, newChangesetId)); 1063 1063 } 1064 1064 -
src/org/openstreetmap/josm/data/osm/IPrimitive.java
27 27 Date getTimestamp(); 28 28 void setTimestamp(Date timestamp); 29 29 boolean isTimestampEmpty(); 30 intgetChangesetId();31 void setChangesetId( intchangesetId);30 long getChangesetId(); 31 void setChangesetId(long changesetId); 32 32 33 33 void visit(PrimitiveVisitor visitor); 34 34 String getName(); -
src/org/openstreetmap/josm/data/osm/OsmPrimitive.java
384 384 } 385 385 386 386 @Override 387 public void setChangesetId( intchangesetId) throws IllegalStateException, IllegalArgumentException {387 public void setChangesetId(long changesetId) throws IllegalStateException, IllegalArgumentException { 388 388 boolean locked = writeLock(); 389 389 try { 390 intold = this.changesetId;390 long old = this.changesetId; 391 391 super.setChangesetId(changesetId); 392 392 if (dataSet != null) { 393 393 dataSet.fireChangesetIdChanged(this, old, changesetId); -
src/org/openstreetmap/josm/data/osm/event/ChangesetIdChangedEvent.java
9 9 public class ChangesetIdChangedEvent extends AbstractDatasetChangedEvent { 10 10 11 11 private final List<OsmPrimitive> primitives; 12 private final intoldChangesetId;13 private final intnewChangesetId;12 private final long oldChangesetId; 13 private final long newChangesetId; 14 14 15 public ChangesetIdChangedEvent(DataSet dataSet, List<OsmPrimitive> primitives, int oldChangesetId, intnewChangesetId) {15 public ChangesetIdChangedEvent(DataSet dataSet, List<OsmPrimitive> primitives, long oldChangesetId, long newChangesetId) { 16 16 super(dataSet); 17 17 this.primitives = primitives; 18 18 this.oldChangesetId = oldChangesetId; … … 34 34 return DatasetEventType.CHANGESET_ID_CHANGED; 35 35 } 36 36 37 public intgetOldChangesetId() {37 public long getOldChangesetId() { 38 38 return oldChangesetId; 39 39 } 40 40 41 public intgetNewChangesetId() {41 public long getNewChangesetId() { 42 42 return newChangesetId; 43 43 } 44 44 -
src/org/openstreetmap/josm/gui/dialogs/ChangesetDialog.java
256 256 public void mouseClicked(MouseEvent e) { 257 257 if (!SwingUtilities.isLeftMouseButton(e) || e.getClickCount() < 2) 258 258 return; 259 Set< Integer> sel = getCurrentChangesetListModel().getSelectedChangesetIds();259 Set<Long> sel = getCurrentChangesetListModel().getSelectedChangesetIds(); 260 260 if (sel.isEmpty()) 261 261 return; 262 262 if (Main.main.getCurrentDataSet() == null) … … 292 292 updateEnabledState(); 293 293 } 294 294 295 public void selectObjectsByChangesetIds(DataSet ds, Set< Integer> ids) {295 public void selectObjectsByChangesetIds(DataSet ds, Set<Long> ids) { 296 296 if (ds == null || ids == null) 297 297 return; 298 298 Set<OsmPrimitive> sel = new HashSet<OsmPrimitive>(); … … 308 308 if (Main.main.getEditLayer() == null) 309 309 return; 310 310 ChangesetListModel model = getCurrentChangesetListModel(); 311 Set< Integer> sel = model.getSelectedChangesetIds();311 Set<Long> sel = model.getSelectedChangesetIds(); 312 312 if (sel.isEmpty()) 313 313 return; 314 314 … … 344 344 345 345 public void actionPerformed(ActionEvent arg0) { 346 346 ChangesetListModel model = getCurrentChangesetListModel(); 347 Set< Integer> sel = model.getSelectedChangesetIds();347 Set<Long> sel = model.getSelectedChangesetIds(); 348 348 if (sel.isEmpty()) 349 349 return; 350 350 ChangesetHeaderDownloadTask task = new ChangesetHeaderDownloadTask(sel); … … 448 448 putValue(SMALL_ICON, ImageProvider.get("dialogs/changeset", "changesetmanager")); 449 449 } 450 450 451 protected void launchChangesetManager(Collection< Integer> toSelect) {451 protected void launchChangesetManager(Collection<Long> toSelect) { 452 452 ChangesetCacheManager cm = ChangesetCacheManager.getInstance(); 453 453 if (cm.isVisible()) { 454 454 cm.setExtendedState(Frame.NORMAL); … … 464 464 465 465 public void actionPerformed(ActionEvent arg0) { 466 466 ChangesetListModel model = getCurrentChangesetListModel(); 467 Set< Integer> sel = model.getSelectedChangesetIds();468 final Set< Integer> toDownload = new HashSet<Integer>();467 Set<Long> sel = model.getSelectedChangesetIds(); 468 final Set<Long> toDownload = new HashSet<Long>(); 469 469 ChangesetCache cc = ChangesetCache.getInstance(); 470 for ( intid: sel) {470 for (long id: sel) { 471 471 if (!cc.contains(id)) { 472 472 toDownload.add(id); 473 473 } -
src/org/openstreetmap/josm/gui/dialogs/InspectPrimitiveDialog.java
221 221 add(tr("Edited by: "), o.getUser() == null ? tr("<new object>") 222 222 : getNameAndId(o.getUser().getName(), o.getUser().getId())); 223 223 add(tr("Version: "), Integer.toString(o.getVersion())); 224 add(tr("In changeset: "), Integer.toString(o.getChangesetId()));224 add(tr("In changeset: "), Long.toString(o.getChangesetId())); 225 225 } 226 226 227 227 void addAttributes(OsmPrimitive o) { -
src/org/openstreetmap/josm/gui/dialogs/changeset/ChangesetCacheManager.java
606 606 * 607 607 * @param ids the collection of ids. If null, the selection is cleared. 608 608 */ 609 public void setSelectedChangesetsById(Collection< Integer> ids) {609 public void setSelectedChangesetsById(Collection<Long> ids) { 610 610 if (ids == null) { 611 611 setSelectedChangesets(null); 612 612 return; 613 613 } 614 614 Set<Changeset> toSelect = new HashSet<Changeset>(); 615 615 ChangesetCache cc = ChangesetCache.getInstance(); 616 for ( intid: ids) {616 for (long id: ids) { 617 617 if (cc.contains(id)) { 618 618 toSelect.add(cc.get(id)); 619 619 } -
src/org/openstreetmap/josm/gui/dialogs/changeset/ChangesetCacheManagerModel.java
89 89 * 90 90 * @return a set of ids of the selected changesets 91 91 */ 92 public Set< Integer> getSelectedChangesetIds() {93 Set< Integer> ret = new HashSet<Integer>();92 public Set<Long> getSelectedChangesetIds() { 93 Set<Long> ret = new HashSet<Long>(); 94 94 for (Changeset cs: getSelectedChangesets()) { 95 95 ret.add(cs.getId()); 96 96 } -
src/org/openstreetmap/josm/gui/dialogs/changeset/ChangesetCacheTableCellRenderer.java
41 41 } 42 42 43 43 protected void renderId(Changeset cs) { 44 setText( Integer.toString(cs.getId()));44 setText(Long.toString(cs.getId())); 45 45 setToolTipText(""); 46 46 } 47 47 -
src/org/openstreetmap/josm/gui/dialogs/changeset/ChangesetContentDownloadTask.java
31 31 public class ChangesetContentDownloadTask extends PleaseWaitRunnable implements ChangesetDownloadTask{ 32 32 33 33 /** the list of changeset ids to download */ 34 private final List< Integer> toDownload = new ArrayList<Integer>();34 private final List<Long> toDownload = new ArrayList<Long>(); 35 35 /** true if the task was canceled */ 36 36 private boolean canceled; 37 37 /** keeps the last exception thrown in the task, if any */ … … 46 46 * 47 47 * @param ids the collection of ids. May be null. 48 48 */ 49 protected void init(Collection< Integer> ids) {49 protected void init(Collection<Long> ids) { 50 50 if (ids == null) { 51 51 ids = Collections.emptyList(); 52 52 } 53 for ( Integerid: ids) {53 for (Long id: ids) { 54 54 if (id == null || id <= 0) { 55 55 continue; 56 56 } … … 65 65 * @param changesetId the changeset id. >0 required. 66 66 * @throws IllegalArgumentException thrown if changesetId <= 0 67 67 */ 68 public ChangesetContentDownloadTask( intchangesetId) throws IllegalArgumentException{68 public ChangesetContentDownloadTask(long changesetId) throws IllegalArgumentException{ 69 69 super(tr("Downloading changeset content"), false /* don't ignore exceptions */); 70 70 if (changesetId <= 0) 71 71 throw new IllegalArgumentException(MessageFormat.format("Expected integer value > 0 for parameter ''{0}'', got ''{1}''", "changesetId", changesetId)); … … 78 78 * 79 79 * @param changesetIds the changeset ids. Empty collection assumed, if null. 80 80 */ 81 public ChangesetContentDownloadTask(Collection< Integer> changesetIds) {81 public ChangesetContentDownloadTask(Collection<Long> changesetIds) { 82 82 super(tr("Downloading changeset content"), false /* don't ignore exceptions */); 83 83 init(changesetIds); 84 84 } … … 91 91 * @throws IllegalArgumentException thrown if changesetId <= 0 92 92 * @throws IllegalArgumentException thrown if parent is null 93 93 */ 94 public ChangesetContentDownloadTask(Component parent, intchangesetId) throws IllegalArgumentException{94 public ChangesetContentDownloadTask(Component parent, long changesetId) throws IllegalArgumentException{ 95 95 super(parent, tr("Downloading changeset content"), false /* don't ignore exceptions */); 96 96 if (changesetId <= 0) 97 97 throw new IllegalArgumentException(MessageFormat.format("Expected integer value > 0 for parameter ''{0}'', got ''{1}''", "changesetId", changesetId)); … … 106 106 * @param changesetIds the changeset ids. Empty collection assumed, if null. 107 107 * @throws IllegalArgumentException thrown if parent is null 108 108 */ 109 public ChangesetContentDownloadTask(Component parent, Collection< Integer> changesetIds) throws IllegalArgumentException {109 public ChangesetContentDownloadTask(Component parent, Collection<Long> changesetIds) throws IllegalArgumentException { 110 110 super(parent, tr("Downloading changeset content"), false /* don't ignore exceptions */); 111 111 init(changesetIds); 112 112 } … … 119 119 * @return true if the local {@see ChangesetCache} already includes the changeset with 120 120 * id <code>changesetId</code> 121 121 */ 122 protected boolean isAvailableLocally( intchangesetId) {122 protected boolean isAvailableLocally(long changesetId) { 123 123 return ChangesetCache.getInstance().get(changesetId) != null; 124 124 } 125 125 … … 130 130 * @param changesetId the changeset id 131 131 * @throws OsmTransferException thrown if something went wrong 132 132 */ 133 protected void downloadChangeset( intchangesetId) throws OsmTransferException {133 protected void downloadChangeset(long changesetId) throws OsmTransferException { 134 134 synchronized(this) { 135 135 reader = new OsmServerChangesetReader(); 136 136 } … … 164 164 try { 165 165 getProgressMonitor().setTicksCount(toDownload.size()); 166 166 int i=0; 167 for ( intid: toDownload) {167 for (long id: toDownload) { 168 168 i++; 169 169 if (!isAvailableLocally(id)) { 170 170 getProgressMonitor().setCustomText(tr("({0}/{1}) Downloading changeset {2}...", i, toDownload.size(), id)); -
src/org/openstreetmap/josm/gui/dialogs/changeset/ChangesetDetailPanel.java
206 206 protected void updateView(Changeset cs) { 207 207 String msg; 208 208 if (cs == null) return; 209 tfID.setText( Integer.toString(cs.getId()));209 tfID.setText(Long.toString(cs.getId())); 210 210 String comment = cs.get("comment"); 211 211 taComment.setText(comment == null ? "" : comment); 212 212 -
src/org/openstreetmap/josm/gui/dialogs/changeset/ChangesetHeaderDownloadTask.java
64 64 changesets = Collections.emptyList(); 65 65 } 66 66 67 HashSet< Integer> ids = new HashSet<Integer>();67 HashSet<Long> ids = new HashSet<Long>(); 68 68 for (Changeset cs: changesets) { 69 69 if (cs == null || cs.isNew()) { 70 70 continue; … … 78 78 79 79 } 80 80 81 private Set< Integer> idsToDownload;81 private Set<Long> idsToDownload; 82 82 private OsmServerChangesetReader reader; 83 83 private boolean canceled; 84 84 private Exception lastException; 85 85 private Set<Changeset> downloadedChangesets; 86 86 87 protected void init(Collection< Integer> ids) {87 protected void init(Collection<Long> ids) { 88 88 if (ids == null) { 89 89 ids = Collections.emptyList(); 90 90 } 91 idsToDownload = new HashSet< Integer>();91 idsToDownload = new HashSet<Long>(); 92 92 if (ids == null || ids.isEmpty()) 93 93 return; 94 for ( intid: ids) {94 for (long id: ids) { 95 95 if (id <= 0) { 96 96 continue; 97 97 } … … 107 107 * 108 108 * @param ids the collection of ids. Empty collection assumed if null. 109 109 */ 110 public ChangesetHeaderDownloadTask(Collection< Integer> ids) {110 public ChangesetHeaderDownloadTask(Collection<Long> ids) { 111 111 // parent for dialog is Main.parent 112 112 super(tr("Download changesets"), false /* don't ignore exceptions */); 113 113 init(ids); … … 123 123 * @param ids the collection of ids. Empty collection assumed if null. 124 124 * @throws IllegalArgumentException thrown if dialogParent is null 125 125 */ 126 public ChangesetHeaderDownloadTask(Component dialogParent, Collection< Integer> ids) throws IllegalArgumentException{126 public ChangesetHeaderDownloadTask(Component dialogParent, Collection<Long> ids) throws IllegalArgumentException{ 127 127 super(dialogParent,tr("Download changesets"), false /* don't ignore exceptions */); 128 128 init(ids); 129 129 } -
src/org/openstreetmap/josm/gui/dialogs/changeset/ChangesetListModel.java
39 39 return ret; 40 40 } 41 41 42 public Set< Integer> getSelectedChangesetIds() {43 Set< Integer> ret = new HashSet<Integer>();42 public Set<Long> getSelectedChangesetIds() { 43 Set<Long> ret = new HashSet<Long>(); 44 44 for (int i=0; i < getSize(); i++) { 45 45 if (selectionModel.isSelectedIndex(i)) { 46 46 ret.add(data.get(i).getId()); -
src/org/openstreetmap/josm/gui/dialogs/changeset/SingleChangesetDownloadPanel.java
83 83 public void actionPerformed(ActionEvent arg0) { 84 84 if (!isEnabled()) 85 85 return; 86 intid = getChangesetId();86 long id = getChangesetId(); 87 87 if (id == 0) return; 88 88 ChangesetContentDownloadTask task = new ChangesetContentDownloadTask( 89 89 SingleChangesetDownloadPanel.this, -
src/org/openstreetmap/josm/io/AbstractReader.java
1 // License: GPL. For details, see LICENSE file. 2 package org.openstreetmap.josm.io; 3 4 import static org.openstreetmap.josm.tools.I18n.tr; 5 6 import java.util.ArrayList; 7 import java.util.Collection; 8 import java.util.HashMap; 9 import java.util.List; 10 import java.util.Map; 11 12 import org.openstreetmap.josm.data.osm.Changeset; 13 import org.openstreetmap.josm.data.osm.DataSet; 14 import org.openstreetmap.josm.data.osm.Node; 15 import org.openstreetmap.josm.data.osm.OsmPrimitive; 16 import org.openstreetmap.josm.data.osm.OsmPrimitiveType; 17 import org.openstreetmap.josm.data.osm.PrimitiveId; 18 import org.openstreetmap.josm.data.osm.Relation; 19 import org.openstreetmap.josm.data.osm.RelationMember; 20 import org.openstreetmap.josm.data.osm.SimplePrimitiveId; 21 import org.openstreetmap.josm.data.osm.Way; 22 23 /** 24 * Base class for OsmReader (XML file format) and PbfReader (Protobuf file format) 25 * @author Vincent 26 * 27 */ 28 public abstract class AbstractReader { 29 30 /** 31 * Used as a temporary storage for relation members, before they 32 * are resolved into pointers to real objects. 33 */ 34 protected static class RelationMemberData { 35 public OsmPrimitiveType type; 36 public long id; 37 public String role; 38 } 39 40 /** 41 * The dataset to add parsed objects to. 42 */ 43 protected final DataSet ds = new DataSet(); 44 45 protected Changeset uploadChangeset; 46 47 /** the map from external ids to read OsmPrimitives. External ids are 48 * longs too, but in contrast to internal ids negative values are used 49 * to identify primitives unknown to the OSM server 50 */ 51 protected Map<PrimitiveId, OsmPrimitive> externalIdMap = new HashMap<PrimitiveId, OsmPrimitive>(); 52 53 /** 54 * Data structure for the remaining way objects 55 */ 56 protected Map<Long, Collection<Long>> ways = new HashMap<Long, Collection<Long>>(); 57 58 /** 59 * Data structure for relation objects 60 */ 61 protected Map<Long, Collection<RelationMemberData>> relations = new HashMap<Long, Collection<RelationMemberData>>(); 62 63 /** 64 * Replies the parsed data set 65 * 66 * @return the parsed data set 67 */ 68 public DataSet getDataSet() { 69 return ds; 70 } 71 72 /** 73 * Processes the parsed nodes after parsing. Just adds them to 74 * the dataset 75 * 76 */ 77 private void processNodesAfterParsing() { 78 for (OsmPrimitive primitive: externalIdMap.values()) { 79 if (primitive instanceof Node) { 80 this.ds.addPrimitive(primitive); 81 } 82 } 83 } 84 85 /** 86 * Processes the ways after parsing. Rebuilds the list of nodes of each way and 87 * adds the way to the dataset 88 * 89 * @throws IllegalDataException thrown if a data integrity problem is detected 90 */ 91 private void processWaysAfterParsing() throws IllegalDataException{ 92 for (Long externalWayId: ways.keySet()) { 93 Way w = (Way)externalIdMap.get(new SimplePrimitiveId(externalWayId, OsmPrimitiveType.WAY)); 94 List<Node> wayNodes = new ArrayList<Node>(); 95 for (long id : ways.get(externalWayId)) { 96 Node n = (Node)externalIdMap.get(new SimplePrimitiveId(id, OsmPrimitiveType.NODE)); 97 if (n == null) { 98 if (id <= 0) 99 throw new IllegalDataException ( 100 tr("Way with external ID ''{0}'' includes missing node with external ID ''{1}''.", 101 externalWayId, 102 id)); 103 // create an incomplete node if necessary 104 // 105 n = (Node)ds.getPrimitiveById(id,OsmPrimitiveType.NODE); 106 if (n == null) { 107 n = new Node(id); 108 ds.addPrimitive(n); 109 } 110 } 111 if (n.isDeleted()) { 112 System.out.println(tr("Deleted node {0} is part of way {1}", id, w.getId())); 113 } else { 114 wayNodes.add(n); 115 } 116 } 117 w.setNodes(wayNodes); 118 if (w.hasIncompleteNodes()) { 119 System.out.println(tr("Way {0} with {1} nodes has incomplete nodes because at least one node was missing in the loaded data.", 120 externalWayId, w.getNodesCount())); 121 } 122 ds.addPrimitive(w); 123 } 124 } 125 126 /** 127 * Completes the parsed relations with its members. 128 * 129 * @throws IllegalDataException thrown if a data integrity problem is detected, i.e. if a 130 * relation member refers to a local primitive which wasn't available in the data 131 * 132 */ 133 private void processRelationsAfterParsing() throws IllegalDataException { 134 135 // First add all relations to make sure that when relation reference other relation, the referenced will be already in dataset 136 for (Long externalRelationId : relations.keySet()) { 137 Relation relation = (Relation) externalIdMap.get( 138 new SimplePrimitiveId(externalRelationId, OsmPrimitiveType.RELATION) 139 ); 140 ds.addPrimitive(relation); 141 } 142 143 for (Long externalRelationId : relations.keySet()) { 144 Relation relation = (Relation) externalIdMap.get( 145 new SimplePrimitiveId(externalRelationId, OsmPrimitiveType.RELATION) 146 ); 147 List<RelationMember> relationMembers = new ArrayList<RelationMember>(); 148 for (RelationMemberData rm : relations.get(externalRelationId)) { 149 OsmPrimitive primitive = null; 150 151 // lookup the member from the map of already created primitives 152 primitive = externalIdMap.get(new SimplePrimitiveId(rm.id, rm.type)); 153 154 if (primitive == null) { 155 if (rm.id <= 0) 156 // relation member refers to a primitive with a negative id which was not 157 // found in the data. This is always a data integrity problem and we abort 158 // with an exception 159 // 160 throw new IllegalDataException( 161 tr("Relation with external id ''{0}'' refers to a missing primitive with external id ''{1}''.", 162 externalRelationId, 163 rm.id)); 164 165 // member refers to OSM primitive which was not present in the parsed data 166 // -> create a new incomplete primitive and add it to the dataset 167 // 168 primitive = ds.getPrimitiveById(rm.id, rm.type); 169 if (primitive == null) { 170 switch (rm.type) { 171 case NODE: 172 primitive = new Node(rm.id); break; 173 case WAY: 174 primitive = new Way(rm.id); break; 175 case RELATION: 176 primitive = new Relation(rm.id); break; 177 default: throw new AssertionError(); // can't happen 178 } 179 180 ds.addPrimitive(primitive); 181 externalIdMap.put(new SimplePrimitiveId(rm.id, rm.type), primitive); 182 } 183 } 184 if (primitive.isDeleted()) { 185 System.out.println(tr("Deleted member {0} is used by relation {1}", primitive.getId(), relation.getId())); 186 } else { 187 relationMembers.add(new RelationMember(rm.role, primitive)); 188 } 189 } 190 relation.setMembers(relationMembers); 191 } 192 } 193 194 private void processChangesetAfterParsing() { 195 if (uploadChangeset != null) { 196 for (Map.Entry<String, String> e : uploadChangeset.getKeys().entrySet()) { 197 ds.addChangeSetTag(e.getKey(), e.getValue()); 198 } 199 } 200 } 201 202 protected final void prepareDataSet() throws IllegalDataException { 203 try { 204 ds.beginUpdate(); 205 processNodesAfterParsing(); 206 processWaysAfterParsing(); 207 processRelationsAfterParsing(); 208 processChangesetAfterParsing(); 209 } finally { 210 ds.endUpdate(); 211 } 212 } 213 } -
src/org/openstreetmap/josm/io/AllFormatsImporter.java
12 12 */ 13 13 public class AllFormatsImporter extends FileImporter { 14 14 public AllFormatsImporter() { 15 super(new ExtensionFileFilter("osm,xml,osm.gz,osm.bz2,osm.bz, gpx,gpx.gz,nmea,nme,nma,log,txt,wms,jpg", "", tr("All Formats")15 super(new ExtensionFileFilter("osm,xml,osm.gz,osm.bz2,osm.bz,osm.pbf,gpx,gpx.gz,nmea,nme,nma,log,txt,wms,jpg", "", tr("All Formats") 16 16 + " (*.gpx *.osm *.nmea *.jpg ...)")); 17 17 } 18 18 @Override public boolean acceptFile(File pathname) { -
src/org/openstreetmap/josm/io/OsmImporter.java
42 42 protected void importData(InputStream in, final File associatedFile) throws IllegalDataException { 43 43 final DataSet dataSet = OsmReader.parseDataSet(in, NullProgressMonitor.INSTANCE); 44 44 final OsmDataLayer layer = new OsmDataLayer(dataSet, associatedFile.getName(), associatedFile); 45 addDataLayer(dataSet, layer, associatedFile.getPath()); 46 } 47 48 protected void addDataLayer(final DataSet dataSet, final OsmDataLayer layer, final String filePath) { 45 49 // FIXME: remove UI stuff from IO subsystem 46 50 // 47 51 Runnable uiStuff = new Runnable() { … … 50 54 if (dataSet.allPrimitives().isEmpty()) { 51 55 JOptionPane.showMessageDialog( 52 56 Main.parent, 53 tr("No data found in file {0}.", associatedFile.getPath()),57 tr("No data found in file {0}.", filePath), 54 58 tr("Open OSM file"), 55 59 JOptionPane.INFORMATION_MESSAGE); 56 60 } -
src/org/openstreetmap/josm/io/OsmReader.java
8 8 import java.text.MessageFormat; 9 9 import java.util.ArrayList; 10 10 import java.util.Collection; 11 import java.util.HashMap;12 import java.util.LinkedList;13 import java.util.List;14 import java.util.Map;15 11 import java.util.regex.Matcher; 16 12 import java.util.regex.Pattern; 17 13 14 import javax.xml.stream.Location; 18 15 import javax.xml.stream.XMLInputFactory; 19 import javax.xml.stream.XMLStreamReader;20 16 import javax.xml.stream.XMLStreamConstants; 21 17 import javax.xml.stream.XMLStreamException; 22 import javax.xml.stream. Location;18 import javax.xml.stream.XMLStreamReader; 23 19 24 20 import org.openstreetmap.josm.data.Bounds; 25 21 import org.openstreetmap.josm.data.coor.LatLon; … … 28 24 import org.openstreetmap.josm.data.osm.DataSource; 29 25 import org.openstreetmap.josm.data.osm.Node; 30 26 import org.openstreetmap.josm.data.osm.NodeData; 31 import org.openstreetmap.josm.data.osm.OsmPrimitive;32 27 import org.openstreetmap.josm.data.osm.OsmPrimitiveType; 33 28 import org.openstreetmap.josm.data.osm.PrimitiveData; 34 import org.openstreetmap.josm.data.osm.PrimitiveId;35 29 import org.openstreetmap.josm.data.osm.Relation; 36 30 import org.openstreetmap.josm.data.osm.RelationData; 37 import org.openstreetmap.josm.data.osm.RelationMember;38 import org.openstreetmap.josm.data.osm.SimplePrimitiveId;39 31 import org.openstreetmap.josm.data.osm.Tagged; 40 32 import org.openstreetmap.josm.data.osm.User; 41 33 import org.openstreetmap.josm.data.osm.Way; … … 52 44 * The XMLStreamReader cursor points to the start of the element, when the method is 53 45 * entered, and it must point to the end of the same element, when it is exited. 54 46 */ 55 public class OsmReader { 56 57 /** 58 * Used as a temporary storage for relation members, before they 59 * are resolved into pointers to real objects. 60 */ 61 private static class RelationMemberData { 62 public OsmPrimitiveType type; 63 public long id; 64 public String role; 65 } 66 67 /** 68 * The dataset to add parsed objects to. 69 */ 70 private DataSet ds = new DataSet(); 47 public class OsmReader extends AbstractReader { 71 48 72 49 private XMLStreamReader parser; 73 50 74 /** the map from external ids to read OsmPrimitives. External ids are75 * longs too, but in contrast to internal ids negative values are used76 * to identify primitives unknown to the OSM server77 */78 private Map<PrimitiveId, OsmPrimitive> externalIdMap = new HashMap<PrimitiveId, OsmPrimitive>();79 80 /**81 * Data structure for the remaining way objects82 */83 private Map<Long, Collection<Long>> ways = new HashMap<Long, Collection<Long>>();84 85 /**86 * Data structure for relation objects87 */88 private Map<Long, Collection<RelationMemberData>> relations = new HashMap<Long, Collection<RelationMemberData>>();89 90 private Changeset uploadChangeset;91 92 /**93 * constructor (for private use only)94 *95 * @see #parseDataSet(InputStream, DataSet, ProgressMonitor)96 */97 private OsmReader() {98 externalIdMap = new HashMap<PrimitiveId, OsmPrimitive>();99 }100 101 51 public void setParser(XMLStreamReader parser) { 102 52 this.parser = parser; 103 53 } 104 54 105 /**106 * Replies the parsed data set107 *108 * @return the parsed data set109 */110 public DataSet getDataSet() {111 return ds;112 }113 114 55 protected void throwException(String msg) throws XMLStreamException { 115 56 throw new OsmParsingException(msg, parser.getLocation()); 116 57 } … … 136 77 parser.close(); 137 78 } 138 79 80 @SuppressWarnings("null") 139 81 private void parseOsm() throws XMLStreamException { 140 82 String v = parser.getAttributeValue(null, "version"); 141 83 if (v == null) { … … 351 293 } 352 294 } 353 295 296 @SuppressWarnings("null") 354 297 private void parseTag(Tagged t) throws XMLStreamException { 355 298 String key = parser.getAttributeValue(null, "k"); 356 299 String value = parser.getAttributeValue(null, "v"); … … 579 522 } 580 523 581 524 /** 582 * Processes the parsed nodes after parsing. Just adds them to583 * the dataset584 *585 */586 protected void processNodesAfterParsing() {587 for (OsmPrimitive primitive: externalIdMap.values()) {588 if (primitive instanceof Node) {589 this.ds.addPrimitive(primitive);590 }591 }592 }593 594 /**595 * Processes the ways after parsing. Rebuilds the list of nodes of each way and596 * adds the way to the dataset597 *598 * @throws IllegalDataException thrown if a data integrity problem is detected599 */600 protected void processWaysAfterParsing() throws IllegalDataException{601 for (Long externalWayId: ways.keySet()) {602 Way w = (Way)externalIdMap.get(new SimplePrimitiveId(externalWayId, OsmPrimitiveType.WAY));603 List<Node> wayNodes = new ArrayList<Node>();604 for (long id : ways.get(externalWayId)) {605 Node n = (Node)externalIdMap.get(new SimplePrimitiveId(id, OsmPrimitiveType.NODE));606 if (n == null) {607 if (id <= 0)608 throw new IllegalDataException (609 tr("Way with external ID ''{0}'' includes missing node with external ID ''{1}''.",610 externalWayId,611 id));612 // create an incomplete node if necessary613 //614 n = (Node)ds.getPrimitiveById(id,OsmPrimitiveType.NODE);615 if (n == null) {616 n = new Node(id);617 ds.addPrimitive(n);618 }619 }620 if (n.isDeleted()) {621 System.out.println(tr("Deleted node {0} is part of way {1}", id, w.getId()));622 } else {623 wayNodes.add(n);624 }625 }626 w.setNodes(wayNodes);627 if (w.hasIncompleteNodes()) {628 System.out.println(tr("Way {0} with {1} nodes has incomplete nodes because at least one node was missing in the loaded data.",629 externalWayId, w.getNodesCount()));630 }631 ds.addPrimitive(w);632 }633 }634 635 /**636 * Completes the parsed relations with its members.637 *638 * @throws IllegalDataException thrown if a data integrity problem is detected, i.e. if a639 * relation member refers to a local primitive which wasn't available in the data640 *641 */642 private void processRelationsAfterParsing() throws IllegalDataException {643 644 // First add all relations to make sure that when relation reference other relation, the referenced will be already in dataset645 for (Long externalRelationId : relations.keySet()) {646 Relation relation = (Relation) externalIdMap.get(647 new SimplePrimitiveId(externalRelationId, OsmPrimitiveType.RELATION)648 );649 ds.addPrimitive(relation);650 }651 652 for (Long externalRelationId : relations.keySet()) {653 Relation relation = (Relation) externalIdMap.get(654 new SimplePrimitiveId(externalRelationId, OsmPrimitiveType.RELATION)655 );656 List<RelationMember> relationMembers = new ArrayList<RelationMember>();657 for (RelationMemberData rm : relations.get(externalRelationId)) {658 OsmPrimitive primitive = null;659 660 // lookup the member from the map of already created primitives661 primitive = externalIdMap.get(new SimplePrimitiveId(rm.id, rm.type));662 663 if (primitive == null) {664 if (rm.id <= 0)665 // relation member refers to a primitive with a negative id which was not666 // found in the data. This is always a data integrity problem and we abort667 // with an exception668 //669 throw new IllegalDataException(670 tr("Relation with external id ''{0}'' refers to a missing primitive with external id ''{1}''.",671 externalRelationId,672 rm.id));673 674 // member refers to OSM primitive which was not present in the parsed data675 // -> create a new incomplete primitive and add it to the dataset676 //677 primitive = ds.getPrimitiveById(rm.id, rm.type);678 if (primitive == null) {679 switch (rm.type) {680 case NODE:681 primitive = new Node(rm.id); break;682 case WAY:683 primitive = new Way(rm.id); break;684 case RELATION:685 primitive = new Relation(rm.id); break;686 default: throw new AssertionError(); // can't happen687 }688 689 ds.addPrimitive(primitive);690 externalIdMap.put(new SimplePrimitiveId(rm.id, rm.type), primitive);691 }692 }693 if (primitive.isDeleted()) {694 System.out.println(tr("Deleted member {0} is used by relation {1}", primitive.getId(), relation.getId()));695 } else {696 relationMembers.add(new RelationMember(rm.role, primitive));697 }698 }699 relation.setMembers(relationMembers);700 }701 }702 703 private void processChangesetAfterParsing() {704 if (uploadChangeset != null) {705 for (Map.Entry<String, String> e : uploadChangeset.getKeys().entrySet()) {706 ds.addChangeSetTag(e.getKey(), e.getValue());707 }708 }709 }710 711 /**712 525 * Parse the given input source and return the dataset. 713 526 * 714 527 * @param source the source input stream. Must not be null. … … 735 548 progressMonitor.worked(1); 736 549 737 550 progressMonitor.indeterminateSubTask(tr("Preparing data set...")); 738 reader.ds.beginUpdate(); 739 try { 740 reader.processNodesAfterParsing(); 741 reader.processWaysAfterParsing(); 742 reader.processRelationsAfterParsing(); 743 reader.processChangesetAfterParsing(); 744 } finally { 745 reader.ds.endUpdate(); 746 } 551 reader.prepareDataSet(); 747 552 progressMonitor.worked(1); 748 553 return reader.getDataSet(); 749 554 } catch(IllegalDataException e) { -
src/org/openstreetmap/josm/io/OsmServerChangesetReader.java
120 120 * @throws OsmTransferException thrown if something goes wrong 121 121 * @throws IllegalArgumentException if id <= 0 122 122 */ 123 public List<Changeset> readChangesets(Collection< Integer> ids, ProgressMonitor monitor) throws OsmTransferException {123 public List<Changeset> readChangesets(Collection<Long> ids, ProgressMonitor monitor) throws OsmTransferException { 124 124 if (ids == null) 125 125 return Collections.emptyList(); 126 126 if (monitor == null) { … … 131 131 monitor.setTicksCount(ids.size()); 132 132 List<Changeset> ret = new ArrayList<Changeset>(); 133 133 int i=0; 134 for (Iterator< Integer> it = ids.iterator(); it.hasNext(); ) {135 intid = it.next();134 for (Iterator<Long> it = ids.iterator(); it.hasNext(); ) { 135 long id = it.next(); 136 136 if (id <= 0) { 137 137 continue; 138 138 } … … 169 169 * @throws IllegalArgumentException thrown if id <= 0 170 170 * @throws OsmTransferException thrown if something went wrong 171 171 */ 172 public ChangesetDataSet downloadChangeset( intid, ProgressMonitor monitor) throws IllegalArgumentException, OsmTransferException {172 public ChangesetDataSet downloadChangeset(long id, ProgressMonitor monitor) throws IllegalArgumentException, OsmTransferException { 173 173 if (id <= 0) 174 174 throw new IllegalArgumentException(MessageFormat.format("Expected value of type integer > 0 for parameter ''{0}'', got {1}", "id", id)); 175 175 if (monitor == null) { -
src/org/openstreetmap/josm/io/PbfImporter.java
1 // License: GPL. For details, see LICENSE file. 2 package org.openstreetmap.josm.io; 3 4 import static org.openstreetmap.josm.tools.I18n.tr; 5 6 import java.io.File; 7 import java.io.InputStream; 8 9 import org.openstreetmap.josm.actions.ExtensionFileFilter; 10 import org.openstreetmap.josm.data.osm.DataSet; 11 import org.openstreetmap.josm.gui.layer.OsmDataLayer; 12 import org.openstreetmap.josm.gui.progress.NullProgressMonitor; 13 14 /** 15 * @author Vincent 16 * 17 */ 18 public class PbfImporter extends OsmImporter { 19 20 public PbfImporter() { 21 super(new ExtensionFileFilter("osm.pbf", "osm.pbf", tr("OSM Server Files PBF compressed") + " (*.osm.pbf)")); 22 } 23 24 /* (non-Javadoc) 25 * @see org.openstreetmap.josm.io.OsmImporter#importData(java.io.InputStream, java.io.File) 26 */ 27 @Override 28 protected void importData(InputStream in, File associatedFile) throws IllegalDataException { 29 final DataSet dataSet = PbfReader.parseDataSet(in, NullProgressMonitor.INSTANCE); 30 final OsmDataLayer layer = new OsmDataLayer(dataSet, associatedFile.getName(), associatedFile); 31 addDataLayer(dataSet, layer, associatedFile.getPath()); 32 } 33 } -
src/org/openstreetmap/josm/io/PbfReader.java
1 // License: GPL. For details, see LICENSE file. 2 package org.openstreetmap.josm.io; 3 4 import static org.openstreetmap.josm.tools.I18n.tr; 5 6 import java.io.IOException; 7 import java.io.InputStream; 8 import java.util.ArrayList; 9 import java.util.Collection; 10 import java.util.Date; 11 import java.util.HashMap; 12 import java.util.List; 13 import java.util.Map; 14 15 import org.openstreetmap.josm.data.coor.LatLon; 16 import org.openstreetmap.josm.data.osm.DataSet; 17 import org.openstreetmap.josm.data.osm.Node; 18 import org.openstreetmap.josm.data.osm.OsmPrimitiveType; 19 import org.openstreetmap.josm.data.osm.Relation; 20 import org.openstreetmap.josm.data.osm.User; 21 import org.openstreetmap.josm.data.osm.Way; 22 import org.openstreetmap.josm.gui.progress.NullProgressMonitor; 23 import org.openstreetmap.josm.gui.progress.ProgressMonitor; 24 import org.openstreetmap.josm.tools.CheckParameterUtil; 25 26 import crosby.binary.BinaryParser; 27 import crosby.binary.Osmformat; 28 import crosby.binary.Osmformat.DenseNodes; 29 import crosby.binary.Osmformat.HeaderBlock; 30 import crosby.binary.file.BlockInputStream; 31 32 /** 33 * @author Vincent 34 * 35 */ 36 public class PbfReader extends AbstractReader { 37 38 protected class PbfParser extends BinaryParser { 39 40 @Override 41 protected void parse(HeaderBlock header) { 42 } 43 44 @Override 45 protected void parseDense(DenseNodes nodes) { 46 int keyindex = 0; 47 // Almost all data is DELTA coded 48 long previousId = 0; 49 long previousLat = 0; 50 long previousLon = 0; 51 long previousChangesetId = 0; 52 int previousUid = 0; 53 int previousSuid = 0; 54 long previousTimestamp = 0; 55 for (int i = 0; i < nodes.getIdCount(); i++) { 56 // Id (delta) and version (normal) 57 Node node = new Node(previousId+=nodes.getId(i), nodes.getDenseinfo().getVersion(i)); 58 // Lat/Lon (delta) 59 node.setCoor(new LatLon(parseLat(previousLat+=nodes.getLat(i)), parseLon(previousLon+=nodes.getLon(i)))); 60 // Changeset (delta) 61 node.setChangesetId(previousChangesetId+=nodes.getDenseinfo().getChangeset(i)); 62 // User (delta) 63 node.setUser(User.createOsmUser(previousUid+=nodes.getDenseinfo().getUid(i), getStringById(previousSuid+=nodes.getDenseinfo().getUserSid(i)))); 64 // Timestamp (delta) 65 node.setTimestamp(new Date(previousTimestamp+=nodes.getDenseinfo().getTimestamp(i))); 66 // A single table contains all keys/values of all nodes. 67 // Each node's tags are encoded in alternating <key_id> <value_id>. 68 // A single stringid of 0 delimit when the tags of a node ends and the tags of the next node begin. 69 Map<String, String> keys = new HashMap<String, String>(); 70 while (keyindex < nodes.getKeysValsCount()) { 71 int key_id = nodes.getKeysVals(keyindex++); 72 if (key_id == 0) { 73 break; // End of current node's tags 74 } else { 75 int value_id = nodes.getKeysVals(keyindex++); 76 keys.put(getStringById(key_id), getStringById(value_id)); 77 } 78 } 79 node.setKeys(keys); 80 externalIdMap.put(node.getPrimitiveId(), node); 81 } 82 } 83 84 @Override 85 protected void parseNodes(List<Osmformat.Node> osmNodes) { 86 for (Osmformat.Node n : osmNodes) { 87 Node node = new Node(n.getId(), n.getInfo().getVersion()); 88 node.setCoor(new LatLon(parseLat(n.getLat()), parseLon(n.getLon()))); 89 node.setChangesetId(n.getInfo().getChangeset()); 90 node.setUser(User.createOsmUser(n.getInfo().getUid(), getStringById(n.getInfo().getUserSid()))); 91 node.setTimestamp(new Date(n.getInfo().getTimestamp())); 92 Map<String, String> keys = new HashMap<String, String>(); 93 for (int i=0; i<n.getKeysCount(); i++) { 94 keys.put(getStringById(n.getKeys(i)), getStringById(n.getVals(i))); 95 } 96 node.setKeys(keys); 97 externalIdMap.put(node.getPrimitiveId(), node); 98 } 99 } 100 101 @Override 102 protected void parseWays(List<Osmformat.Way> osmWays) { 103 for (Osmformat.Way w : osmWays) { 104 Way way = new Way(w.getId(), w.getInfo().getVersion()); 105 way.setChangesetId(w.getInfo().getChangeset()); 106 way.setUser(User.createOsmUser(w.getInfo().getUid(), getStringById(w.getInfo().getUserSid()))); 107 way.setTimestamp(new Date(w.getInfo().getTimestamp())); 108 Map<String, String> keys = new HashMap<String, String>(); 109 for (int i=0; i<w.getKeysCount(); i++) { 110 keys.put(getStringById(w.getKeys(i)), getStringById(w.getVals(i))); 111 } 112 way.setKeys(keys); 113 long previousId = 0; // Node ids are delta coded 114 Collection<Long> nodeIds = new ArrayList<Long>(); 115 for (Long id : w.getRefsList()) { 116 nodeIds.add(previousId+=id); 117 } 118 ways.put(way.getUniqueId(), nodeIds); 119 externalIdMap.put(way.getPrimitiveId(), way); 120 } 121 } 122 123 @Override 124 protected void parseRelations(List<Osmformat.Relation> osmRels) { 125 for (Osmformat.Relation r : osmRels) { 126 Relation rel = new Relation(r.getId(), r.getInfo().getVersion()); 127 rel.setChangesetId(r.getInfo().getChangeset()); 128 rel.setUser(User.createOsmUser(r.getInfo().getUid(), getStringById(r.getInfo().getUserSid()))); 129 rel.setTimestamp(new Date(r.getInfo().getTimestamp())); 130 Map<String, String> keys = new HashMap<String, String>(); 131 for (int i=0; i<r.getKeysCount(); i++) { 132 keys.put(getStringById(r.getKeys(i)), getStringById(r.getVals(i))); 133 } 134 rel.setKeys(keys); 135 long previousId = 0; // Member ids are delta coded 136 Collection<RelationMemberData> members = new ArrayList<RelationMemberData>(); 137 for (int i = 0; i<r.getMemidsCount(); i++) { 138 RelationMemberData rmd = new RelationMemberData(); 139 rmd.id = previousId+=r.getMemids(i); 140 rmd.role = getStringById(r.getRolesSid(i)); 141 switch (r.getTypes(i)) { 142 case NODE: 143 rmd.type = OsmPrimitiveType.NODE; 144 break; 145 case WAY: 146 rmd.type = OsmPrimitiveType.WAY; 147 break; 148 case RELATION: 149 rmd.type = OsmPrimitiveType.RELATION; 150 break; 151 } 152 members.add(rmd); 153 } 154 relations.put(rel.getUniqueId(), members); 155 externalIdMap.put(rel.getPrimitiveId(), rel); 156 } 157 } 158 159 @Override 160 public void complete() { 161 } 162 } 163 164 private PbfParser parser = new PbfParser(); 165 166 /** 167 * Parse the given input source and return the dataset. 168 * 169 * @param source the source input stream. Must not be null. 170 * @param progressMonitor the progress monitor. If null, {@see NullProgressMonitor#INSTANCE} is assumed 171 * 172 * @return the dataset with the parsed data 173 * @throws IllegalDataException thrown if the an error was found while parsing the data from the source 174 * @throws IllegalArgumentException thrown if source is null 175 */ 176 public static DataSet parseDataSet(InputStream source, ProgressMonitor progressMonitor) throws IllegalDataException { 177 if (progressMonitor == null) { 178 progressMonitor = NullProgressMonitor.INSTANCE; 179 } 180 CheckParameterUtil.ensureParameterNotNull(source, "source"); 181 182 PbfReader reader = new PbfReader(); 183 184 try { 185 progressMonitor.beginTask(tr("Prepare OSM data...", 2)); 186 progressMonitor.indeterminateSubTask(tr("Reading OSM data...")); 187 188 reader.parse(source); 189 progressMonitor.worked(1); 190 191 progressMonitor.indeterminateSubTask(tr("Preparing data set...")); 192 reader.prepareDataSet(); 193 progressMonitor.worked(1); 194 return reader.getDataSet(); 195 } catch (IllegalDataException e) { 196 throw e; 197 } catch (Exception e) { 198 throw new IllegalDataException(e); 199 } finally { 200 progressMonitor.finishTask(); 201 } 202 } 203 204 public void parse(InputStream source) throws IOException { 205 new BlockInputStream(source, parser).process(); 206 } 207 }