Fix open sea maps creator

This commit is contained in:
vshcherb 2013-12-01 17:08:52 +01:00
parent 9e6b9560dc
commit a1ed8cabbf
4 changed files with 28 additions and 38 deletions

View file

@ -56,11 +56,11 @@ public class BinaryInspector {
in.inspector(args); in.inspector(args);
// test cases show info // test cases show info
/*in.inspector(new String[]{ /*in.inspector(new String[]{
"-vpoi", //"-vpoi",
//"-vmap", "-vmapobjects", "-vmap", "-vmapobjects",
//"-vstreets", //"-vstreets",
"-bbox=4,55,7,50", "-bbox=4,55,7,50",
"/home/victor/projects/osmand/osm-gen/World_sea_map.obf"});*/ "/home/victor/projects/osmand/osm-gen/World_seamarks_2.obf"});*/
} }
private void printToFile(String s) throws IOException { private void printToFile(String s) throws IOException {

View file

@ -12,13 +12,12 @@ import java.util.Iterator;
import java.util.LinkedHashMap; import java.util.LinkedHashMap;
import java.util.List; import java.util.List;
import java.util.Map; import java.util.Map;
import java.util.Set;
import java.util.Map.Entry; import java.util.Map.Entry;
import java.util.Set;
import java.util.TreeMap; import java.util.TreeMap;
import net.osmand.PlatformUtil; import net.osmand.PlatformUtil;
import net.osmand.data.AmenityType; import net.osmand.data.AmenityType;
import net.osmand.osm.edit.Entity;
import net.osmand.osm.edit.OSMSettings.OSMTagKey; import net.osmand.osm.edit.OSMSettings.OSMTagKey;
import net.osmand.util.Algorithms; import net.osmand.util.Algorithms;
@ -133,8 +132,17 @@ public class MapRenderingTypes {
return amenityTypeNameToTagVal; return amenityTypeNameToTagVal;
} }
public Iterator<Map<String, String>> splitTagsIntoDifferentObjects(final Map<String, String> tags) { public Collection<Map<String, String>> splitTagsIntoDifferentObjects(final Map<String, String> tags) {
// check open sea maps tags // check open sea maps tags
boolean split = splitIsNeeded(tags);
if(!split) {
return Collections.singleton(tags);
} else {
return splitOpenSeaMapsTags(tags);
}
}
protected boolean splitIsNeeded(final Map<String, String> tags) {
boolean seamark = false; boolean seamark = false;
for(String s : tags.keySet()) { for(String s : tags.keySet()) {
if(s.startsWith("seamark:")) { if(s.startsWith("seamark:")) {
@ -142,35 +150,10 @@ public class MapRenderingTypes {
break; break;
} }
} }
if(!seamark) { return seamark;
return oneIterator(tags);
} else {
return splitOpenSeaMapsTags(tags);
}
} }
private <T> Iterator<T> oneIterator(final T obj) { private Collection<Map<String, String>> splitOpenSeaMapsTags(final Map<String, String> tags) {
return new Iterator<T>() {
boolean hasNext = true;
@Override
public void remove() {
throw new UnsupportedOperationException();
}
@Override
public T next() {
hasNext = false;
return obj;
}
@Override
public boolean hasNext() {
return hasNext;
}
};
}
private Iterator<Map<String, String>> splitOpenSeaMapsTags(final Map<String, String> tags) {
Map<String, Map<String, String>> groupByOpenSeamaps = new HashMap<String, Map<String, String>>(); Map<String, Map<String, String>> groupByOpenSeamaps = new HashMap<String, Map<String, String>>();
Map<String, String> common = new HashMap<String, String>(); Map<String, String> common = new HashMap<String, String>();
String ATTACHED_KEY = "seamark:attached"; String ATTACHED_KEY = "seamark:attached";
@ -197,15 +180,19 @@ public class MapRenderingTypes {
common.put(s, value); common.put(s, value);
} }
} }
List<Map<String, String>> res = new ArrayList<Map<String,String>>();
for (Entry<String, Map<String, String>> g : groupByOpenSeamaps.entrySet()) { for (Entry<String, Map<String, String>> g : groupByOpenSeamaps.entrySet()) {
g.getValue().putAll(common); g.getValue().putAll(common);
g.getValue().put("seamark", g.getKey()); g.getValue().put("seamark", g.getKey());
if (openSeaType(type).equals(g.getKey())) { if (openSeaType(type).equals(g.getKey())) {
g.getValue().remove(ATTACHED_KEY); g.getValue().remove(ATTACHED_KEY);
g.getValue().put("seamark", type); g.getValue().put("seamark", type);
res.add(0, g.getValue());
} else {
res.add(g.getValue());
} }
} }
return groupByOpenSeamaps.values().iterator(); return res;
} }

View file

@ -142,6 +142,10 @@ public abstract class Entity {
return tags.put(key, value); return tags.put(key, value);
} }
public void replaceTags(Map<String, String> toPut){
tags = new LinkedHashMap<String, String>(toPut);
}
public String getTag(OSMTagKey key){ public String getTag(OSMTagKey key){
return getTag(key.getValue()); return getTag(key.getValue());
} }

View file

@ -1,6 +1,6 @@
package net.osmand.osm.edit; package net.osmand.osm.edit;
import java.util.Iterator; import java.util.Collection;
import java.util.List; import java.util.List;
import java.util.Map; import java.util.Map;
@ -110,9 +110,8 @@ public class EntityParser {
amenitiesList.clear(); amenitiesList.clear();
// it could be collection of amenities // it could be collection of amenities
boolean relation = entity instanceof Relation; boolean relation = entity instanceof Relation;
Iterator<Map<String, String>> it = renderingTypes.splitTagsIntoDifferentObjects(entity.getTags()); Collection<Map<String, String>> it = renderingTypes.splitTagsIntoDifferentObjects(entity.getTags());
while (it.hasNext()) { for(Map<String, String> tags : it) {
Map<String, String> tags = it.next();
if (!tags.isEmpty()) { if (!tags.isEmpty()) {
boolean purerelation = relation && !"multipolygon".equals(tags.get("type")); boolean purerelation = relation && !"multipolygon".equals(tags.get("type"));
for (Map.Entry<String, String> e : tags.entrySet()) { for (Map.Entry<String, String> e : tags.entrySet()) {