Good news: I have started to add the MDR6 with ZIP information to the
index branch.
Bad new: It does not work yet.
But I want to post it in this early stage. Maybe someone of you can have
a look on it and can find my early beginners fault in creating an MDR
section :-)
WanMil
Index: src/uk/me/parabola/imgfmt/app/map/MapReader.java
===================================================================
--- src/uk/me/parabola/imgfmt/app/map/MapReader.java (revision 1781)
+++ src/uk/me/parabola/imgfmt/app/map/MapReader.java (working copy)
@@ -26,6 +26,7 @@
import uk.me.parabola.imgfmt.app.lbl.Country;
import uk.me.parabola.imgfmt.app.lbl.LBLFileReader;
import uk.me.parabola.imgfmt.app.lbl.Region;
+import uk.me.parabola.imgfmt.app.lbl.Zip;
import uk.me.parabola.imgfmt.app.net.NETFileReader;
import uk.me.parabola.imgfmt.app.trergn.Point;
import uk.me.parabola.imgfmt.app.trergn.Polyline;
@@ -153,6 +154,10 @@
public List<Region> getRegions() {
return lblFile.getRegions();
}
+
+ public List<Zip> getZips() {
+ return lblFile.getZips();
+ }
public Area getTreBounds() {
return treFile.getBounds();
Index: src/uk/me/parabola/imgfmt/app/mdr/MDRFile.java
===================================================================
--- src/uk/me/parabola/imgfmt/app/mdr/MDRFile.java (revision 1781)
+++ src/uk/me/parabola/imgfmt/app/mdr/MDRFile.java (working copy)
@@ -19,6 +19,7 @@
import uk.me.parabola.imgfmt.app.Label;
import uk.me.parabola.imgfmt.app.lbl.Country;
import uk.me.parabola.imgfmt.app.lbl.Region;
+import uk.me.parabola.imgfmt.app.lbl.Zip;
import uk.me.parabola.imgfmt.app.srt.Sort;
import uk.me.parabola.imgfmt.app.trergn.Point;
import uk.me.parabola.imgfmt.app.trergn.Polyline;
@@ -31,13 +32,15 @@
* @author Steve Ratcliffe
*/
public class MDRFile extends ImgFile {
-
+ private final boolean mdr6enabled = true;
+
private final MDRHeader mdrHeader;
// The sections
private final Mdr1 mdr1;
private final Mdr4 mdr4;
private final Mdr5 mdr5;
+ private final Mdr6 mdr6;
private final Mdr7 mdr7;
private final Mdr8 mdr8;
private final Mdr9 mdr9;
@@ -75,6 +78,7 @@
mdr1 = new Mdr1(config);
mdr4 = new Mdr4(config);
mdr5 = new Mdr5(config);
+ mdr6 = new Mdr6(config);
mdr7 = new Mdr7(config);
mdr8 = new Mdr8(config);
mdr9 = new Mdr9(config);
@@ -86,7 +90,7 @@
mdr15 = new Mdr15(config);
this.sections = new MdrSection[]{
null,
- mdr1, null, null, mdr4, mdr5, null,
+ mdr1, null, null, mdr4, mdr5, (mdr6enabled ? mdr6 : null),
mdr7, mdr8, mdr9, mdr10, mdr11, mdr12,
mdr13, mdr14, mdr15
};
@@ -128,6 +132,13 @@
mdr5.addCity(currentMap, city, labelOffset, name, strOff);
}
}
+
+ public void addZip(Zip zip) {
+ if (mdr6enabled) {
+ int strOff = createString(zip.getLabel().getText());
+ mdr6.addZip(currentMap, zip, strOff);
+ }
+ }
public void addPoint(Point point, Mdr5Record city, boolean isCity) {
assert currentMap > 0;
@@ -195,8 +206,10 @@
mdr8.setIndex(mdr7.getIndex());
writeSection(writer, 8, mdr8);
writeSection(writer, 5, mdr5);
- //writeSection(writer, 6, mdr6);
-
+ if (mdr6enabled) {
+ writeSection(writer, 6, mdr6);
+ }
+
// 9 depends on stuff from 10.
mdr9.setGroups(mdr10.getGroupSizes());
writeSection(writer, 9, mdr9);
Index: src/uk/me/parabola/imgfmt/app/mdr/Mdr6.java
===================================================================
--- src/uk/me/parabola/imgfmt/app/mdr/Mdr6.java (revision 0)
+++ src/uk/me/parabola/imgfmt/app/mdr/Mdr6.java (revision 0)
@@ -0,0 +1,93 @@
+/*
+ * Copyright (C) 2009.
+ *
+ * This program is free software; you can redistribute it and/or modify
+ * it under the terms of the GNU General Public License version 3 or
+ * version 2 as published by the Free Software Foundation.
+ *
+ * This program is distributed in the hope that it will be useful, but
+ * WITHOUT ANY WARRANTY; without even the implied warranty of
+ * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
+ * General Public License for more details.
+ */
+package uk.me.parabola.imgfmt.app.mdr;
+
+import java.util.ArrayList;
+import java.util.List;
+
+import uk.me.parabola.imgfmt.app.ImgFileWriter;
+import uk.me.parabola.imgfmt.app.lbl.Zip;
+import uk.me.parabola.imgfmt.app.srt.SortKey;
+
+/**
+ * Section containing cities.
+ *
+ * We need: map number, city index in map, offset in LBL, flags
+ * and pointer into MDR 15 for the string name.
+ *
+ * @author Steve Ratcliffe
+ */
+public class Mdr6 extends MdrMapSection {
+
+ private final List<Mdr6Record> zips = new ArrayList<Mdr6Record>();
+
+
+ public Mdr6(MdrConfig config) {
+ setConfig(config);
+ }
+
+ public void addZip(int mapIndex, Zip zip, int strOff) {
+ Mdr6Record record = new Mdr6Record(zip);
+ record.setMapIndex(mapIndex);
+ record.setStringOffset(strOff);
+ zips.add(record);
+ }
+
+
+ public void writeSectData(ImgFileWriter writer) {
+ int zipSize = getPointerSize();
+
+ List<SortKey<Mdr6Record>> sortKeys = MdrUtils.sortList(getConfig().getSort(), zips);
+ for (SortKey<Mdr6Record> key : sortKeys) {
+ Mdr6Record z = key.getObject();
+ putMapIndex(writer, z.getMapIndex());
+ putN(writer, zipSize, z.getZipIndex());
+ putStringOffset(writer, z.getStringOffset());
+ }
+ }
+
+ /**
+ * Base size of 8, plus enough bytes to represent the map number
+ * and the city number.
+ * @return The size of a record in this section.
+ */
+ public int getItemSize() {
+ PointerSizes sizes = getSizes();
+ return sizes.getMapSize() + getPointerSize() + sizes.getStrOffSize();
+ }
+
+ public int getNumberOfItems() {
+ return zips.size();
+ }
+
+ /**
+ * Get the size of an integer that is sufficient to store a record number
+ * from this section.
+ * @return A number between 1 and 4 giving the number of bytes required
+ * to store the largest record number in this section.
+ */
+ public int getPointerSize() {
+ return numberToPointerSize(zips.size());
+ }
+
+ /**
+ * Known structure:
+ * bits 0-1: size of local city index - 1 (all values appear to work)
+ * bits 2: if MDR 15 available
+ * bit 4 does not appear to have any effect
+ * @return The value to be placed in the header.
+ */
+ public int getExtraValue() {
+ return 0x04 | (getPointerSize()-1)&0x03;
+ }
+}
Index: src/uk/me/parabola/imgfmt/app/mdr/Mdr6Record.java
===================================================================
--- src/uk/me/parabola/imgfmt/app/mdr/Mdr6Record.java (revision 0)
+++ src/uk/me/parabola/imgfmt/app/mdr/Mdr6Record.java (revision 0)
@@ -0,0 +1,51 @@
+/*
+ * Copyright (C) 2009.
+ *
+ * This program is free software; you can redistribute it and/or modify
+ * it under the terms of the GNU General Public License version 3 or
+ * version 2 as published by the Free Software Foundation.
+ *
+ * This program is distributed in the hope that it will be useful, but
+ * WITHOUT ANY WARRANTY; without even the implied warranty of
+ * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
+ * General Public License for more details.
+ */
+package uk.me.parabola.imgfmt.app.mdr;
+
+import uk.me.parabola.imgfmt.app.lbl.Zip;
+
+/**
+ * Holds information about a zip that will make its way into mdr 6.
+ * This class is used in several places as the information has to be gathered
+ * from the zips section of LBL.
+ *
+ * @author Steve Ratcliffe
+ */
+public class Mdr6Record extends RecordBase implements NamedRecord {
+ /** The zip index within its own map */
+ private final int zipIndex;
+
+ private final String name;
+ private int stringOffset;
+
+ public Mdr6Record(Zip zip) {
+ zipIndex = zip.getIndex();
+ name = zip.getLabel().getText();
+ }
+
+ public int getZipIndex() {
+ return zipIndex;
+ }
+
+ public String getName() {
+ return name;
+ }
+
+ public int getStringOffset() {
+ return stringOffset;
+ }
+
+ public void setStringOffset(int stringOffset) {
+ this.stringOffset = stringOffset;
+ }
+}
Index: src/uk/me/parabola/imgfmt/app/lbl/LBLFileReader.java
===================================================================
--- src/uk/me/parabola/imgfmt/app/lbl/LBLFileReader.java (revision 1781)
+++ src/uk/me/parabola/imgfmt/app/lbl/LBLFileReader.java (working copy)
@@ -50,6 +50,7 @@
private final Map<Integer, POIRecord> pois = new HashMap<Integer, POIRecord>();
private final Map<Integer, Country> countries = new HashMap<Integer, Country>();
private final Map<Integer, Region> regions = new HashMap<Integer, Region>();
+ private final Map<Integer, Zip> zips = new HashMap<Integer, Zip>();
private final List<City> cities = new ArrayList<City>();
@@ -69,6 +70,7 @@
readCities();
readPoiInfo();
+ readZips();
}
/**
@@ -102,6 +104,10 @@
public List<Region> getRegions() {
return new ArrayList<Region>(regions.values());
}
+
+ public List<Zip> getZips() {
+ return new ArrayList<Zip>(zips.values());
+ }
/**
* Return POI information.
@@ -260,6 +266,28 @@
return currentOffset + 1 + encText.getOffsetAdjustment();
}
+ private void readZips() {
+ ImgFileReader reader = getReader();
+
+ PlacesHeader placeHeader = header.getPlaceHeader();
+ int start = placeHeader.getZipsStart();
+ int end = placeHeader.getZipsEnd();
+
+ reader.position(start);
+
+ int zipIndex = 1;
+ while (reader.position() < end) {
+ int lblOffset = reader.get3();
+
+ Zip zip = new Zip(zipIndex);
+ zip.setLabel(fetchLabel(lblOffset));
+
+ zips.put(zip.getIndex(), zip);
+
+ zipIndex++;
+ }
+ }
+
/**
* Read all the POI information.
* This will create a POIRecord, but we just get the name at the minute.
@@ -359,8 +387,8 @@
if (placeHeader.getNumZips() > 0xff)
n = reader.getChar();
else
- n = reader.get();
- // TODO save the zip
+ n = reader.get() & 0xff;
+ poi.setZipIndex(n);
}
if (hasPhone) {
Index: src/uk/me/parabola/imgfmt/app/lbl/PlacesHeader.java
===================================================================
--- src/uk/me/parabola/imgfmt/app/lbl/PlacesHeader.java (revision 1781)
+++ src/uk/me/parabola/imgfmt/app/lbl/PlacesHeader.java (working copy)
@@ -253,4 +253,12 @@
public int getNumHighways() {
return highway.getNumItems();
}
+
+ public int getZipsStart() {
+ return zip.getPosition();
+ }
+
+ public int getZipsEnd() {
+ return zip.getEndPos();
+ }
}
Index: src/uk/me/parabola/imgfmt/app/lbl/Zip.java
===================================================================
--- src/uk/me/parabola/imgfmt/app/lbl/Zip.java (revision 1781)
+++ src/uk/me/parabola/imgfmt/app/lbl/Zip.java (working copy)
@@ -28,7 +28,6 @@
// The index is not stored in the file, you just use the index of it in
// the section.
private final int index;
-
private Label label;
public Zip(int index) {
@@ -39,6 +38,10 @@
writer.put3(label.getOffset());
}
+ public Label getLabel() {
+ return label;
+ }
+
public void setLabel(Label label) {
this.label = label;
}
@@ -46,4 +49,5 @@
public int getIndex() {
return index;
}
+
}
Index: src/uk/me/parabola/mkgmap/combiners/MdrBuilder.java
===================================================================
--- src/uk/me/parabola/mkgmap/combiners/MdrBuilder.java (revision 1781)
+++ src/uk/me/parabola/mkgmap/combiners/MdrBuilder.java (working copy)
@@ -33,6 +33,7 @@
import uk.me.parabola.imgfmt.app.lbl.Country;
import uk.me.parabola.imgfmt.app.lbl.POIRecord;
import uk.me.parabola.imgfmt.app.lbl.Region;
+import uk.me.parabola.imgfmt.app.lbl.Zip;
import uk.me.parabola.imgfmt.app.map.MapReader;
import uk.me.parabola.imgfmt.app.mdr.MDRFile;
import uk.me.parabola.imgfmt.app.mdr.Mdr5Record;
@@ -163,6 +164,7 @@
addPoints(mr, cityMap);
addCities(cityMap);
addStreets(mr);
+ addZips(mr);
} catch (FileNotFoundException e) {
throw new ExitException("Could not open " + filename + " when creating mdr file");
} finally {
@@ -187,6 +189,12 @@
mdrFile.addCity(c);
}
}
+
+ private void addZips(MapReader mr) {
+ List<Zip> zips = mr.getZips();
+ for (Zip zip : zips)
+ mdrFile.addZip(zip);
+ }
/**
* Make a map from the subdivision and point index of the city within
_______________________________________________
mkgmap-dev mailing list
[email protected]
http://www.mkgmap.org.uk/mailman/listinfo/mkgmap-dev