Merge remote-tracking branch 'origin/master'

This commit is contained in:
Weblate 2015-07-09 14:21:44 +02:00
commit 1254a9459d
9 changed files with 259 additions and 68 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.origin3.obf"
});
} else {
in.inspector(args);

View file

@ -364,6 +364,7 @@ public class OsmandRegions {
quadTree = new QuadTree<String>(new QuadRect(0, 0, Integer.MAX_VALUE, Integer.MAX_VALUE),
8, 0.55f);
final ResultMatcher<BinaryMapDataObject> resultMatcher = new ResultMatcher<BinaryMapDataObject>() {
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<BinaryMapDataObject> ls = new LinkedList<BinaryMapDataObject>();
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");

View file

@ -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<String, String> getAmenityAdditionalInfo(Map<String, String> tags, AmenityType type, String subtype) {
TODO;
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){
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;
}
}

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,47 @@ 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);
}
return am;
}
public static Amenity parseAmenity(Entity entity, Map<String, String> 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);
}
@ -143,8 +162,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 +174,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://")) {
@ -169,23 +188,45 @@ public class EntityParser {
return siteUrl;
}
public static List<Amenity> parseAmenities(MapRenderingTypes renderingTypes,
MapPoiTypes poiTypes, Entity entity, List<Amenity> amenitiesList){
public static List<Amenity> parseAmenities(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()) {
boolean purerelation = relation && !"multipolygon".equals(tags.get("type"));
boolean hasName = !Algorithms.isEmpty(tags.get("name"));
for (Map.Entry<String, String> 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<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, pc, subtype, tags, renderingTypes);
Amenity a = parseAmenity(entity, stags, pc, subtype, renderingTypes);
if (checkAmenitiesToAdd(a, amenitiesList) && !"no".equals(subtype)) {
amenitiesList.add(a);
}
@ -209,18 +250,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 +269,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 +279,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

@ -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<LatLon> list = new ArrayList<LatLon>();
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<Node> nodes) {
public static LatLon getWeightCenterForNodes(Collection<Node> 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<Node> nodes = w.getNodes();
if (nodes.isEmpty()) {
return null;
}
boolean area = w.getFirstNodeId() == w.getLastNodeId();
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) {
flat = n.getLatitude();
flon = n.getLongitude();
minDistance = d;
}
}
}
}
return new LatLon(flat, flon);
}
public static LatLon getMathWeightCenterForNodes(Collection<Node> nodes) {
if (nodes.isEmpty()) {

View file

@ -178,7 +178,7 @@ public class Way extends Entity {
if(nodes == null){
return null;
}
return OsmMapUtils.getWeightCenterForNodes(nodes);
return OsmMapUtils.getWeightCenterForWay(this);
}

View file

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

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