I started to strip down the index branch to things that work so that we can add more and more things until we get a running index branch.

As a first step I modified the OSM reader so that there will be no special character for sure. All non recognized characters ('a'-'z','A'-'Z','0'-'9',' ','-') are replaced by 'Z'. As far as I understood the character encoding might be a problem. So replacing all problematic characters might help. (see attached patch)

2nd: I splitted Germany with the default splitter settings so that I get big enough tiles.

3rd: I removed MDR8 and MDR12 from the MDRFile class.

4th: I compiled a map using 2 tiles from my Germany split.

The result was interesting:
* POI search works
* All region search fields are disabled
* I don't see any more exceptions or crashes in MapSource
* Street search still has the problem with the message "Selected street is not allowed in this map product" (translated from german...) * Most of the country information is set to ABC. I don't know if that has something to do with removing the --make-poi-index option?


I observed the same result when I added the MDR8.
Adding MDR12 returns to the old behaviour with exceptions and MapSource crashes.

WanMil

Index: src/uk/me/parabola/mkgmap/reader/osm/xml/Osm5XmlHandler.java
===================================================================
--- src/uk/me/parabola/mkgmap/reader/osm/xml/Osm5XmlHandler.java	(revision 1787)
+++ src/uk/me/parabola/mkgmap/reader/osm/xml/Osm5XmlHandler.java	(working copy)
@@ -16,6 +16,8 @@
  */
 package uk.me.parabola.mkgmap.reader.osm.xml;
 
+import java.nio.charset.Charset;
+
 import uk.me.parabola.imgfmt.app.Coord;
 import uk.me.parabola.log.Logger;
 import uk.me.parabola.mkgmap.reader.osm.Element;
