Apply tag/transform for poi

This commit is contained in:
Victor Shcherb 2015-07-07 20:58:45 +03:00
parent fcc68e2a14
commit 1f3e889ec8
4 changed files with 65 additions and 58 deletions

View file

@ -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);

View file

@ -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<String, String> 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<String, String> 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<String, String> 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<String, String> tagValues,
public static Amenity parseAmenity(Entity entity, Map<String, String> 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<String, String> 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<Amenity> parseAmenities(MapRenderingTypes renderingTypes,
MapPoiTypes poiTypes, Entity entity, List<Amenity> amenitiesList){
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(entity.getTags());
for(Map<String, String> tags : it) {
if (!tags.isEmpty()) {
boolean purerelation = relation && !"multipolygon".equals(tags.get("type"));
boolean hasName = !Algorithms.isEmpty(tags.get("name"));
for (Map.Entry<String, String> e : tags.entrySet()) {
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, 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;
}

View file

@ -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();

View file

@ -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;
}