MDR6 seems to work now. Mapsource shows the zip codes in the search
dialog. So far I wasn't able to read out the zip information from the
NET section. So address search with zips will give no results at the
moment. I don't know how long it will take for me to realize this. If
anyone likes to implement that, please let me know :-)
@Steve: I stumbled upon a little pitfall in the MDRHeader class. This
class writes static header values for some MDR sections. Did you check
if these values are still up to date?
The MDR6 patch could be committed because I didn't see any drawback.
Steve, decide on your own if want to include that in the index branch
right now.
WanMil
Hi WanMil
First, thanks very much for working on the index!
Steve: Do you know where addresses are loaded? At the moment only the
zips of POIs are put into the MDR6 and on a first look I haven't found
where addresses with street names and house number etc. are loaded.
All address information for streets is in the NET section. Look at
RoadDef for the class that writes it out. We only do ZIPs/cities
currently.
..Steve
_______________________________________________
mkgmap-dev mailing list
[email protected]
http://www.mkgmap.org.uk/mailman/listinfo/mkgmap-dev
Index: src/uk/me/parabola/imgfmt/app/map/MapReader.java
===================================================================
--- src/uk/me/parabola/imgfmt/app/map/MapReader.java (revision 1783)
+++ 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,12 @@
public List<Region> getRegions() {
return lblFile.getRegions();
}
+
+ public List<Zip> getZips() {
+ // TODO join with zip information from the addresses
+ // where are the addresses stored?
+ return lblFile.getZips();
+ }
public Area getTreBounds() {
return treFile.getBounds();
Index: src/uk/me/parabola/imgfmt/app/mdr/MDRHeader.java
===================================================================
--- src/uk/me/parabola/imgfmt/app/mdr/MDRHeader.java (revision 1783)
+++ src/uk/me/parabola/imgfmt/app/mdr/MDRHeader.java (working copy)
@@ -86,8 +86,7 @@
sections[5].writeSectionInfo(writer, true, true);
- sections[6].writeSectionInfo(writer);
- writer.putInt(2);
+ sections[6].writeSectionInfo(writer, true, true);
sections[7].writeSectionInfo(writer, true, true);
Index: src/uk/me/parabola/imgfmt/app/mdr/Mdr1.java
===================================================================
--- src/uk/me/parabola/imgfmt/app/mdr/Mdr1.java (revision 1783)
+++ src/uk/me/parabola/imgfmt/app/mdr/Mdr1.java (working copy)
@@ -35,7 +35,7 @@
* sub2 points into MDR 10 (POI types)
* sub3 points into MDR 7 (street names)
* sub4 points into MDR 5 (cities)
- * sub5 points into MDR 6
+ * sub5 points into MDR 6 (zips)
* sub6 points into MDR 20
* sub7 points into MDR 21
* sub8 points into MDR 22
Index: src/uk/me/parabola/imgfmt/app/mdr/MDRFile.java
===================================================================
--- src/uk/me/parabola/imgfmt/app/mdr/MDRFile.java (revision 1783)
+++ 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,13 @@
* @author Steve Ratcliffe
*/
public class MDRFile extends ImgFile {
-
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 +76,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 +88,7 @@
mdr15 = new Mdr15(config);
this.sections = new MdrSection[]{
null,
- mdr1, null, null, mdr4, mdr5, null,
+ mdr1, null, null, mdr4, mdr5, mdr6,
mdr7, mdr8, mdr9, mdr10, mdr11, mdr12,
mdr13, mdr14, mdr15
};
@@ -128,6 +130,11 @@
mdr5.addCity(currentMap, city, labelOffset, name, strOff);
}
}
+
+ public void addZip(Zip zip) {
+ 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 +202,8 @@
mdr8.setIndex(mdr7.getIndex());
writeSection(writer, 8, mdr8);
writeSection(writer, 5, mdr5);
- //writeSection(writer, 6, mdr6);
-
+ 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,92 @@
+/*
+ * 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 zip codes.
+ *
+ * We need: map number, zip index in map, pointer into MDR 15 for the string name.
+ *
+ * @author WanMil
+ */
+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());
+ }
+ }
+
+ /**
+ * Enough bytes to represent the map number
+ * and the zip index and the string offset.
+ * @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 zip 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 ((getPointerSize()-1)&0x03) | 0x04;
+ }
+}
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,49 @@
+/*
+ * 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.
+ *
+ * @author WanMil
+ */
+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/mdr/package.html
===================================================================
--- src/uk/me/parabola/imgfmt/app/mdr/package.html (revision 1783)
+++ src/uk/me/parabola/imgfmt/app/mdr/package.html (working copy)
@@ -11,6 +11,6 @@
<p>
Initial sections to implement: 1, 4, 5, 6, 7, 11, 15.
- Of these 4 and 6 are not known and only some subsection of MDR 1 are
+ Of these 4 is not known and only some subsection of MDR 1 are
also not known.
</body>
\ No newline at end of file
Index: src/uk/me/parabola/imgfmt/app/lbl/LBLFileReader.java
===================================================================
--- src/uk/me/parabola/imgfmt/app/lbl/LBLFileReader.java (revision 1783)
+++ 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>();
@@ -68,6 +69,7 @@
readRegions();
readCities();
+ readZips();
readPoiInfo();
}
@@ -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,32 @@
return currentOffset + 1 + encText.getOffsetAdjustment();
}
+
+ /**
+ * Reads the zips.
+ */
+ 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 +391,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 1783)
+++ 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 1783)
+++ 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 1783)
+++ 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