Changeset 32859 in osm for applications
- Timestamp:
- 2016-08-21T15:04:46+02:00 (8 years ago)
- Location:
- applications/editors/josm/plugins/pbf
- Files:
-
- 16 added
- 9 edited
Legend:
- Unmodified
- Added
- Removed
-
applications/editors/josm/plugins/pbf/.classpath
r32680 r32859 3 3 <classpathentry kind="src" path="gen"/> 4 4 <classpathentry excluding="crosby/binary/test/" kind="src" path="src"/> 5 <classpathentry kind="src" path="test/unit"/> 5 6 <classpathentry kind="con" path="org.eclipse.jdt.launching.JRE_CONTAINER/org.eclipse.jdt.internal.debug.ui.launcher.StandardVMType/JavaSE-1.8"/> 6 7 <classpathentry combineaccessrules="false" kind="src" path="/JOSM"/> 8 <classpathentry kind="con" path="org.eclipse.jdt.junit.JUNIT_CONTAINER/4"/> 7 9 <classpathentry kind="output" path="build"/> 8 10 </classpath> -
applications/editors/josm/plugins/pbf/.project
r32286 r32859 16 16 </arguments> 17 17 </buildCommand> 18 <buildCommand> 19 <name>net.sf.eclipsecs.core.CheckstyleBuilder</name> 20 <arguments> 21 </arguments> 22 </buildCommand> 18 23 </buildSpec> 19 24 <natures> 20 25 <nature>org.sonar.ide.eclipse.core.sonarNature</nature> 21 26 <nature>org.eclipse.jdt.core.javanature</nature> 27 <nature>net.sf.eclipsecs.core.CheckstyleNature</nature> 22 28 </natures> 23 29 </projectDescription> -
applications/editors/josm/plugins/pbf/src/org/openstreetmap/josm/plugins/pbf/PbfConstants.java
r30341 r32859 7 7 8 8 /** 9 * 9 * PBF constants. 10 10 * @author Don-vip 11 *12 11 */ 13 12 public interface PbfConstants { 14 13 15 14 /** 16 15 * File extension. 17 16 */ 18 public static finalString EXTENSION = "osm.pbf";19 17 String EXTENSION = "osm.pbf"; 18 20 19 /** 21 20 * File filter used in import/export dialogs. 22 21 */ 23 public static final ExtensionFileFilter FILE_FILTER = new ExtensionFileFilter(EXTENSION, EXTENSION, tr("OSM Server Files pbf compressed") + " (*."+EXTENSION+")"); 22 ExtensionFileFilter FILE_FILTER = new ExtensionFileFilter(EXTENSION, EXTENSION, 23 tr("OSM Server Files pbf compressed") + " (*."+EXTENSION+")"); 24 24 } -
applications/editors/josm/plugins/pbf/src/org/openstreetmap/josm/plugins/pbf/action/DownloadPbfTask.java
r30341 r32859 13 13 import org.openstreetmap.josm.plugins.pbf.io.PbfServerReader; 14 14 15 /** 16 * Task allowing to download remote PBF files. 17 */ 15 18 public class DownloadPbfTask extends DownloadOsmTask implements PbfConstants { 16 19 17 @Override 18 public Future<?> download(boolean newLayer, Bounds downloadArea, 19 ProgressMonitor progressMonitor) { 20 return null; 21 } 20 @Override 21 public Future<?> download(boolean newLayer, Bounds downloadArea, ProgressMonitor progressMonitor) { 22 return null; 23 } 22 24 23 @Override 24 public Future<?> loadUrl(boolean newLayer, String url, 25 ProgressMonitor progressMonitor) { 26 downloadTask = new DownloadTask(newLayer, 27 new PbfServerReader(url), progressMonitor); 25 @Override 26 public Future<?> loadUrl(boolean newLayer, String url, ProgressMonitor progressMonitor) { 27 downloadTask = new DownloadTask(newLayer, new PbfServerReader(url), progressMonitor); 28 28 // We need submit instead of execute so we can wait for it to finish and get the error 29 29 // message if necessary. If no one calls getErrorMessage() it just behaves like execute. 30 30 return Main.worker.submit(downloadTask); 31 31 } 32 32 33 33 @Override -
applications/editors/josm/plugins/pbf/src/org/openstreetmap/josm/plugins/pbf/io/PbfExporter.java
r30659 r32859 3 3 4 4 import java.io.File; 5 import java.io.FileNotFoundException;6 5 import java.io.FileOutputStream; 7 6 import java.io.IOException; … … 13 12 14 13 /** 14 * Exports data to a .pbf file. 15 15 * @author Don-vip 16 *17 16 */ 18 17 public class PbfExporter extends OsmExporter { 19 18 19 /** 20 * Constructs a new {@code PbfExporter}. 21 */ 20 22 public PbfExporter() { 21 23 super(PbfConstants.FILE_FILTER); … … 23 25 24 26 @Override 25 protected void doSave(File file, OsmDataLayer layer) throws IOException , FileNotFoundException{27 protected void doSave(File file, OsmDataLayer layer) throws IOException { 26 28 try ( 27 29 OutputStream out = new FileOutputStream(file); -
applications/editors/josm/plugins/pbf/src/org/openstreetmap/josm/plugins/pbf/io/PbfImporter.java
r30495 r32859 8 8 import org.openstreetmap.josm.gui.progress.NullProgressMonitor; 9 9 import org.openstreetmap.josm.gui.progress.ProgressMonitor; 10 import org.openstreetmap.josm.io.CachedFile; 10 11 import org.openstreetmap.josm.io.IllegalDataException; 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 /** 16 * Imports data from a .pbf file. 17 17 * @author Don-vip 18 *19 18 */ 20 19 public class PbfImporter extends OsmImporter { 21 20 21 /** 22 * Constructs a new {@code PbfImporter}. 23 */ 22 24 public PbfImporter() { 23 25 super(PbfConstants.FILE_FILTER); 24 26 } 25 27 26 27 28 29 28 @Override 29 protected DataSet parseDataSet(InputStream in, ProgressMonitor progressMonitor) throws IllegalDataException { 30 return PbfReader.parseDataSet(in, progressMonitor); 31 } 30 32 31 protected DataSet parseDataSet(final String source) throws IOException, SAXException, IllegalDataException { 32 return parseDataSet(new CachedFile(source).getInputStream(), NullProgressMonitor.INSTANCE); 33 } 33 protected DataSet parseDataSet(final String source) throws IOException, IllegalDataException { 34 try (CachedFile cf = new CachedFile(source)) { 35 return parseDataSet(cf.getInputStream(), NullProgressMonitor.INSTANCE); 36 } 37 } 34 38 } -
applications/editors/josm/plugins/pbf/src/org/openstreetmap/josm/plugins/pbf/io/PbfReader.java
r32128 r32859 19 19 import org.openstreetmap.josm.data.osm.DataSet; 20 20 import org.openstreetmap.josm.data.osm.Node; 21 import org.openstreetmap.josm.data.osm.OsmPrimitive; 21 22 import org.openstreetmap.josm.data.osm.OsmPrimitiveType; 22 23 import org.openstreetmap.josm.data.osm.Relation; … … 32 33 import crosby.binary.BinaryParser; 33 34 import crosby.binary.Osmformat; 35 import crosby.binary.Osmformat.DenseInfo; 34 36 import crosby.binary.Osmformat.DenseNodes; 35 37 import crosby.binary.Osmformat.HeaderBBox; 36 38 import crosby.binary.Osmformat.HeaderBlock; 37 39 import crosby.binary.Osmformat.Info; 40 import crosby.binary.Osmformat.Relation.MemberType; 38 41 import crosby.binary.file.BlockInputStream; 39 42 import crosby.binary.file.FileBlockPosition; 40 43 41 44 /** 45 * OSM reader for the PBF file format. 42 46 * @author Don-vip 43 *44 47 */ 45 48 public class PbfReader extends AbstractReader { 46 49 47 50 protected class PbfParser extends BinaryParser { 48 51 49 p ublicIllegalDataException exception = null;50 52 private IllegalDataException exception = null; 53 private boolean discourageUpload; 51 54 private double parseRawDegrees(long raw) { 52 55 return raw * .000000001; 53 56 } 54 57 55 58 @Override 56 59 protected void parse(HeaderBlock header) { 57 60 58 61 for (String requiredFeature : header.getRequiredFeaturesList()) { 59 62 switch (requiredFeature) { … … 67 70 } 68 71 } 69 72 70 73 HeaderBBox bbox = header.getBbox(); 71 74 if (bbox != null) { … … 75 78 double maxlon = parseRawDegrees(bbox.getRight()); 76 79 Bounds b = new Bounds(minlat, minlon, maxlat, maxlon); 77 if (!b.isCollapsed() && LatLon.isValidLat(minlat) && LatLon.isValidLat(maxlat) 78 && LatLon.isValidLon(minlon) && LatLon.isValidLon(maxlon)) { 80 if (!b.isCollapsed() && areCoordinatesValid(minlat, minlon, maxlat, maxlon)) { 79 81 ds.dataSources.add(new DataSource(b, header.getSource())); 80 82 } else { … … 84 86 } 85 87 88 private boolean areCoordinatesValid(double minlat, double minlon, double maxlat, double maxlon) { 89 return LatLon.isValidLat(minlat) && LatLon.isValidLat(maxlat) 90 && LatLon.isValidLon(minlon) && LatLon.isValidLon(maxlon); 91 } 92 93 private void setMetadata(OsmPrimitive osm, Info info) throws IllegalDataException { 94 if (info.hasChangeset()) { 95 checkChangesetId(info.getChangeset()); 96 osm.setChangesetId((int) info.getChangeset()); 97 } 98 if (info.hasUid() && info.hasUserSid()) { 99 osm.setUser(User.createOsmUser(info.getUid(), getStringById(info.getUserSid()))); 100 } 101 if (info.hasTimestamp()) { 102 checkTimestamp(info.getTimestamp()); 103 osm.setTimestamp(getDate(info)); 104 } 105 } 106 86 107 @Override 87 108 public boolean skipBlock(FileBlockPosition block) { 88 109 return exception != null; 89 110 } 90 111 91 112 protected void checkCoordinates(LatLon coor) throws IllegalDataException { 92 113 if (!coor.isValid()) { … … 100 121 } 101 122 } 102 123 103 124 protected void checkTimestamp(long timestamp) throws IllegalDataException { 104 125 if (timestamp < 0) { … … 109 130 @Override 110 131 protected void parseDense(DenseNodes nodes) { 132 if (!nodes.hasDenseinfo()) 133 discourageUpload = true; 111 134 if (exception == null) { 112 135 try { … … 122 145 for (int i = 0; i < nodes.getIdCount(); i++) { 123 146 // Id (delta) and version (normal) 124 Node node = new Node(nodeId +=nodes.getId(i), nodes.getDenseinfo().getVersion(i));147 Node node = new Node(nodeId += nodes.getId(i), nodes.hasDenseinfo() ? nodes.getDenseinfo().getVersion(i) : 1); 125 148 // Lat/Lon (delta) 126 node.setCoor(new LatLon(parseLat(nodeLat+=nodes.getLat(i)), parseLon(nodeLon+=nodes.getLon(i))).getRoundedToOsmPrecision()); 149 node.setCoor(new LatLon(parseLat(nodeLat += nodes.getLat(i)), 150 parseLon(nodeLon += nodes.getLon(i))).getRoundedToOsmPrecision()); 127 151 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)); 152 if (nodes.hasDenseinfo()) { 153 DenseInfo info = nodes.getDenseinfo(); 154 // Changeset (delta) 155 if (info.getChangesetCount() > i) { 156 checkChangesetId(changesetId += info.getChangeset(i)); 157 node.setChangesetId((int) changesetId); 158 } 159 // User (delta) 160 if (info.getUidCount() > i && info.getUserSidCount() > i) { 161 node.setUser(User.createOsmUser(uid += info.getUid(i), 162 getStringById(suid += info.getUserSid(i)))); 163 } 164 // Timestamp (delta) 165 if (info.getTimestampCount() > i) { 166 checkTimestamp(timestamp += info.getTimestamp(i)); 167 node.setTimestamp(new Date(date_granularity * timestamp)); 168 } 169 } 136 170 // A single table contains all keys/values of all nodes. 137 171 // Each node's tags are encoded in alternating <key_id> <value_id>. … … 139 173 Map<String, String> keys = new HashMap<>(); 140 174 while (keyIndex < nodes.getKeysValsCount()) { 141 int key _id = nodes.getKeysVals(keyIndex++);142 if (key _id == 0) {175 int keyId = nodes.getKeysVals(keyIndex++); 176 if (keyId == 0) { 143 177 break; // End of current node's tags 144 178 } else if (keyIndex < nodes.getKeysValsCount()) { 145 int value_id = nodes.getKeysVals(keyIndex++); 146 keys.put(getStringById(key_id), getStringById(value_id)); 179 keys.put(getStringById(keyId), getStringById(nodes.getKeysVals(keyIndex++))); 147 180 } else { 148 181 throw new IllegalDataException(tr("Invalid DenseNodes key/values table")); … … 163 196 try { 164 197 for (Osmformat.Node n : osmNodes) { 165 final Info info = n.getInfo(); 166 final Node node = new Node(n.getId(), info.getVersion()); 198 final Info info = n.getInfo(); 199 if (!info.hasVersion()) 200 discourageUpload = true; 201 final Node node = new Node(n.getId(), info.hasVersion() ? info.getVersion() : 1); 167 202 node.setCoor(new LatLon(parseLat(n.getLat()), parseLon(n.getLon())).getRoundedToOsmPrecision()); 168 203 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)); 204 setMetadata(node, info); 174 205 Map<String, String> keys = new HashMap<>(); 175 for (int i =0; i<n.getKeysCount(); i++) {206 for (int i = 0; i < n.getKeysCount(); i++) { 176 207 keys.put(getStringById(n.getKeys(i)), getStringById(n.getVals(i))); 177 208 } … … 184 215 } 185 216 } 186 217 187 218 @Override 188 219 protected void parseWays(List<Osmformat.Way> osmWays) { … … 190 221 try { 191 222 for (Osmformat.Way w : osmWays) { 192 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)); 223 final Info info = w.getInfo(); 224 if (!info.hasVersion()) 225 discourageUpload = true; 226 final Way way = new Way(w.getId(), info.hasVersion() ? info.getVersion() : 1); 227 setMetadata(way, info); 199 228 Map<String, String> keys = new HashMap<>(); 200 for (int i =0; i<w.getKeysCount(); i++) {229 for (int i = 0; i < w.getKeysCount(); i++) { 201 230 keys.put(getStringById(w.getKeys(i)), getStringById(w.getVals(i))); 202 231 } … … 205 234 Collection<Long> nodeIds = new ArrayList<>(); 206 235 for (Long id : w.getRefsList()) { 207 nodeIds.add(previousId +=id);236 nodeIds.add(previousId += id); 208 237 } 209 238 ways.put(way.getUniqueId(), nodeIds); … … 215 244 } 216 245 } 217 246 218 247 @Override 219 248 protected void parseRelations(List<Osmformat.Relation> osmRels) { … … 221 250 try { 222 251 for (Osmformat.Relation r : osmRels) { 223 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)); 252 final Info info = r.getInfo(); 253 if (!info.hasVersion()) 254 discourageUpload = true; 255 final Relation rel = new Relation(r.getId(), info.hasVersion() ? info.getVersion() : 1); 256 setMetadata(rel, info); 230 257 Map<String, String> keys = new HashMap<>(); 231 for (int i =0; i<r.getKeysCount(); i++) {258 for (int i = 0; i < r.getKeysCount(); i++) { 232 259 keys.put(getStringById(r.getKeys(i)), getStringById(r.getVals(i))); 233 260 } … … 235 262 long previousId = 0; // Member ids are delta coded 236 263 Collection<RelationMemberData> members = new ArrayList<>(); 237 for (int i = 0; i<r.getMemidsCount(); i++) { 238 long id = previousId+=r.getMemids(i); 239 String role = getStringById(r.getRolesSid(i)); 240 OsmPrimitiveType type = null; 241 switch (r.getTypes(i)) { 242 case NODE: 243 type = OsmPrimitiveType.NODE; 244 break; 245 case WAY: 246 type = OsmPrimitiveType.WAY; 247 break; 248 case RELATION: 249 type = OsmPrimitiveType.RELATION; 250 break; 251 } 252 members.add(new RelationMemberData(role, type, id)); 264 for (int i = 0; i < r.getMemidsCount(); i++) { 265 members.add(new RelationMemberData( 266 getStringById(r.getRolesSid(i)), 267 mapOsmType(r.getTypes(i)), 268 previousId += r.getMemids(i))); 253 269 } 254 270 relations.put(rel.getUniqueId(), members); … … 259 275 } 260 276 } 277 if (discourageUpload) 278 ds.setUploadDiscouraged(true); 279 } 280 281 private OsmPrimitiveType mapOsmType(MemberType type) { 282 switch (type) { 283 case NODE: 284 return OsmPrimitiveType.NODE; 285 case WAY: 286 return OsmPrimitiveType.WAY; 287 case RELATION: 288 return OsmPrimitiveType.RELATION; 289 default: 290 return null; 291 } 261 292 } 262 293 263 294 @Override 264 295 public void complete() { 296 if (discourageUpload) 297 ds.setUploadDiscouraged(true); 265 298 } 266 299 } 267 300 268 301 private PbfParser parser = new PbfParser(); 269 302 270 303 /** 271 304 * Parse the given input source and return the dataset. … … 279 312 */ 280 313 public static DataSet parseDataSet(InputStream source, ProgressMonitor progressMonitor) throws IllegalDataException { 281 if (progressMonitor == null) { 282 progressMonitor = NullProgressMonitor.INSTANCE; 283 } 314 ProgressMonitor monitor = progressMonitor == null ? NullProgressMonitor.INSTANCE : progressMonitor; 284 315 CheckParameterUtil.ensureParameterNotNull(source, "source"); 285 316 286 317 PbfReader reader = new PbfReader(); 287 318 288 319 try { 289 progressMonitor.beginTask(tr("Prepare OSM data...", 2));290 progressMonitor.indeterminateSubTask(tr("Reading OSM data..."));320 monitor.beginTask(tr("Prepare OSM data...", 2)); 321 monitor.indeterminateSubTask(tr("Reading OSM data...")); 291 322 292 323 reader.parse(source); 293 progressMonitor.worked(1);294 295 progressMonitor.indeterminateSubTask(tr("Preparing data set..."));324 monitor.worked(1); 325 326 monitor.indeterminateSubTask(tr("Preparing data set...")); 296 327 reader.prepareDataSet(); 297 progressMonitor.worked(1);328 monitor.worked(1); 298 329 return reader.getDataSet(); 299 330 } catch (IllegalDataException e) { … … 302 333 throw new IllegalDataException(e); 303 334 } finally { 304 progressMonitor.finishTask();335 monitor.finishTask(); 305 336 } 306 337 } -
applications/editors/josm/plugins/pbf/src/org/openstreetmap/josm/plugins/pbf/io/PbfServerReader.java
r30341 r32859 9 9 import org.openstreetmap.josm.io.OsmTransferException; 10 10 11 /** 12 * This DataReader reads PBF directly from an URL. 13 */ 11 14 public class PbfServerReader extends OsmServerReader { 12 15 13 private String url; 14 15 public PbfServerReader(String url) { 16 this.url = url; 17 } 16 private String url; 18 17 19 @Override 20 public DataSet parseOsm(ProgressMonitor progressMonitor) 21 throws OsmTransferException { 18 /** 19 * Constructs a new {@code PbfServerReader}. 20 * @param url source URL 21 */ 22 public PbfServerReader(String url) { 23 this.url = url; 24 } 25 26 @Override 27 public DataSet parseOsm(ProgressMonitor progressMonitor) 28 throws OsmTransferException { 22 29 try { 23 30 progressMonitor.beginTask(tr("Contacting Server...", 10)); … … 28 35 progressMonitor.finishTask(); 29 36 } 30 37 } 31 38 } -
applications/editors/josm/plugins/pbf/src/org/openstreetmap/josm/plugins/pbf/io/PbfWriter.java
r30737 r32859 29 29 import crosby.binary.file.FileBlock; 30 30 31 /** 32 * OSM writer for the PBF file format. 33 * @author Don-vip 34 */ 31 35 public class PbfWriter implements Closeable { 32 36 33 37 private final PbfSerializer out; 34 38 39 /** 40 * Constructs a new {@code PbfWriter}. 41 * @param out output stream 42 */ 35 43 public PbfWriter(OutputStream out) { 36 44 this.out = new PbfSerializer(new BlockOutputStream(out)); … … 42 50 /** Additional configuration flag for whether to serialize into DenseNodes/DenseInfo? */ 43 51 protected boolean useDense = true; 44 52 45 53 /** Has the header been written yet? */ 46 54 protected boolean headerWritten = false; … … 48 56 /** 49 57 * Constructs a new {@code PbfSerializer}. 50 * 58 * 51 59 * @param output The PBF block stream to send serialized data 52 60 */ … … 57 65 /** 58 66 * Change the flag of whether to use the dense format. 59 * 67 * 60 68 * @param useDense The new use dense value. 61 69 */ … … 73 81 /** 74 82 * Add to the queue. 75 * 83 * 76 84 * @param item The entity to add 77 85 */ … … 101 109 } 102 110 103 long lasttimestamp = 0, lastchangeset = 0; 104 int lastuserSid = 0, lastuid = 0; 111 long lasttimestamp = 0; 112 long lastchangeset = 0; 113 int lastuserSid = 0; 114 int lastuid = 0; 105 115 StringTable stable = getStringTable(); 106 116 for (OsmPrimitive e : entities) { 107 117 108 int uid = 118 int uid = e.getUser() == null ? -1 : (int) e.getUser().getId(); 109 119 int userSid = stable.getIndex(e.getUser() == null ? "" : e.getUser().getName()); 110 120 int timestamp = (int) (e.getTimestamp().getTime() / date_granularity); … … 139 149 } 140 150 } 141 151 142 152 private class NodeGroup extends Prim<Node> implements PrimGroupWriterInterface { 143 153 154 @Override 144 155 public Osmformat.PrimitiveGroup serialize() { 145 156 if (useDense) { … … 154 165 */ 155 166 public Osmformat.PrimitiveGroup serializeDense() { 156 if (contents. size() == 0) {167 if (contents.isEmpty()) { 157 168 return null; 158 169 } … … 160 171 StringTable stable = getStringTable(); 161 172 162 long lastlat = 0, lastlon = 0, lastid = 0; 173 long lastlat = 0; 174 long lastlon = 0; 175 long lastid = 0; 163 176 Osmformat.DenseNodes.Builder bi = Osmformat.DenseNodes.newBuilder(); 164 177 boolean doesBlockHaveTags = false; … … 202 215 /** 203 216 * Serialize all nodes in the non-dense format. 204 * 217 * 205 218 * @param parentbuilder Add to this PrimitiveBlock. 206 219 */ 207 220 public Osmformat.PrimitiveGroup serializeNonDense() { 208 if (contents. size() == 0) {221 if (contents.isEmpty()) { 209 222 return null; 210 223 } … … 235 248 private class WayGroup extends Prim<Way> implements 236 249 PrimGroupWriterInterface { 250 @Override 237 251 public Osmformat.PrimitiveGroup serialize() { 238 if (contents. size() == 0) {252 if (contents.isEmpty()) { 239 253 return null; 240 254 } … … 265 279 266 280 private class RelationGroup extends Prim<Relation> implements PrimGroupWriterInterface { 281 @Override 267 282 public void addStringsToStringtable() { 268 283 StringTable stable = getStringTable(); … … 275 290 } 276 291 292 @Override 277 293 public Osmformat.PrimitiveGroup serialize() { 278 if (contents. size() == 0) {294 if (contents.isEmpty()) { 279 295 return null; 280 296 } … … 299 315 bi.addTypes(MemberType.RELATION); 300 316 } else { 301 assert (false); // Software bug: Unknown entity.317 assert false; // Software bug: Unknown entity. 302 318 } 303 319 bi.addRolesSid(stable.getIndex(j.getRole())); … … 321 337 private NodeGroup nodes; 322 338 private RelationGroup relations; 323 339 324 340 private Processor processor = new Processor(); 325 341 … … 350 366 } 351 367 368 /** 369 * Process node. 370 * @param node node 371 */ 352 372 public void processNode(Node node) { 353 373 if (nodes == null) { … … 362 382 } 363 383 384 /** 385 * Process way. 386 * @param way way 387 */ 364 388 public void processWay(Way way) { 365 389 if (ways == null) { … … 372 396 } 373 397 398 /** 399 * Process relation. 400 * @param relation relation 401 */ 374 402 public void processRelation(Relation relation) { 375 403 if (relations == null) { … … 404 432 public void processBounds(DataSource entity) { 405 433 Osmformat.HeaderBlock.Builder headerblock = Osmformat.HeaderBlock.newBuilder(); 406 434 407 435 Osmformat.HeaderBBox.Builder bbox = Osmformat.HeaderBBox.newBuilder(); 408 436 bbox.setLeft(mapRawDegrees(entity.bounds.getMinLon())); … … 429 457 /** 430 458 * Write the header fields that are always needed. 431 * 459 * 432 460 * @param headerblock Incomplete builder to complete and write. 433 461 * */ … … 446 474 headerWritten = true; 447 475 } 448 476 449 477 public void process(DataSet ds) { 450 478 processor.processSources(ds.dataSources); … … 471 499 } 472 500 501 /** 502 * Writes data to an OSM data layer. 503 * @param layer data layer 504 */ 473 505 public void writeLayer(OsmDataLayer layer) { 474 506 writeData(layer.data); 475 507 } 476 508 509 /** 510 * Writes data to a dataset. 511 * @param ds dataset 512 */ 477 513 public void writeData(DataSet ds) { 478 514 out.process(ds);
Note:
See TracChangeset
for help on using the changeset viewer.