From 1f3e889ec89105cce9974117b426206fd4ab6674 Mon Sep 17 00:00:00 2001 From: Victor Shcherb Date: Tue, 7 Jul 2015 20:58:45 +0300 Subject: [PATCH 1/4] Apply tag/transform for poi --- .../net/osmand/binary/BinaryInspector.java | 14 ++- .../src/net/osmand/osm/edit/EntityParser.java | 102 +++++++++--------- .../osmedit/EditingPOIDialogProvider.java | 2 +- .../plus/osmedit/OpenstreetmapRemoteUtil.java | 5 + 4 files changed, 65 insertions(+), 58 deletions(-) diff --git a/OsmAnd-java/src/net/osmand/binary/BinaryInspector.java b/OsmAnd-java/src/net/osmand/binary/BinaryInspector.java index fcae432fd0..9b138e3599 100644 --- a/OsmAnd-java/src/net/osmand/binary/BinaryInspector.java +++ b/OsmAnd-java/src/net/osmand/binary/BinaryInspector.java @@ -66,17 +66,15 @@ public class BinaryInspector { // test cases show info if(args.length == 1 && "test".equals(args[0])) { in.inspector(new String[]{ - "-vpoi", - "-vmap", "-vmapobjects", +// "-vpoi", +// "-vmap", "-vmapobjects", // "-vrouting", - "-vaddress", "-vcities","-vstreetgroups", - "-vstreets", "-vbuildings", "-vintersections", - "-zoom=16", +// "-vaddress", "-vcities","-vstreetgroups", +// "-vstreets", "-vbuildings", "-vintersections", +// "-zoom=16", // "-bbox=1.74,51.17,1.75,51.16", // "-vstats", - "/Users/victorshcherb/osmand/osm-gen/Map.obf" - - + "/Users/victorshcherb/osmand/osm-gen/Andorra-latest.origin.obf" }); } else { in.inspector(args); diff --git a/OsmAnd-java/src/net/osmand/osm/edit/EntityParser.java b/OsmAnd-java/src/net/osmand/osm/edit/EntityParser.java index 24ceb09c95..bc540bc6a6 100644 --- a/OsmAnd-java/src/net/osmand/osm/edit/EntityParser.java +++ b/OsmAnd-java/src/net/osmand/osm/edit/EntityParser.java @@ -1,34 +1,41 @@ package net.osmand.osm.edit; -import net.osmand.data.*; -import net.osmand.data.City.CityType; -import net.osmand.osm.MapPoiTypes; -import net.osmand.osm.MapRenderingTypes; -import net.osmand.osm.PoiCategory; -import net.osmand.osm.edit.OSMSettings.OSMTagKey; -import net.osmand.util.Algorithms; - import java.util.ArrayList; import java.util.Collection; 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; +import net.osmand.data.LatLon; +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; + public class EntityParser { - public static void parseMapObject(MapObject mo, Entity e) { + public static void parseMapObject(MapObject mo, Entity e, Map tags) { mo.setId(e.getId()); if(mo instanceof Amenity) { - mo.setId((e.getId() << 1) + ((e instanceof Node) ? 0 : 1)); + mo.setId((e.getId() << 1) + ((EntityType.valueOf(e) == EntityType.NODE) ? 0 : 1)); } if (mo.getName().length() == 0) { - mo.setName(e.getTag(OSMTagKey.NAME)); + mo.setName(tags.get(OSMTagKey.NAME.getValue())); } if (mo.getEnName(false).length() == 0) { - mo.setEnName(e.getTag(OSMTagKey.NAME_EN)); + mo.setEnName(tags.get(OSMTagKey.NAME_EN.getValue())); } - for(String ts : e.getTags().keySet()) { + for(String ts : tags.keySet()) { if(ts.startsWith("name:") && !ts.equals(OSMTagKey.NAME_EN.getValue())) { - mo.setName(ts.substring(("name:").length()), e.getTag(ts)); + mo.setName(ts.substring(("name:").length()), tags.get(ts)); } } if (mo.getName().length() == 0) { @@ -47,10 +54,10 @@ public class EntityParser { } } if (mo.getName().length() == 0) { - setNameFromOperator(mo, e); + setNameFromOperator(mo, tags); } if (mo.getName().length() == 0) { - setNameFromRef(mo, e); + setNameFromRef(mo, tags); } } @@ -82,7 +89,7 @@ public class EntityParser { Node lastEntrance = null; for (Node node : nodes) { - String entrance = node.getTag(OSMTagKey.ENTRANCE); + String entrance = node.getTag(OSMTagKey.ENTRANCE.getValue()); if (entrance != null && !"no".equals(entrance)) { if ("main".equals(entrance)) { // main entrance should be only one @@ -106,35 +113,32 @@ public class EntityParser { return null; } - private static void setNameFromRef(MapObject mo, Entity e) { - String ref = e.getTag(OSMTagKey.REF); + private static void setNameFromRef(MapObject mo, Map tags) { + String ref = tags.get(OSMTagKey.REF.getValue()); if(ref != null){ mo.setName(ref); } } - private static void setNameFromOperator(MapObject mo,Entity e) { - String op = e.getTag(OSMTagKey.OPERATOR); + private static void setNameFromOperator(MapObject mo, Map tags) { + String op = tags.get(OSMTagKey.OPERATOR.getValue()); if (op == null) return; - String ref = e.getTag(OSMTagKey.REF); + String ref = tags.get(OSMTagKey.REF.getValue()); if (ref != null) op += " [" + ref + "]"; mo.setName(op); } - public static Amenity parseAmenity(Entity entity, PoiCategory type, String subtype, Map tagValues, + public static Amenity parseAmenity(Entity entity, Map tagValues, PoiCategory type, String subtype, MapRenderingTypes types) { Amenity am = new Amenity(); - parseMapObject(am, entity); - if(tagValues == null) { - tagValues = entity.getTags(); - } + 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(entity); + String wbs = getWebSiteURL(tagValues); if(wbs != null) { am.setAdditionalInfo("website", wbs); } @@ -143,8 +147,8 @@ public class EntityParser { - private static String getWebSiteURL(Entity entity) { - String siteUrl = entity.getTag(OSMTagKey.WIKIPEDIA); + private static String getWebSiteURL(Map tagValues) { + String siteUrl = tagValues.get(OSMTagKey.WIKIPEDIA.getValue()); if (siteUrl != null) { if (!siteUrl.startsWith("http://")) { //$NON-NLS-1$ int i = siteUrl.indexOf(':'); @@ -155,11 +159,11 @@ public class EntityParser { } } } else { - siteUrl = entity.getTag(OSMTagKey.WEBSITE); + siteUrl = tagValues.get(OSMTagKey.WEBSITE.getValue()); if (siteUrl == null) { - siteUrl = entity.getTag(OSMTagKey.URL); + siteUrl = tagValues.get(OSMTagKey.URL.getValue()); if (siteUrl == null) { - siteUrl = entity.getTag(OSMTagKey.CONTACT_WEBSITE); + siteUrl = tagValues.get(OSMTagKey.CONTACT_WEBSITE.getValue()); } } if (siteUrl != null && !siteUrl.startsWith("http://") && !siteUrl.startsWith("https://")) { @@ -170,22 +174,22 @@ public class EntityParser { } public static List parseAmenities(MapRenderingTypes renderingTypes, - MapPoiTypes poiTypes, Entity entity, List amenitiesList){ + MapPoiTypes poiTypes, Entity entity, Map tags, List amenitiesList){ amenitiesList.clear(); // it could be collection of amenities boolean relation = entity instanceof Relation; - Collection> it = renderingTypes.splitTagsIntoDifferentObjects(entity.getTags()); - for(Map tags : it) { - if (!tags.isEmpty()) { - boolean purerelation = relation && !"multipolygon".equals(tags.get("type")); - boolean hasName = !Algorithms.isEmpty(tags.get("name")); - for (Map.Entry e : tags.entrySet()) { + Collection> it = renderingTypes.splitTagsIntoDifferentObjects(tags); + for(Map stags : it) { + if (!stags.isEmpty()) { + boolean purerelation = relation && !"multipolygon".equals(stags.get("type")); + boolean hasName = !Algorithms.isEmpty(stags.get("name")); + for (Map.Entry 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, pc, subtype, tags, renderingTypes); + Amenity a = parseAmenity(entity, stags, pc, subtype, renderingTypes); if (checkAmenitiesToAdd(a, amenitiesList) && !"no".equals(subtype)) { amenitiesList.add(a); } @@ -209,18 +213,18 @@ public class EntityParser { public static Building parseBuilding(Entity e){ Building b = new Building(); - parseMapObject(b, e); + parseMapObject(b, e, e.getTags()); // try to extract postcode - String p = e.getTag(OSMTagKey.ADDR_POSTCODE); + String p = e.getTag(OSMTagKey.ADDR_POSTCODE.getValue()); if(p == null) { - p = e.getTag(OSMTagKey.POSTAL_CODE); + p = e.getTag(OSMTagKey.POSTAL_CODE.getValue()); } b.setPostcode(p); return b; } public static City parseCity(Node el) { - return parseCity(el, CityType.valueFromString(el.getTag(OSMTagKey.PLACE))); + return parseCity(el, CityType.valueFromString(el.getTag(OSMTagKey.PLACE.getValue()))); } public static City parseCity(Entity el, CityType t) { @@ -228,8 +232,8 @@ public class EntityParser { return null; } City c = new City(t); - parseMapObject(c, el); - String isin = el.getTag(OSMTagKey.IS_IN); + parseMapObject(c, el, el.getTags()); + String isin = el.getTag(OSMTagKey.IS_IN.getValue()); isin = isin != null ? isin.toLowerCase() : null; c.setIsin(isin); return c; @@ -238,14 +242,14 @@ public class EntityParser { public static OsmTransportRoute parserRoute(Relation r, String ref){ OsmTransportRoute rt = new OsmTransportRoute(); - parseMapObject(rt, r); + parseMapObject(rt, r, r.getTags()); rt.setRef(ref); return rt; } public static TransportStop parseTransportStop(Entity e){ TransportStop st = new TransportStop(); - parseMapObject(st, e); + parseMapObject(st, e, e.getTags()); return st; } diff --git a/OsmAnd/src/net/osmand/plus/osmedit/EditingPOIDialogProvider.java b/OsmAnd/src/net/osmand/plus/osmedit/EditingPOIDialogProvider.java index 456f0441c7..3f140084f4 100644 --- a/OsmAnd/src/net/osmand/plus/osmedit/EditingPOIDialogProvider.java +++ b/OsmAnd/src/net/osmand/plus/osmedit/EditingPOIDialogProvider.java @@ -153,7 +153,7 @@ public class EditingPOIDialogProvider implements DialogProvider { } private void showPOIDialog(int dialogID, Node n, PoiCategory type, String subType) { - Amenity a = EntityParser.parseAmenity(n, type, subType, null, MapRenderingTypes.getDefault()); + Amenity a = EntityParser.parseAmenity(n, n.getTags(), type, subType, MapRenderingTypes.getDefault()); dialogBundle.putSerializable(KEY_AMENITY, a); dialogBundle.putSerializable(KEY_AMENITY_NODE, n); createPOIDialog(dialogID, dialogBundle).show(); diff --git a/OsmAnd/src/net/osmand/plus/osmedit/OpenstreetmapRemoteUtil.java b/OsmAnd/src/net/osmand/plus/osmedit/OpenstreetmapRemoteUtil.java index 7a4cae0a4d..8e8a90ff47 100644 --- a/OsmAnd/src/net/osmand/plus/osmedit/OpenstreetmapRemoteUtil.java +++ b/OsmAnd/src/net/osmand/plus/osmedit/OpenstreetmapRemoteUtil.java @@ -326,6 +326,11 @@ public class OpenstreetmapRemoteUtil implements OpenstreetmapUtil { n.putTag(rtag, entity.getTag(rtag)); } } + if(MapUtils.getDistance(n.getLatLon(), entity.getLatLon()) < 10) { + // avoid shifting due to round error + n.setLatitude(entity.getLatitude()); + n.setLongitude(entity.getLongitude()); + } entityInfo = st.getRegisteredEntityInfo().get(id); return entityInfo; } From 0c158551f1b12d2485924c309dde715872fa06f6 Mon Sep 17 00:00:00 2001 From: Victor Shcherb Date: Tue, 7 Jul 2015 21:28:17 +0300 Subject: [PATCH 2/4] Fix poi out of its boundaries --- .../src/net/osmand/osm/edit/OsmMapUtils.java | 35 ++++++++++++++- OsmAnd-java/src/net/osmand/osm/edit/Way.java | 2 +- .../src/net/osmand/util/MapAlgorithms.java | 45 +++++++++++++++++++ 3 files changed, 79 insertions(+), 3 deletions(-) diff --git a/OsmAnd-java/src/net/osmand/osm/edit/OsmMapUtils.java b/OsmAnd-java/src/net/osmand/osm/edit/OsmMapUtils.java index 103698823b..bd11e745d9 100644 --- a/OsmAnd-java/src/net/osmand/osm/edit/OsmMapUtils.java +++ b/OsmAnd-java/src/net/osmand/osm/edit/OsmMapUtils.java @@ -7,6 +7,7 @@ import java.util.Comparator; import java.util.List; import net.osmand.data.LatLon; +import net.osmand.util.MapAlgorithms; import net.osmand.util.MapUtils; public class OsmMapUtils { @@ -27,7 +28,7 @@ public class OsmMapUtils { if (e instanceof Node) { return ((Node) e).getLatLon(); } else if (e instanceof Way) { - return getWeightCenterForNodes(((Way) e).getNodes()); + return getWeightCenterForWay(((Way) e)); } else if (e instanceof Relation) { List list = new ArrayList(); for (Entity fe : ((Relation) e).getMembers(null)) { @@ -58,7 +59,7 @@ public class OsmMapUtils { return new LatLon(latitude / nodes.size(), longitude / nodes.size()); } - public static LatLon getWeightCenterForNodes(Collection nodes) { + public static LatLon getWeightCenterForNodes(Collection nodes ) { if (nodes.isEmpty()) { return null; } @@ -77,6 +78,36 @@ public class OsmMapUtils { } return new LatLon(latitude / count, longitude / count); } + + public static LatLon getWeightCenterForWay(Way w) { + Collection nodes = w.getNodes(); + boolean area = w.getFirstNodeId() == w.getLastNodeId(); + if (nodes.isEmpty()) { + return null; + } + LatLon ll = area ? getMathWeightCenterForNodes(nodes) : getWeightCenterForNodes(nodes); + if(ll == null) { + return null; + } + double flat = ll.getLatitude(); + double flon = ll.getLongitude(); + if(!area || !MapAlgorithms.containsPoint(nodes, ll.getLatitude(), ll.getLongitude())) { + double minDistance = Double.MAX_VALUE; + for (Node n : nodes) { + if (n != null) { + double d = MapUtils.getDistance(n.getLatitude(), n.getLongitude(), ll.getLatitude(), ll.getLongitude()); + if(d < minDistance) { + flon = n.getLongitude(); + flat = n.getLatitude(); + minDistance = d; + } + } + } + } + + return new LatLon(flat, flon); + } + public static LatLon getMathWeightCenterForNodes(Collection nodes) { if (nodes.isEmpty()) { diff --git a/OsmAnd-java/src/net/osmand/osm/edit/Way.java b/OsmAnd-java/src/net/osmand/osm/edit/Way.java index 982053a703..882b25cd2e 100644 --- a/OsmAnd-java/src/net/osmand/osm/edit/Way.java +++ b/OsmAnd-java/src/net/osmand/osm/edit/Way.java @@ -178,7 +178,7 @@ public class Way extends Entity { if(nodes == null){ return null; } - return OsmMapUtils.getWeightCenterForNodes(nodes); + return OsmMapUtils.getWeightCenterForWay(this); } diff --git a/OsmAnd-java/src/net/osmand/util/MapAlgorithms.java b/OsmAnd-java/src/net/osmand/util/MapAlgorithms.java index 4de1f17758..44c019b217 100644 --- a/OsmAnd-java/src/net/osmand/util/MapAlgorithms.java +++ b/OsmAnd-java/src/net/osmand/util/MapAlgorithms.java @@ -1,7 +1,12 @@ package net.osmand.util; +import java.util.Collection; +import java.util.List; + import gnu.trove.list.TLongList; import net.osmand.data.LatLon; +import net.osmand.osm.edit.Node; +import net.osmand.osm.edit.OsmMapUtils; public class MapAlgorithms { @@ -285,4 +290,44 @@ public class MapAlgorithms { } return true; } + + public static boolean containsPoint(Collection polyNodes, double latitude, double longitude){ + return countIntersections(polyNodes, latitude, longitude) % 2 == 1; + } + + /** + * count the intersections when going from lat, lon to outside the ring + * @param polyNodes2 + */ + private static int countIntersections(Collection polyNodes, double latitude, double longitude) { + int intersections = 0; + if (polyNodes.size() == 0) return 0; + Node prev = null; + Node first = null; + Node last = null; + for(Node n : polyNodes) { + if(prev == null) { + prev = n; + first = prev; + continue; + } + if(n == null) { + continue; + } + last = n; + if (OsmMapUtils.ray_intersect_lon(prev, + n, latitude, longitude) != -360.0d) { + intersections++; + } + prev = n; + } + // special handling, also count first and last, might not be closed, but + // we want this! + if (OsmMapUtils.ray_intersect_lon(first, + last, latitude, longitude) != -360.0d) { + intersections++; + } + return intersections; + } + } \ No newline at end of file From 21327bb47b1cc607d78b521d3bb253886938a069 Mon Sep 17 00:00:00 2001 From: Victor Shcherb Date: Tue, 7 Jul 2015 21:46:00 +0300 Subject: [PATCH 3/4] Tag/transform routing types --- OsmAnd-java/src/net/osmand/binary/BinaryInspector.java | 2 +- OsmAnd-java/src/net/osmand/osm/edit/OsmMapUtils.java | 4 ++-- 2 files changed, 3 insertions(+), 3 deletions(-) diff --git a/OsmAnd-java/src/net/osmand/binary/BinaryInspector.java b/OsmAnd-java/src/net/osmand/binary/BinaryInspector.java index 9b138e3599..21daf205b9 100644 --- a/OsmAnd-java/src/net/osmand/binary/BinaryInspector.java +++ b/OsmAnd-java/src/net/osmand/binary/BinaryInspector.java @@ -74,7 +74,7 @@ public class BinaryInspector { // "-zoom=16", // "-bbox=1.74,51.17,1.75,51.16", // "-vstats", - "/Users/victorshcherb/osmand/osm-gen/Andorra-latest.origin.obf" + "/Users/victorshcherb/osmand/osm-gen/Andorra-latest.origin3.obf" }); } else { in.inspector(args); diff --git a/OsmAnd-java/src/net/osmand/osm/edit/OsmMapUtils.java b/OsmAnd-java/src/net/osmand/osm/edit/OsmMapUtils.java index bd11e745d9..02c3bc14eb 100644 --- a/OsmAnd-java/src/net/osmand/osm/edit/OsmMapUtils.java +++ b/OsmAnd-java/src/net/osmand/osm/edit/OsmMapUtils.java @@ -81,10 +81,10 @@ public class OsmMapUtils { public static LatLon getWeightCenterForWay(Way w) { Collection nodes = w.getNodes(); - boolean area = w.getFirstNodeId() == w.getLastNodeId(); if (nodes.isEmpty()) { return null; } + boolean area = w.getFirstNodeId() == w.getLastNodeId(); LatLon ll = area ? getMathWeightCenterForNodes(nodes) : getWeightCenterForNodes(nodes); if(ll == null) { return null; @@ -97,8 +97,8 @@ public class OsmMapUtils { if (n != null) { double d = MapUtils.getDistance(n.getLatitude(), n.getLongitude(), ll.getLatitude(), ll.getLongitude()); if(d < minDistance) { - flon = n.getLongitude(); flat = n.getLatitude(); + flon = n.getLongitude(); minDistance = d; } } From 40bc7bf0bb15e360fb8f407c7de55b0912d2c2cf Mon Sep 17 00:00:00 2001 From: Victor Shcherb Date: Thu, 9 Jul 2015 14:14:52 +0200 Subject: [PATCH 4/4] Update poi types with entity convert --- .../src/net/osmand/map/OsmandRegions.java | 16 +++-- .../src/net/osmand/osm/MapPoiTypes.java | 67 ++++++++++++++++++- .../src/net/osmand/osm/edit/EntityParser.java | 37 ++++++++++ 3 files changed, 114 insertions(+), 6 deletions(-) diff --git a/OsmAnd-java/src/net/osmand/map/OsmandRegions.java b/OsmAnd-java/src/net/osmand/map/OsmandRegions.java index 26efd2ceab..65c7007315 100644 --- a/OsmAnd-java/src/net/osmand/map/OsmandRegions.java +++ b/OsmAnd-java/src/net/osmand/map/OsmandRegions.java @@ -364,6 +364,7 @@ public class OsmandRegions { quadTree = new QuadTree(new QuadRect(0, 0, Integer.MAX_VALUE, Integer.MAX_VALUE), 8, 0.55f); final ResultMatcher resultMatcher = new ResultMatcher() { + int c = 0; @Override public boolean publish(BinaryMapDataObject object) { if (object.getPointsLength() < 1) { @@ -371,6 +372,9 @@ public class OsmandRegions { } initTypes(object); String nm = object.getNameByType(downloadNameType); + if(nm != null) { + System.out.println((c++) +" " + nm); + } if (!countriesByDownloadName.containsKey(nm)) { LinkedList ls = new LinkedList(); countriesByDownloadName.put(nm, ls); @@ -449,7 +453,9 @@ public class OsmandRegions { if(nm == null) { nm = b.getName(); } - found.add(nm.toLowerCase()); + if(or.isDownloadOfType(b, MAP_TYPE)) { + found.add(nm.toLowerCase()); + } } if (!found.equals(expected)) { @@ -461,17 +467,17 @@ public class OsmandRegions { public static void main(String[] args) throws IOException { OsmandRegions or = new OsmandRegions(); - or.prepareFile("/home/victor/projects/osmand/repo/resources/countries-info/regions.ocbf"); + or.prepareFile("/Users/victorshcherb/osmand/repos/resources/countries-info/regions.ocbf"); or.cacheAllCountries(); // long t = System.currentTimeMillis(); // or.cacheAllCountries(); // System.out.println("Init " + (System.currentTimeMillis() - t)); //testCountry(or, 15.8, 23.09, "chad"); - testCountry(or, 52.10, 4.92, "the netherlands"); + testCountry(or, 52.10, 4.92, "the netherlands", "utrecht"); testCountry(or, 52.15, 7.50, "north rhine-westphalia"); - testCountry(or, 40.0760, 9.2807, "italy", "sardinia"); - testCountry(or, 28.8056, 29.9858, "africa", "egypt" ); + testCountry(or, 28.8056, 29.9858, "egypt" ); +// testCountry(or, 40.0760, 9.2807, "italy", "sardinia"); testCountry(or, 35.7521, 139.7887, "japan"); testCountry(or, 46.5145, 102.2580, "mongolia"); testCountry(or, 62.54, 43.36, "arkhangelsk oblast", "northwestern federal district"); diff --git a/OsmAnd-java/src/net/osmand/osm/MapPoiTypes.java b/OsmAnd-java/src/net/osmand/osm/MapPoiTypes.java index caa6b37a08..e9eb60956b 100644 --- a/OsmAnd-java/src/net/osmand/osm/MapPoiTypes.java +++ b/OsmAnd-java/src/net/osmand/osm/MapPoiTypes.java @@ -15,6 +15,9 @@ import java.util.TreeMap; import net.osmand.PlatformUtil; import net.osmand.StringMatcher; +import net.osmand.data.AmenityType; +import net.osmand.osm.MapRenderingTypes.MapRulType; +import net.osmand.osm.edit.OSMSettings.OSMTagKey; import net.osmand.util.Algorithms; import org.apache.commons.logging.Log; @@ -432,7 +435,7 @@ public class MapPoiTypes { } } - + public String getTranslation(AbstractPoiType abstractPoiType) { if(poiTranslator != null) { String translation = poiTranslator.getTranslation(abstractPoiType); @@ -447,5 +450,67 @@ public class MapPoiTypes { public boolean isRegisteredType(PoiCategory t) { return getPoiCategoryByName(t.getKeyName()) != otherCategory; } + + public Map getAmenityAdditionalInfo(Map tags, AmenityType type, String subtype) { + TODO; + Map map = new LinkedHashMap(); + 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 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){ + TODO; + return getAmenityType(tag, val, false, hasName); + } + + public AmenityType getAmenityTypeForRelation(String tag, String val, boolean hasName){ + TODO; + return getAmenityType(tag, val, true, hasName); + } + + + public boolean isTextAdditionalInfo(String key, String value) { + if(key.startsWith("name:")) { + return true; + } + TODO; + return true; + } + } diff --git a/OsmAnd-java/src/net/osmand/osm/edit/EntityParser.java b/OsmAnd-java/src/net/osmand/osm/edit/EntityParser.java index bc540bc6a6..e5c5e1c67d 100644 --- a/OsmAnd-java/src/net/osmand/osm/edit/EntityParser.java +++ b/OsmAnd-java/src/net/osmand/osm/edit/EntityParser.java @@ -144,6 +144,21 @@ public class EntityParser { } return am; } + + public static Amenity parseAmenity(Entity entity, Map tagValues, PoiCategory type, String subtype, + MapPoiTypes 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; + } @@ -173,6 +188,28 @@ public class EntityParser { return siteUrl; } + + public static List parseAmenities(MapPoiTypes poiTypes, Entity entity, Map tags,List amenitiesList) { + amenitiesList.clear(); + // it could be collection of amenities + boolean relation = entity instanceof Relation; + boolean purerelation = relation && !"multipolygon".equals(tags.get("type")); + boolean hasName = !Algorithms.isEmpty(tags.get("name")); + for (Map.Entry e : tags.entrySet()) { + AmenityType type = purerelation ? poiTypes.getAmenityTypeForRelation(e.getKey(), e.getValue(), hasName) + : poiTypes.getAmenityType(e.getKey(), e.getValue(), hasName); + if (type != null) { + String subtype = poiTypes.getAmenitySubtype(e.getKey(), e.getValue()); + PoiCategory pc = poiTypes.getPoiCategoryByName(type.getCategoryName(), true); + Amenity a = parseAmenity(entity, tags, pc, subtype, poiTypes); + if (checkAmenitiesToAdd(a, amenitiesList) && !"no".equals(subtype)) { + amenitiesList.add(a); + } + } + } + return amenitiesList; + } + public static List parseAmenities(MapRenderingTypes renderingTypes, MapPoiTypes poiTypes, Entity entity, Map tags, List amenitiesList){ amenitiesList.clear();