Ticket #10132: improve_pbf_plugin.patch
File improve_pbf_plugin.patch, 10.3 KB (added by , 9 years ago) |
---|
-
plugins/pbf/src/org/openstreetmap/josm/plugins/pbf/io/PbfImporter.java
11 11 import org.openstreetmap.josm.io.CachedFile; 12 12 import org.openstreetmap.josm.io.OsmImporter; 13 13 import org.openstreetmap.josm.plugins.pbf.PbfConstants; 14 import org.xml.sax.SAXException;15 14 16 15 /** 17 16 * @author Don-vip … … 28 27 return PbfReader.parseDataSet(in, progressMonitor); 29 28 } 30 29 31 protected DataSet parseDataSet(final String source) throws IOException, SAXException, IllegalDataException { 32 return parseDataSet(new CachedFile(source).getInputStream(), NullProgressMonitor.INSTANCE); 30 protected DataSet parseDataSet(final String source) throws IOException, IllegalDataException { 31 try(CachedFile cf = new CachedFile(source)) { 32 return parseDataSet(cf.getInputStream(), NullProgressMonitor.INSTANCE); 33 } 33 34 } 34 35 } -
plugins/pbf/src/org/openstreetmap/josm/plugins/pbf/io/PbfReader.java
31 31 32 32 import crosby.binary.BinaryParser; 33 33 import crosby.binary.Osmformat; 34 import crosby.binary.Osmformat.DenseInfo; 34 35 import crosby.binary.Osmformat.DenseNodes; 35 36 import crosby.binary.Osmformat.HeaderBBox; 36 37 import crosby.binary.Osmformat.HeaderBlock; … … 47 48 protected class PbfParser extends BinaryParser { 48 49 49 50 public IllegalDataException exception = null; 50 51 private boolean discourageUpload; 51 52 private double parseRawDegrees(long raw) { 52 53 return raw * .000000001; 53 54 } … … 108 109 109 110 @Override 110 111 protected void parseDense(DenseNodes nodes) { 112 if (nodes.hasDenseinfo() == false) 113 discourageUpload = true; 111 114 if (exception == null) { 112 115 try { 113 116 int keyIndex = 0; … … 121 124 long timestamp = 0; 122 125 for (int i = 0; i < nodes.getIdCount(); i++) { 123 126 // Id (delta) and version (normal) 124 Node node = new Node(nodeId+=nodes.getId(i), nodes. getDenseinfo().getVersion(i));127 Node node = new Node(nodeId+=nodes.getId(i), nodes.hasDenseinfo() ? nodes.getDenseinfo().getVersion(i): 1); 125 128 // Lat/Lon (delta) 126 129 node.setCoor(new LatLon(parseLat(nodeLat+=nodes.getLat(i)), parseLon(nodeLon+=nodes.getLon(i))).getRoundedToOsmPrecision()); 127 130 checkCoordinates(node.getCoor()); 128 // Changeset (delta) 129 checkChangesetId(changesetId+=nodes.getDenseinfo().getChangeset(i)); 130 node.setChangesetId((int) changesetId); 131 // User (delta) 132 node.setUser(User.createOsmUser(uid+=nodes.getDenseinfo().getUid(i), getStringById(suid+=nodes.getDenseinfo().getUserSid(i)))); 133 // Timestamp (delta) 134 checkTimestamp(timestamp+=nodes.getDenseinfo().getTimestamp(i)); 135 node.setTimestamp(new Date(date_granularity * timestamp)); 131 if (nodes.hasDenseinfo()) { 132 // Changeset (delta) 133 if (nodes.getDenseinfo().getChangesetCount() > i) { 134 checkChangesetId(changesetId+=nodes.getDenseinfo().getChangeset(i)); 135 node.setChangesetId((int) changesetId); 136 } 137 // User (delta) 138 if (nodes.getDenseinfo().getUidCount() > i && nodes.getDenseinfo().getUserSidCount() > i) { 139 node.setUser(User.createOsmUser(uid+=nodes.getDenseinfo().getUid(i), getStringById(suid+=nodes.getDenseinfo().getUserSid(i)))); 140 } 141 // Timestamp (delta) 142 if (nodes.getDenseinfo().getTimestampCount() > i) { 143 checkTimestamp(timestamp+=nodes.getDenseinfo().getTimestamp(i)); 144 node.setTimestamp(new Date(date_granularity * timestamp)); 145 } 146 } 136 147 // A single table contains all keys/values of all nodes. 137 148 // Each node's tags are encoded in alternating <key_id> <value_id>. 138 149 // A single stringid of 0 delimit when the tags of a node ends and the tags of the next node begin. … … 163 174 try { 164 175 for (Osmformat.Node n : osmNodes) { 165 176 final Info info = n.getInfo(); 166 final Node node = new Node(n.getId(), info.getVersion()); 177 if (info.hasVersion() == false) 178 discourageUpload = true; 179 final Node node = new Node(n.getId(), info.hasVersion() ? info.getVersion() : 1); 167 180 node.setCoor(new LatLon(parseLat(n.getLat()), parseLon(n.getLon())).getRoundedToOsmPrecision()); 168 181 checkCoordinates(node.getCoor()); 169 checkChangesetId(info.getChangeset()); 170 node.setChangesetId((int) info.getChangeset()); 171 node.setUser(User.createOsmUser(info.getUid(), getStringById(info.getUserSid()))); 172 checkTimestamp(info.getTimestamp()); 173 node.setTimestamp(getDate(info)); 182 if (info.hasChangeset()) { 183 checkChangesetId(info.getChangeset()); 184 node.setChangesetId((int) info.getChangeset()); 185 } 186 if (info.hasUid() && info.hasUserSid()) 187 node.setUser(User.createOsmUser(info.getUid(), getStringById(info.getUserSid()))); 188 if (info.hasTimestamp()) { 189 checkTimestamp(info.getTimestamp()); 190 node.setTimestamp(getDate(info)); 191 } 174 192 Map<String, String> keys = new HashMap<>(); 175 193 for (int i=0; i<n.getKeysCount(); i++) { 176 194 keys.put(getStringById(n.getKeys(i)), getStringById(n.getVals(i))); … … 190 208 try { 191 209 for (Osmformat.Way w : osmWays) { 192 210 final Info info = w.getInfo(); 193 final Way way = new Way(w.getId(), info.getVersion()); 194 checkChangesetId(info.getChangeset()); 195 way.setChangesetId((int) info.getChangeset()); 196 way.setUser(User.createOsmUser(info.getUid(), getStringById(info.getUserSid()))); 197 checkTimestamp(info.getTimestamp()); 198 way.setTimestamp(getDate(info)); 211 if (info.hasVersion() == false) 212 discourageUpload = true; 213 final Way way = new Way(w.getId(), info.hasVersion() ? info.getVersion() : 1); 214 if (info.hasChangeset()) { 215 checkChangesetId(info.getChangeset()); 216 way.setChangesetId((int) info.getChangeset()); 217 } 218 if (info.hasUid() && info.hasUserSid()) { 219 way.setUser(User.createOsmUser(info.getUid(), getStringById(info.getUserSid()))); 220 } 221 if (info.hasTimestamp()) { 222 checkTimestamp(info.getTimestamp()); 223 way.setTimestamp(getDate(info)); 224 } 199 225 Map<String, String> keys = new HashMap<>(); 200 226 for (int i=0; i<w.getKeysCount(); i++) { 201 227 keys.put(getStringById(w.getKeys(i)), getStringById(w.getVals(i))); … … 221 247 try { 222 248 for (Osmformat.Relation r : osmRels) { 223 249 final Info info = r.getInfo(); 224 final Relation rel = new Relation(r.getId(), info.getVersion()); 225 checkChangesetId(info.getChangeset()); 226 rel.setChangesetId((int) info.getChangeset()); 227 rel.setUser(User.createOsmUser(info.getUid(), getStringById(info.getUserSid()))); 228 checkTimestamp(info.getTimestamp()); 229 rel.setTimestamp(getDate(info)); 250 if (info.hasVersion() == false) 251 discourageUpload = true; 252 final Relation rel = new Relation(r.getId(), info.hasVersion() ? info.getVersion() : 1); 253 if (info.hasChangeset()) { 254 checkChangesetId(info.getChangeset()); 255 rel.setChangesetId((int) info.getChangeset()); 256 } 257 if (info.hasUid() && info.hasUserSid()) { 258 rel.setUser(User.createOsmUser(info.getUid(), getStringById(info.getUserSid()))); 259 } 260 if (info.hasTimestamp()) { 261 checkTimestamp(info.getTimestamp()); 262 rel.setTimestamp(getDate(info)); 263 } 230 264 Map<String, String> keys = new HashMap<>(); 231 265 for (int i=0; i<r.getKeysCount(); i++) { 232 266 keys.put(getStringById(r.getKeys(i)), getStringById(r.getVals(i))); … … 258 292 exception = e; 259 293 } 260 294 } 295 if (discourageUpload) 296 ds.setUploadDiscouraged(true); 261 297 } 262 298 263 299 @Override 264 300 public void complete() { 301 if (discourageUpload) 302 ds.setUploadDiscouraged(true); 265 303 } 266 304 } 267 305