Index: src/uk/me/parabola/mkgmap/reader/osm/xml/Osm5XmlHandler.java =================================================================== --- src/uk/me/parabola/mkgmap/reader/osm/xml/Osm5XmlHandler.java (revision 1457) +++ src/uk/me/parabola/mkgmap/reader/osm/xml/Osm5XmlHandler.java (working copy) @@ -17,12 +17,9 @@ package uk.me.parabola.mkgmap.reader.osm.xml; import java.io.BufferedReader; -import java.io.DataInputStream; -import java.io.FileInputStream; import java.io.FileNotFoundException; -import java.io.InputStreamReader; +import java.io.FileReader; import java.io.IOException; - import java.util.ArrayList; import java.util.HashMap; import java.util.HashSet; @@ -117,7 +114,8 @@ private final Double minimumArcLength; private final String frigRoundabouts; - private HashMap> deletedTags; + private Map> tagBlackList; + private Map> tagWhiteList; public Osm5XmlHandler(EnhancedProperties props) { if(props.getProperty("make-all-cycleways", false)) { @@ -163,9 +161,15 @@ frigRoundabouts = props.getProperty("frig-roundabouts"); ignoreTurnRestrictions = props.getProperty("ignore-turn-restrictions", false); reportUndefinedNodes = props.getProperty("report-undefined-nodes", false); - String deleteTagsFileName = props.getProperty("delete-tags-file"); - if(deleteTagsFileName != null) - readDeleteTagsFile(deleteTagsFileName); + String blacklistTagsFileName = props.getProperty("blacklist-tags-file"); + if (blacklistTagsFileName==null) + // accept the old parameter delete-tags-file + blacklistTagsFileName = props.getProperty("delete-tags-file"); + if(blacklistTagsFileName != null) + tagBlackList = readTagListFile(blacklistTagsFileName); + String whitelistTagsFileName = props.getProperty("whitelist-tags-file"); + if(whitelistTagsFileName != null) + tagWhiteList = readTagListFile(whitelistTagsFileName); if (props.getProperty("preserve-element-order", false)) { nodeMap = new LinkedHashMap(5000); @@ -178,11 +182,12 @@ } } - private void readDeleteTagsFile(String fileName) { + private Map> readTagListFile(String fileName) { + Map> tagList = null; try { - BufferedReader br = new BufferedReader(new InputStreamReader(new DataInputStream(new FileInputStream(fileName)))); + BufferedReader br = new BufferedReader(new FileReader(fileName)); String line; - deletedTags = new HashMap>(); + tagList = new HashMap>(); while((line = br.readLine()) != null) { line = line.trim(); if(line.length() > 0 && @@ -190,20 +195,20 @@ !line.startsWith(";")) { String parts[] = line.split("="); if(parts.length != 2) { - log.error("Ignoring bad line in deleted tags file: " + line); + log.error("Ignoring bad line in tag list file: " + line); } else { parts[0] = parts[0].trim(); parts[1] = parts[1].trim(); if("*".equals(parts[1])) { - deletedTags.put(parts[0], new HashSet()); + tagList.put(parts[0], new HashSet()); } else { - Set vals = deletedTags.get(parts[0]); + Set vals = tagList.get(parts[0]); if(vals == null) vals = new HashSet(); vals.add(parts[1]); - deletedTags.put(parts[0], vals); + tagList.put(parts[0], vals); } } } @@ -211,21 +216,42 @@ br.close(); } catch(FileNotFoundException e) { - log.error("Could not open delete tags file " + fileName); + log.error("Could not open tag list file " + fileName); } catch(IOException e) { - log.error("Error reading delete tags file " + fileName); + log.error("Error reading tag list file " + fileName); } - if(deletedTags != null && deletedTags.size() == 0) - deletedTags = null; + if(tagList != null && tagList.size() == 0) + return null; + else + return tagList; } - private boolean deleteTag(String key, String val) { - if(deletedTags != null) { - Set vals = deletedTags.get(key); + /** + * Checks if the given tag (key=value) should be deleted because of + * the whitelist and the blacklist. + * @param key tag name + * @param val tag value + * @return true if the tag should be deleted + */ + private boolean checkTagDelete(String key, String val) { + // first check if there is a tag whitelist + if (tagWhiteList != null) { + // the tag must be in the whitelist + Set vals = tagWhiteList.get(key); + if(vals == null || (vals.isEmpty() == false && vals.contains(val) == false)) { + // the tag is not in the whitelist => delete it + return true; + } + } + // the tag has passed the whitelist check + // now check if it is in the blacklist + if(tagBlackList != null) { + Set vals = tagBlackList.get(key); if(vals != null && (vals.size() == 0 || vals.contains(val))) { // System.err.println("Deleting " + key + "=" + val); + // it is in the blacklist => delete it return true; } } @@ -317,7 +343,7 @@ } else if (qName.equals("tag")) { String key = attributes.getValue("k"); String val = attributes.getValue("v"); - if(!deleteTag(key, val)) + if(!checkTagDelete(key, val)) currentRelation.addTag(key, val); } } @@ -329,7 +355,7 @@ } else if (qName.equals("tag")) { String key = attributes.getValue("k"); String val = attributes.getValue("v"); - if(!deleteTag(key, val)) + if(!checkTagDelete(key, val)) currentWay.addTag(key, val); } } @@ -339,7 +365,7 @@ String key = attributes.getValue("k"); String val = attributes.getValue("v"); - if(deleteTag(key, val)) + if(checkTagDelete(key, val)) return; // We only want to create a full node for nodes that are POI's Index: resources/help/en/options =================================================================== --- resources/help/en/options (revision 1457) +++ resources/help/en/options (working copy) @@ -346,11 +346,13 @@ access (e.g. bollards). Their access restrictions are applied to a small region of the way near the POI. ---delete-tags-file=FILENAME +--blacklist-tags-file=FILENAME +--whitelist-tags-file=FILENAME Names a file that should contain one or more lines of the form TAG=VALUE or TAG=*. Blank lines and lines that start with # or ; are ignored. All tag/value pairs in the OSM input are - compared with these patterns and those that match are deleted. + compared with these patterns. Those that do not match to the + whitelist or those that match to the blacklist are deleted. --tdbfile Write a .tdb file.