Remove deprecated poi parser

This commit is contained in:
Victor Shcherb 2015-10-15 01:29:13 +02:00
parent ac0bfb51e3
commit cbd7f07508
3 changed files with 18 additions and 224 deletions

View file

@ -66,8 +66,8 @@ public class BinaryInspector {
// test cases show info
if(args.length == 1 && "test".equals(args[0])) {
in.inspector(new String[]{
"-vpoi",
// "-vmap","-vmapobjects", // "-vmapcoordinates",
// "-vpoi",
"-vmap","-vmapobjects", // "-vmapcoordinates",
// "-vrouting",
// "-vaddress", "-vcities",//"-vstreetgroups",
// "-vstreets", "-vbuildings", "-vintersections",

View file

@ -7,18 +7,12 @@ import java.util.ArrayList;
import java.util.Collection;
import java.util.Collections;
import java.util.HashMap;
import java.util.HashSet;
import java.util.Iterator;
import java.util.LinkedHashMap;
import java.util.List;
import java.util.Map;
import java.util.Map.Entry;
import java.util.Set;
import java.util.TreeMap;
import net.osmand.PlatformUtil;
import net.osmand.data.AmenityType;
import net.osmand.osm.edit.OSMSettings.OSMTagKey;
import net.osmand.util.Algorithms;
import org.apache.commons.logging.Log;
@ -28,7 +22,7 @@ import org.xmlpull.v1.XmlPullParserException;
/**
* reference : http://wiki.openstreetmap.org/wiki/Map_Features
*/
public class MapRenderingTypes {
public abstract class MapRenderingTypes {
private static final Log log = PlatformUtil.getLog(MapRenderingTypes.class);
public static final String[] langs = new String[] { "af", "ar", "az", "be", "bg", "bn", "bpy", "br", "bs", "ca", "ceb", "cs", "cy", "da", "de", "el", "eo", "es", "et", "eu", "id", "fa", "fi", "fr", "fy", "ga", "gl", "he", "hi",
@ -56,15 +50,6 @@ public class MapRenderingTypes {
this.resourceName = fileName;
}
private static MapRenderingTypes DEFAULT_INSTANCE = null;
public static MapRenderingTypes getDefault() {
if(DEFAULT_INSTANCE == null){
DEFAULT_INSTANCE = new MapRenderingTypes(null);
}
return DEFAULT_INSTANCE;
}
public Map<String, MapRulType> getEncodingRuleTypes(){
checkIfInitNeeded();
return types;
@ -160,9 +145,6 @@ public class MapRenderingTypes {
return typeList.get(id);
}
public MapRulType getAmenityRuleType(String tag, String val) {
return getRuleType(tag, val, true);
}
private String lc(String a) {
if(a != null) {
@ -186,13 +168,9 @@ public class MapRenderingTypes {
rType = MapRulType.createAdditional(tag, val);
rType.additional = true;
rType.order = parent.order;
rType.onlyMap = parent.onlyMap;
rType.onlyPoi = parent.onlyPoi;
rType.map = parent.map;
rType.poi = parent.poi;
rType.onlyPoint = parent.onlyPoint;
rType.poiSpecified = parent.poiSpecified;
rType.poiCategory = parent.poiCategory;
rType.poiPrefix = parent.poiPrefix;
rType.poiWithNameOnly = parent.poiWithNameOnly;
rType.namePrefix = parent.namePrefix;
rType = registerRuleType(rType);
}
@ -209,81 +187,6 @@ public class MapRenderingTypes {
return nameEnRuleType;
}
public Map<String, String> getAmenityAdditionalInfo(Map<String, String> tags, AmenityType type, String subtype) {
Map<String, String> map = new LinkedHashMap<String, String>();
for (String tag : tags.keySet()) {
String val = tags.get(tag);
MapRulType rType = getAmenityRuleType(tag, val);
if (rType != null && val != null && val.length() > 0) {
if(rType == nameEnRuleType && Algorithms.objectEquals(val, tags.get(OSMTagKey.NAME))) {
continue;
}
if (rType.isAdditionalOrText()) {
if (!rType.isText() && !Algorithms.isEmpty(rType.tagValuePattern.value)) {
val = rType.tagValuePattern.value;
}
map.put(rType.tagValuePattern.tag, val);
}
}
}
return map;
}
public String getAmenitySubtype(String tag, String val){
String prefix = getAmenitySubtypePrefix(tag, val);
if(prefix != null){
return prefix + val;
}
return val;
}
public String getAmenitySubtypePrefix(String tag, String val){
Map<String, MapRulType> rules = getEncodingRuleTypes();
MapRulType rt = rules.get(constructRuleKey(tag, val));
if(rt != null && rt.poiPrefix != null && rt.isPOI()) {
return rt.poiPrefix;
}
rt = rules.get(constructRuleKey(tag, null));
if(rt != null && rt.poiPrefix != null && rt.isPOI()) {
return rt.poiPrefix;
}
return null;
}
public AmenityType getAmenityType(String tag, String val, boolean hasName){
return getAmenityType(tag, val, false, hasName);
}
public AmenityType getAmenityTypeForRelation(String tag, String val, boolean hasName){
return getAmenityType(tag, val, true, hasName);
}
private AmenityType getAmenityType(String tag, String val, boolean relation, boolean hasName){
// register amenity types
Map<String, MapRulType> rules = getEncodingRuleTypes();
MapRulType rt = rules.get(constructRuleKey(tag, val));
if(rt != null && rt.isPOISpecified()) {
if((relation && !rt.relation) || rt.isAdditionalOrText()) {
return null;
}
if(rt.poiWithNameOnly && !hasName) {
return null;
}
return rt.poiCategory;
}
rt = rules.get(constructRuleKey(tag, null));
if(rt != null && rt.isPOISpecified()) {
if((relation && !rt.relation) || rt.isAdditionalOrText()) {
return null;
}
if(rt.poiWithNameOnly && !hasName) {
return null;
}
return rt.poiCategory;
}
return null;
}
protected void init(){
InputStream is;
@ -329,24 +232,13 @@ public class MapRenderingTypes {
}
}
protected void parseEntityConvertXML(XmlPullParser parser) {
protected abstract void parseEntityConvertXML(XmlPullParser parser);
}
protected abstract void parseRouteTagFromXML(XmlPullParser parser);
protected void parseRouteTagFromXML(XmlPullParser parser) {
}
protected abstract void parseAndRegisterTypeFromXML(XmlPullParser parser, MapRulType parentCategory) ;
protected void parseAndRegisterTypeFromXML(XmlPullParser parser, MapRulType parentCategory) {
parseBaseRuleType(parser, parentCategory, true);
}
protected MapRulType parseBaseRuleType(XmlPullParser parser, MapRulType parentCategory, boolean filterOnlyMap) {
String tag = lc(parser.getAttributeValue("", "tag"));
return parseBaseRuleType(parser, parentCategory, filterOnlyMap, tag);
}
protected MapRulType parseBaseRuleType(XmlPullParser parser, MapRulType parentCategory, boolean filterOnlyMap,
String tag) {
protected MapRulType parseBaseRuleType(XmlPullParser parser, MapRulType parentCategory, String tag) {
String value = lc(parser.getAttributeValue("", "value"));
String additional = parser.getAttributeValue("", "additional");
if (value != null && value.length() == 0) { //$NON-NLS-1$
@ -358,10 +250,10 @@ public class MapRenderingTypes {
} else if("text".equals(additional)) {
rtype = MapRulType.createText(tag);
}
rtype.onlyMap = "true".equals(parser.getAttributeValue("", "only_map"));
if(filterOnlyMap && rtype.onlyMap) {
return null;
}
rtype.map = "true".equals(parser.getAttributeValue("", "map")) ||
"yes".equals(parser.getAttributeValue("", "map")) || parser.getAttributeValue("", "map") == null;
rtype.poi = "true".equals(parser.getAttributeValue("", "poi")) ||
"yes".equals(parser.getAttributeValue("", "poi")) || parser.getAttributeValue("", "poi") == null;
String order = parser.getAttributeValue("", "order");
if(!Algorithms.isEmpty(order)) {
@ -369,38 +261,7 @@ public class MapRenderingTypes {
} else if (parentCategory != null) {
rtype.order = parentCategory.order;
}
if(!rtype.onlyMap) {
rtype = registerRuleType(rtype);
}
rtype.category = parentCategory == null ? null : parentCategory.category;
if (parentCategory != null) {
if (parentCategory.poiCategory != null) {
rtype.poiCategory = parentCategory.poiCategory;
rtype.poiSpecified = true;
}
rtype.poiPrefix = parentCategory.poiPrefix;
rtype.poiWithNameOnly = parentCategory.poiWithNameOnly;
}
String poiCategory = parser.getAttributeValue("", "poi_category");
if (poiCategory != null) {
rtype.poiSpecified = true;
if (poiCategory.length() == 0) {
rtype.poiCategory = null;
} else {
rtype.poiCategory = AmenityType.getAndRegisterType(poiCategory);
}
}
String poiWithName = parser.getAttributeValue("", "poi_with_name");
if (poiWithName != null) {
rtype.poiWithNameOnly = Boolean.parseBoolean(poiWithName);
}
String poiPrefix = parser.getAttributeValue("", "poi_prefix");
if (poiPrefix != null) {
rtype.poiPrefix = poiPrefix;
}
rtype.onlyPoint = Boolean.parseBoolean(parser.getAttributeValue("", "point")); //$NON-NLS-1$
rtype.relation = Boolean.parseBoolean(parser.getAttributeValue("", "relation")); //$NON-NLS-1$
if (rtype.isMain()) {
@ -460,25 +321,11 @@ public class MapRenderingTypes {
}
protected MapRulType parseCategoryFromXml(XmlPullParser parser) {
String poiTag = parser.getAttributeValue("", "poi_tag");
String poiCategory = parser.getAttributeValue("", "poi_category");
MapRulType rtype = new MapRulType();
rtype.category = parser.getAttributeValue("", "name");
if (!Algorithms.isEmpty(parser.getAttributeValue("", "order"))) {
rtype.order = Integer.parseInt(parser.getAttributeValue("", "order"));
}
if (poiCategory != null && poiCategory.length() > 0) {
rtype.poiCategory = AmenityType.getAndRegisterType(parser.getAttributeValue("", "poi_category"));
rtype.poiSpecified = true;
rtype.relation = Boolean.parseBoolean(parser.getAttributeValue("", "relation"));
rtype.poiWithNameOnly = Boolean.parseBoolean(parser.getAttributeValue("", "poi_with_name"));
rtype.poiPrefix = parser.getAttributeValue("", "poi_prefix");
rtype.onlyPoi = true;
if (poiTag != null) {
rtype.tagValuePattern = new TagValuePattern(poiTag, null);
return registerRuleType(rtype);
}
}
return rtype;
}
@ -572,16 +419,10 @@ public class MapRenderingTypes {
protected int order = 50;
protected String category = null;
protected String poiPrefix;
protected boolean poiWithNameOnly;
protected AmenityType poiCategory;
// poi_category was specially removed for one tag/value, to skip unnecessary objects
protected boolean poiSpecified;
protected boolean relation;
// creation of only section
protected boolean onlyMap;
protected boolean onlyPoi;
protected boolean map = true;
protected boolean poi = true;
// Needed only for map rules
protected int minzoom;
@ -600,15 +441,12 @@ public class MapRenderingTypes {
}
public boolean isPOI(){
return !onlyMap;
return poi;
}
public boolean isPOISpecified() {
return isPOI() && poiSpecified;
}
public boolean isMap(){
return !onlyPoi;
return map;
}
public int getOrder() {

View file

@ -6,7 +6,6 @@ import java.util.List;
import java.util.Map;
import net.osmand.data.Amenity;
import net.osmand.data.AmenityType;
import net.osmand.data.Building;
import net.osmand.data.City;
import net.osmand.data.City.CityType;
@ -15,7 +14,6 @@ import net.osmand.data.MapObject;
import net.osmand.data.TransportStop;
import net.osmand.osm.MapPoiTypes;
import net.osmand.osm.MapRenderingTypes;
import net.osmand.osm.PoiCategory;
import net.osmand.osm.edit.Entity.EntityType;
import net.osmand.osm.edit.OSMSettings.OSMTagKey;
import net.osmand.util.Algorithms;
@ -130,23 +128,6 @@ public class EntityParser {
mo.setName(op);
}
public static Amenity parseAmenity(Entity entity, Map<String, String> tagValues, PoiCategory type, String subtype,
MapRenderingTypes types) {
Amenity am = new Amenity();
parseMapObject(am, entity, tagValues);
am.setType(type);
am.setSubType(subtype);
AmenityType at = AmenityType.findOrCreateTypeNoReg(type.getKeyName());
am.setAdditionalInfo(types.getAmenityAdditionalInfo(tagValues, at, subtype));
String wbs = getWebSiteURL(tagValues);
if(wbs != null) {
am.setAdditionalInfo("website", wbs);
}
return am;
}
private static String getWebSiteURL(Map<String, String> tagValues) {
String siteUrl = tagValues.get(OSMTagKey.WIKIPEDIA.getValue());
@ -200,32 +181,7 @@ public class EntityParser {
return amenitiesList;
}
public static List<Amenity> parseAmenities(MapRenderingTypes renderingTypes,
MapPoiTypes poiTypes, Entity entity, Map<String, String> tags, List<Amenity> amenitiesList){
amenitiesList.clear();
// it could be collection of amenities
boolean relation = entity instanceof Relation;
Collection<Map<String, String>> it = renderingTypes.splitTagsIntoDifferentObjects(tags);
for(Map<String, String> stags : it) {
if (!stags.isEmpty()) {
boolean purerelation = relation && !"multipolygon".equals(stags.get("type"));
boolean hasName = !Algorithms.isEmpty(stags.get("name"));
for (Map.Entry<String, String> e : stags.entrySet()) {
AmenityType type = purerelation ? renderingTypes.getAmenityTypeForRelation(e.getKey(), e.getValue(), hasName)
: renderingTypes.getAmenityType(e.getKey(), e.getValue(), hasName );
if (type != null) {
String subtype = renderingTypes.getAmenitySubtype(e.getKey(), e.getValue());
PoiCategory pc = poiTypes.getPoiCategoryByName(type.getCategoryName(), true);
Amenity a = parseAmenity(entity, stags, pc, subtype, renderingTypes);
if (checkAmenitiesToAdd(a, amenitiesList) && !"no".equals(subtype)) {
amenitiesList.add(a);
}
}
}
}
}
return amenitiesList;
}
private static boolean checkAmenitiesToAdd(Amenity a, List<Amenity> amenitiesList){
// check amenity for duplication