@@ -34,12 +36,12 @@
 
 /**
  * Reads and parses the OSM XML format.
- *
+ * 
  * Creates the nodes/ways and relations that are read from the file and passes
  * them to the OsmCollector.
- *
+ * 
  * It should not examine tags, or do anything else.
- *
+ * 
  * @author Steve Ratcliffe
  */
 public class Osm5XmlHandler extends OsmHandler {
@@ -67,35 +69,40 @@
 
 	public Osm5XmlHandler(EnhancedProperties props) {
 		ignoreBounds = props.getProperty("ignore-osm-bounds", false);
-		reportUndefinedNodes = props.getProperty("report-undefined-nodes", false);
+		reportUndefinedNodes = props.getProperty("report-undefined-nodes",
+				false);
 	}
 
 	/**
 	 * The XML handler callbacks.
-	 *
-	 * Need an inner class here so that the top class can inherit from OsmHandler.
+	 * 
+	 * Need an inner class here so that the top class can inherit from
+	 * OsmHandler.
 	 */
 	public class SaxHandler extends DefaultHandler {
 
 		/**
 		 * Receive notification of the start of an element.
-		 *
-		 * @param uri		The Namespace URI, or the empty string if the
-		 *                   element has no Namespace URI or if Namespace
-		 *                   processing is not being performed.
-		 * @param localName  The local name (without prefix), or the
-		 *                   empty string if Namespace processing is not being
-		 *                   performed.
-		 * @param qName	  The qualified name (with prefix), or the
-		 *                   empty string if qualified names are not available.
-		 * @param attributes The attributes attached to the element.  If
-		 *                   there are no attributes, it shall be an empty
-		 *                   Attributes object.
-		 * @throws SAXException Any SAX exception, possibly
-		 *                                  wrapping another exception.
+		 * 
+		 * @param uri
+		 *            The Namespace URI, or the empty string if the element has
+		 *            no Namespace URI or if Namespace processing is not being
+		 *            performed.
+		 * @param localName
+		 *            The local name (without prefix), or the empty string if
+		 *            Namespace processing is not being performed.
+		 * @param qName
+		 *            The qualified name (with prefix), or the empty string if
+		 *            qualified names are not available.
+		 * @param attributes
+		 *            The attributes attached to the element. If there are no
+		 *            attributes, it shall be an empty Attributes object.
+		 * @throws SAXException
+		 *             Any SAX exception, possibly wrapping another exception.
 		 * @see ContentHandler#startElement
 		 */
-		public void startElement(String uri, String localName, String qName, Attributes attributes) throws SAXException {
+		public void startElement(String uri, String localName, String qName,
+				Attributes attributes) throws SAXException {
 			if (mode == 0) {
 				if (qName.equals("node")) {
 					mode = MODE_NODE;
@@ -109,18 +116,19 @@
 
 				} else if (qName.equals("relation")) {
 					mode = MODE_RELATION;
-					currentRelation = new GeneralRelation(idVal(attributes.getValue("id")));
+					currentRelation = new GeneralRelation(
+							idVal(attributes.getValue("id")));
 
 				} else if (qName.equals("bound")) {
 					mode = MODE_BOUND;
-					if(!ignoreBounds) {
+					if (!ignoreBounds) {
 						String box = attributes.getValue("box");
 						setupBBoxFromBound(box);
 					}
 
 				} else if (qName.equals("bounds")) {
 					mode = MODE_BOUNDS;
-					if(!ignoreBounds)
+					if (!ignoreBounds)
 						setupBBoxFromBounds(attributes);
 				}
 
@@ -135,20 +143,23 @@
 
 		/**
 		 * Receive notification of the end of an element.
-		 *
-		 * @param uri	   The Namespace URI, or the empty string if the
-		 *                  element has no Namespace URI or if Namespace
-		 *                  processing is not being performed.
-		 * @param localName The local name (without prefix), or the
-		 *                  empty string if Namespace processing is not being
-		 *                  performed.
-		 * @param qName	 The qualified name (with prefix), or the
-		 *                  empty string if qualified names are not available.
-		 * @throws SAXException Any SAX exception, possibly
-		 *                                  wrapping another exception.
+		 * 
+		 * @param uri
+		 *            The Namespace URI, or the empty string if the element has
+		 *            no Namespace URI or if Namespace processing is not being
+		 *            performed.
+		 * @param localName
+		 *            The local name (without prefix), or the empty string if
+		 *            Namespace processing is not being performed.
+		 * @param qName
+		 *            The qualified name (with prefix), or the empty string if
+		 *            qualified names are not available.
+		 * @throws SAXException
+		 *             Any SAX exception, possibly wrapping another exception.
 		 * @see ContentHandler#endElement
 		 */
-		public void endElement(String uri, String localName, String qName) throws SAXException {
+		public void endElement(String uri, String localName, String qName)
+				throws SAXException {
 			if (mode == MODE_NODE) {
 				if (qName.equals("node")) {
 					mode = 0;
@@ -185,8 +196,9 @@
 		}
 
 		/**
-		 * Called on an XML error.  Attempt to print a line number to aid in
+		 * Called on an XML error. Attempt to print a line number to aid in
 		 * working out the problem.
+		 * 
 		 * @throws SAXException
 		 */
 		public void fatalError(SAXParseException e) throws SAXException {
@@ -196,18 +208,45 @@
 		}
 	}
 
+	private String replace(String org) {
+		StringBuilder sb = new StringBuilder(org);
+		for (int i = 0; i < sb.length(); i++) {
+			char c = sb.charAt(i);
+			if (c >= 'a' && c <= 'z') {
+				continue;
+			}
+			if (c >= 'A' && c <= 'Z') {
+				continue;
+			}
+			if (c >= '0' && c <= '9') {
+				continue;
+			}
+			if (c == ' ') {
+				continue;
+			}
+			if (c == '-') {
+				continue;
+			}
+			sb.setCharAt(i, 'Z');
+		}
+		return sb.toString().intern();
+	}
+
 	/**
 	 * A new tag has been started while we are inside a node element.
-	 * @param qName The new tag name.
-	 * @param attributes Its attributes.
+	 * 
+	 * @param qName
+	 *            The new tag name.
+	 * @param attributes
+	 *            Its attributes.
 	 */
 	private void startInNode(String qName, Attributes attributes) {
 		if (qName.equals("tag")) {
 			String key = attributes.getValue("k");
-			String val = attributes.getValue("v");
+			String val = replace(attributes.getValue("v"));
 
-			if("mkgmap:on-boundary".equals(key)) { // FIXME checking tag value
-				if("1".equals(val) || "true".equals(val) || "yes".equals(val)) {
+			if ("mkgmap:on-boundary".equals(key)) { // FIXME checking tag value
+				if ("1".equals(val) || "true".equals(val) || "yes".equals(val)) {
 					Coord co = saver.getCoord(currentElementId);
 					co.setOnBoundary(true);
 					co.incHighwayCount();
@@ -216,7 +255,7 @@
 			}
 
 			// We only want to create a full node for nodes that are POI's
-			// and not just one point of a way.  Only create if it has tags that
+			// and not just one point of a way. Only create if it has tags that
 			// could be used in a POI.
 			key = keepTag(key, val);
 			if (key != null) {
@@ -232,8 +271,11 @@
 
 	/**
 	 * A new tag has been started while we are inside a way element.
-	 * @param qName The new tag name.
-	 * @param attributes Its attributes.
+	 * 
+	 * @param qName
+	 *            The new tag name.
+	 * @param attributes
+	 *            Its attributes.
 	 */
 	private void startInWay(String qName, Attributes attributes) {
 		if (qName.equals("nd")) {
@@ -241,7 +283,7 @@
 			addCoordToWay(id);
 		} else if (qName.equals("tag")) {
 			String key = attributes.getValue("k");
-			String val = attributes.getValue("v");
+			String val = replace(attributes.getValue("v"));
 			key = keepTag(key, val);
 			if (key != null)
 				currentWay.addTag(key, val);
@@ -250,39 +292,44 @@
 
 	/**
 	 * A new tag has been started while we are inside the relation tag.
-	 * @param qName The new tag name.
-	 * @param attributes Its attributes.
+	 * 
+	 * @param qName
+	 *            The new tag name.
+	 * @param attributes
+	 *            Its attributes.
 	 */
 	private void startInRelation(String qName, Attributes attributes) {
 		if (qName.equals("member")) {
 			long id = idVal(attributes.getValue("ref"));
 			Element el;
 			String type = attributes.getValue("type");
-			if ("way".equals(type)){
+			if ("way".equals(type)) {
 				el = saver.getWay(id);
 			} else if ("node".equals(type)) {
 				el = saver.getNode(id);
-				if(el == null) {
+				if (el == null) {
 					// we didn't make a node for this point earlier,
 					// do it now (if it exists)
 					Coord co = saver.getCoord(id);
-					if(co != null) {
+					if (co != null) {
 						el = new Node(id, co);
-						saver.addNode((Node)el);
+						saver.addNode((Node) el);
 					}
 				}
 			} else if ("relation".equals(type)) {
 				el = saver.getRelation(id);
 				if (el == null) {
-					saver.deferRelation(id, currentRelation, attributes.getValue("role"));
+					saver.deferRelation(id, currentRelation,
+							attributes.getValue("role"));
 				}
 			} else
 				el = null;
-			if (el != null) // ignore non existing ways caused by splitting files
+			if (el != null) // ignore non existing ways caused by splitting
+							// files
 				currentRelation.addElement(attributes.getValue("role"), el);
 		} else if (qName.equals("tag")) {
 			String key = attributes.getValue("k");
-			String val = attributes.getValue("v");
+			String val = replace(attributes.getValue("v"));
 			key = keepTag(key, val);
 			if (key != null)
 				currentRelation.addTag(key, val);
@@ -290,10 +337,12 @@
 	}
 
 	/**
-	 * Set a bounding box from the bounds element.
-	 * There are two ways of specifying a bounding box in the XML format, this
-	 * one uses attributes of the element to give the bounds.
-	 * @param xmlattr The bounds element attributes.
+	 * Set a bounding box from the bounds element. There are two ways of
+	 * specifying a bounding box in the XML format, this one uses attributes of
+	 * the element to give the bounds.
+	 * 
+	 * @param xmlattr
+	 *            The bounds element attributes.
 	 */
 	private void setupBBoxFromBounds(Attributes xmlattr) {
 		try {
@@ -308,10 +357,12 @@
 	}
 
 	/**
-	 * Set a bounding box from the bound element.  There are two ways of
-	 * specifying a bounding box, this one has a single 'box' attribute that
-	 * is a comma separated list of the bounds values.
-	 * @param box The value of the box attribute.
+	 * Set a bounding box from the bound element. There are two ways of
+	 * specifying a bounding box, this one has a single 'box' attribute that is
+	 * a comma separated list of the bounds values.
+	 * 
+	 * @param box
+	 *            The value of the box attribute.
 	 */
 	private void setupBBoxFromBound(String box) {
 		String[] f = box.split(",");
@@ -325,20 +376,24 @@
 	}
 
 	/**
-	 * Save node information.  Consists of a location specified by lat/long.
-	 *
-	 * @param sid The id as a string.
-	 * @param slat The lat as a string.
-	 * @param slon The longitude as a string.
+	 * Save node information. Consists of a location specified by lat/long.
+	 * 
+	 * @param sid
+	 *            The id as a string.
+	 * @param slat
+	 *            The lat as a string.
+	 * @param slon
+	 *            The longitude as a string.
 	 */
 	private void startNode(String sid, String slat, String slon) {
 		if (sid == null || slat == null || slon == null)
 			return;
-		
+
 		try {
 			long id = idVal(sid);
 
-			Coord co = new Coord(Double.parseDouble(slat), Double.parseDouble(slon));
+			Coord co = new Coord(Double.parseDouble(slat),
+					Double.parseDouble(slon));
 			saver.addPoint(id, co);
 			currentElementId = id;
 		} catch (NumberFormatException e) {
@@ -348,7 +403,9 @@
 
 	/**
 	 * A new way element has been seen.
-	 * @param sid The way id as a string.
+	 * 
+	 * @param sid
+	 *            The way id as a string.
 	 */
 	private void startWay(String sid) {
 		try {
@@ -361,7 +418,9 @@
 
 	/**
 	 * Add a coordinate point to the way.
-	 * @param id The coordinate id.
+	 * 
+	 * @param id
+	 *            The coordinate id.
 	 */
 	private void addCoordToWay(long id) {
 		Coord co = saver.getCoord(id);
@@ -373,8 +432,9 @@
 
 			// nodes (way joins) will have highwayCount > 1
 			co.incHighwayCount();
-		} else if(reportUndefinedNodes && currentWay != null) {
-			log.warn("Way", currentWay.toBrowseURL(), "references undefined node", id);
+		} else if (reportUndefinedNodes && currentWay != null) {
+			log.warn("Way", currentWay.toBrowseURL(),
+					"references undefined node", id);
 		}
 	}
 }
_______________________________________________
mkgmap-dev mailing list
mkgmap-dev@lists.mkgmap.org.uk
http://www.mkgmap.org.uk/mailman/listinfo/mkgmap-dev

Reply via email to