Changeset 34826 in osm for applications/editors/josm/plugins
- Timestamp:
- 2019-01-16T09:13:03+01:00 (6 years ago)
- Location:
- applications/editors/josm/plugins/pbf
- Files:
-
- 2 added
- 3 edited
Legend:
- Unmodified
- Added
- Removed
-
applications/editors/josm/plugins/pbf/.project
r32859 r34826 4 4 <comment></comment> 5 5 <projects> 6 <project>josm</project> 6 7 </projects> 7 8 <buildSpec> -
applications/editors/josm/plugins/pbf/src/org/openstreetmap/josm/plugins/pbf/io/PbfReader.java
r34098 r34826 17 17 import org.openstreetmap.josm.data.coor.LatLon; 18 18 import org.openstreetmap.josm.data.osm.DataSet; 19 import org.openstreetmap.josm.data.osm.NodeData; 20 import org.openstreetmap.josm.data.osm.OsmPrimitiveType; 21 import org.openstreetmap.josm.data.osm.PrimitiveData; 22 import org.openstreetmap.josm.data.osm.RelationData; 23 import org.openstreetmap.josm.data.osm.RelationMemberData; 19 24 import org.openstreetmap.josm.data.osm.UploadPolicy; 20 import org.openstreetmap.josm.data.osm.Node;21 import org.openstreetmap.josm.data.osm.OsmPrimitive;22 import org.openstreetmap.josm.data.osm.OsmPrimitiveType;23 import org.openstreetmap.josm.data.osm.Relation;24 import org.openstreetmap.josm.data.osm.RelationMemberData;25 25 import org.openstreetmap.josm.data.osm.User; 26 import org.openstreetmap.josm.data.osm.Way ;26 import org.openstreetmap.josm.data.osm.WayData; 27 27 import org.openstreetmap.josm.gui.progress.NullProgressMonitor; 28 28 import org.openstreetmap.josm.gui.progress.ProgressMonitor; … … 92 92 } 93 93 94 private void setMetadata( OsmPrimitiveosm, Info info) throws IllegalDataException {94 private void setMetadata(PrimitiveData osm, Info info) throws IllegalDataException { 95 95 if (info.hasChangeset()) { 96 96 checkChangesetId(info.getChangeset()); … … 146 146 for (int i = 0; i < nodes.getIdCount(); i++) { 147 147 // Id (delta) and version (normal) 148 Node node = new Node(nodeId += nodes.getId(i), nodes.hasDenseinfo() ? nodes.getDenseinfo().getVersion(i) : 1); 148 NodeData nd = new NodeData(nodeId += nodes.getId(i)); 149 nd.setVersion(nodes.hasDenseinfo() ? nodes.getDenseinfo().getVersion(i) : 1); 149 150 // Lat/Lon (delta) 150 n ode.setCoor(new LatLon(parseLat(nodeLat += nodes.getLat(i)),151 nd.setCoor(new LatLon(parseLat(nodeLat += nodes.getLat(i)), 151 152 parseLon(nodeLon += nodes.getLon(i))).getRoundedToOsmPrecision()); 152 checkCoordinates(n ode.getCoor());153 checkCoordinates(nd.getCoor()); 153 154 if (nodes.hasDenseinfo()) { 154 155 DenseInfo info = nodes.getDenseinfo(); … … 156 157 if (info.getChangesetCount() > i) { 157 158 checkChangesetId(changesetId += info.getChangeset(i)); 158 n ode.setChangesetId((int) changesetId);159 nd.setChangesetId((int) changesetId); 159 160 } 160 161 // User (delta) 161 162 if (info.getUidCount() > i && info.getUserSidCount() > i) { 162 n ode.setUser(User.createOsmUser(uid += info.getUid(i),163 nd.setUser(User.createOsmUser(uid += info.getUid(i), 163 164 getStringById(suid += info.getUserSid(i)))); 164 165 } … … 166 167 if (info.getTimestampCount() > i) { 167 168 checkTimestamp(timestamp += info.getTimestamp(i)); 168 n ode.setTimestamp(new Date(date_granularity * timestamp));169 nd.setTimestamp(new Date(date_granularity * timestamp)); 169 170 } 170 171 } … … 183 184 } 184 185 } 185 n ode.setKeys(keys);186 externalIdMap.put(node.getPrimitiveId(), node);186 nd.setKeys(keys); 187 buildPrimitive(nd); 187 188 } 188 189 } catch (IllegalDataException e) { … … 200 201 if (!info.hasVersion()) 201 202 discourageUpload = true; 202 final Node node = new Node(n.getId(), info.hasVersion() ? info.getVersion() : 1); 203 node.setCoor(new LatLon(parseLat(n.getLat()), parseLon(n.getLon())).getRoundedToOsmPrecision()); 204 checkCoordinates(node.getCoor()); 205 setMetadata(node, info); 203 NodeData nd = new NodeData(n.getId()); 204 nd.setVersion(info.hasVersion() ? info.getVersion() : 1); 205 nd.setCoor(new LatLon(parseLat(n.getLat()), parseLon(n.getLon())).getRoundedToOsmPrecision()); 206 checkCoordinates(nd.getCoor()); 207 setMetadata(nd, info); 206 208 Map<String, String> keys = new HashMap<>(); 207 209 for (int i = 0; i < n.getKeysCount(); i++) { 208 210 keys.put(getStringById(n.getKeys(i)), getStringById(n.getVals(i))); 209 211 } 210 n ode.setKeys(keys);211 externalIdMap.put(node.getPrimitiveId(), node);212 nd.setKeys(keys); 213 buildPrimitive(nd); 212 214 } 213 215 } catch (IllegalDataException e) { … … 225 227 if (!info.hasVersion()) 226 228 discourageUpload = true; 227 final Way way = new Way(w.getId(), info.hasVersion() ? info.getVersion() : 1); 228 setMetadata(way, info); 229 final WayData wd = new WayData(w.getId()); 230 wd.setVersion(info.hasVersion() ? info.getVersion() : 1); 231 setMetadata(wd, info); 229 232 Map<String, String> keys = new HashMap<>(); 230 233 for (int i = 0; i < w.getKeysCount(); i++) { 231 234 keys.put(getStringById(w.getKeys(i)), getStringById(w.getVals(i))); 232 235 } 233 w ay.setKeys(keys);236 wd.setKeys(keys); 234 237 long previousId = 0; // Node ids are delta coded 235 238 Collection<Long> nodeIds = new ArrayList<>(); … … 237 240 nodeIds.add(previousId += id); 238 241 } 239 ways.put(w ay.getUniqueId(), nodeIds);240 externalIdMap.put(way.getPrimitiveId(), way);242 ways.put(wd.getUniqueId(), nodeIds); 243 buildPrimitive(wd); 241 244 } 242 245 } catch (IllegalDataException e) { … … 254 257 if (!info.hasVersion()) 255 258 discourageUpload = true; 256 final Relation rel = new Relation(r.getId(), info.hasVersion() ? info.getVersion() : 1); 257 setMetadata(rel, info); 259 final RelationData rd = new RelationData(r.getId()); 260 rd.setVersion(info.hasVersion() ? info.getVersion() : 1); 261 setMetadata(rd, info); 258 262 Map<String, String> keys = new HashMap<>(); 259 263 for (int i = 0; i < r.getKeysCount(); i++) { 260 264 keys.put(getStringById(r.getKeys(i)), getStringById(r.getVals(i))); 261 265 } 262 r el.setKeys(keys);266 rd.setKeys(keys); 263 267 long previousId = 0; // Member ids are delta coded 264 268 Collection<RelationMemberData> members = new ArrayList<>(); … … 269 273 previousId += r.getMemids(i))); 270 274 } 271 relations.put(r el.getUniqueId(), members);272 externalIdMap.put(rel.getPrimitiveId(), rel);275 relations.put(rd.getUniqueId(), members); 276 buildPrimitive(rd); 273 277 } 274 278 } catch (IllegalDataException e) { -
applications/editors/josm/plugins/pbf/test/unit/org/openstreetmap/josm/plugins/pbf/io/PbfImporterTest.java
r32861 r34826 80 80 assertEquals(97, ds.getRelations().size()); 81 81 } 82 83 /** 84 * Non-regression test for <a href="https://josm.openstreetmap.de/ticket/14545">Ticket #14545</a>. 85 * @throws Exception if an error occurs 86 */ 87 @Test 88 public void testTicket14545() throws Exception { 89 DataSet ds = new PbfImporter().parseDataSet(TestUtils.getRegressionDataFile(14545, "reg14545.osm.pbf")); 90 assertNotNull(ds); 91 assertEquals(12, ds.getNodes().size()); 92 assertEquals(2, ds.getWays().size()); 93 assertEquals(1, ds.getRelations().size()); 94 } 95 96 82 97 }
Note:
See TracChangeset
for help on using the changeset viewer.