filter tags for default locale, cleanups

This commit is contained in:
Hannes Janetzek 2013-05-16 22:19:23 +02:00
parent 77733ed593
commit c966f59d37

View File

@ -25,6 +25,7 @@ import org.oscim.core.GeoPoint;
import org.oscim.core.GeometryBuffer.GeometryType; import org.oscim.core.GeometryBuffer.GeometryType;
import org.oscim.core.MapElement; import org.oscim.core.MapElement;
import org.oscim.core.Tag; import org.oscim.core.Tag;
import org.oscim.core.TagSet;
import org.oscim.core.Tile; import org.oscim.core.Tile;
import org.oscim.database.IMapDatabase; import org.oscim.database.IMapDatabase;
import org.oscim.database.IMapDatabaseCallback; import org.oscim.database.IMapDatabaseCallback;
@ -60,6 +61,7 @@ public class MapDatabase implements IMapDatabase {
private LwHttp lwHttp; private LwHttp lwHttp;
private final UTF8Decoder mStringDecoder; private final UTF8Decoder mStringDecoder;
private final String mLocale = "de";
//private final MapElement mElem; //private final MapElement mElem;
@ -182,20 +184,9 @@ public class MapDatabase implements IMapDatabase {
private static final int TAG_GEOM_LINE = 2; private static final int TAG_GEOM_LINE = 2;
private static final int TAG_GEOM_POLYGON = 3; private static final int TAG_GEOM_POLYGON = 3;
//rivate final short[] mTmpKeys = new short[100];
//private final Tag[] mTmpTags = new Tag[20];
//private Tag[][] mElementTags;
private short[] mTmpTags = new short[1024]; private short[] mTmpTags = new short[1024];
//private final short[] mPrevTags = new short[1024];
private void initDecorder() { private void initDecorder() {
// reusable tag set
// Tag[][] tags = new Tag[10][];
// for (int i = 0; i < 10; i++)
// tags[i] = new Tag[i + 1];
//mElementTags = tags;
} }
private boolean decode() throws IOException { private boolean decode() throws IOException {
@ -274,62 +265,82 @@ public class MapDatabase implements IMapDatabase {
} }
} }
boolean isRoad = "road".equals(name);
boolean isBridge = "bridge".equals(name);
boolean isTunnel = "tunnel".equals(name);
boolean isBuilding = "building".equals(name);
boolean isLanduse = "landuse".equals(name);
boolean isWater = "water".equals(name);
Tag layerTag = new Tag(name, Tag.VALUE_YES); Tag layerTag = new Tag(name, Tag.VALUE_YES);
if (numFeatures == 0) if (numFeatures == 0)
return true; return true;
int[] ignoreLocal = new int[20];
int numIgnore = 0;
int fallBackLocal = -1;
int matchedLocal = -1;
for (int i = 0; i < keys.size(); i++) {
String key = keys.get(i);
if (!key.startsWith(Tag.TAG_KEY_NAME))
continue;
int len = key.length();
if (len == 4) {
fallBackLocal = i;
continue;
}
if (len < 7) {
ignoreLocal[numIgnore++] = i;
continue;
}
if (mLocale.equals(key.substring(5))) {
//Log.d(TAG, "found local " + key);
matchedLocal = i;
} else
ignoreLocal[numIgnore++] = i;
}
for (Feature f : features) { for (Feature f : features) {
int addTags = 0; //Log.d(TAG, "geom: " + f.elem.type + " " + f.elem.pointPos + " tags:" + f.numTags + " "
if (isBuilding || isWater) // + name);
addTags = 1;
Tag[] tags = new Tag[f.numTags + addTags]; if (f.elem.type == GeometryType.NONE)
if (isBuilding)
tags[tags.length - 1] = BUILDING_TAG;
if (isWater)
tags[tags.length - 1] = WATER_TAG;
if (tags.length == 0)
continue; continue;
for (int j = 0; j < (f.numTags << 1); j += 2) { mTagSet.clear();
mTagSet.add(layerTag);
String key = keys.get(f.tags[j]); boolean hasName = false;
String fallbackName = null;
tagLoop: for (int j = 0; j < (f.numTags << 1); j += 2) {
int keyIdx = f.tags[j];
for (int i = 0; i < numIgnore; i++)
if (keyIdx == ignoreLocal[i])
continue tagLoop;
if (keyIdx == fallBackLocal) {
fallbackName = values.get(f.tags[j + 1]);
continue;
}
String key;
String val = values.get(f.tags[j + 1]); String val = values.get(f.tags[j + 1]);
Tag tag = null; if (keyIdx == matchedLocal) {
if ("class".equals(key)) { hasName = true;
if (isRoad || isTunnel || isBridge) { mTagSet.add(new Tag(Tag.TAG_KEY_NAME, val, false));
if ("street".equals(val))
tag = HIGHWAY_STREET_TAG;
else if ("main".equals(val))
tag = HIGHWAY_MAIN_TAG;
else if ("major".equals(val))
tag = HIGHWAY_MAJOR_TAG;
else if ("major_rail".equals(val))
tag = HIGHWAY_RAIL_TAG;
else
tag = new Tag(Tag.TAG_KEY_HIGHWAY, val);
} else if (isLanduse) } else {
tag = new Tag(Tag.TAG_KEY_LANDUSE, val); key = keys.get(keyIdx);
mTagSet.add(new Tag(key, val));
} }
if (tag == null)
tag = new Tag(key, val);
tags[j >> 1] = tag;
} }
f.elem.set(tags, 5); if (!hasName && fallbackName != null)
mTagSet.add(new Tag(Tag.TAG_KEY_NAME, fallbackName, false));
// FIXME extract layer tag here
f.elem.set(mTagSet.asArray(), 5);
mMapGenerator.renderElement(f.elem); mMapGenerator.renderElement(f.elem);
mFeaturePool.release(f); mFeaturePool.release(f);
} }
@ -337,6 +348,7 @@ public class MapDatabase implements IMapDatabase {
return true; return true;
} }
private final TagSet mTagSet = new TagSet();
private final Pool<Feature> mFeaturePool = new Pool<Feature>() { private final Pool<Feature> mFeaturePool = new Pool<Feature>() {
int count; int count;
@ -348,7 +360,7 @@ public class MapDatabase implements IMapDatabase {
@Override @Override
protected boolean clearItem(Feature item) { protected boolean clearItem(Feature item) {
if (count > 50) { if (count > 100) {
count--; count--;
return false; return false;
} }
@ -363,17 +375,6 @@ public class MapDatabase implements IMapDatabase {
} }
}; };
private final static Tag WATER_TAG = new Tag("natural", "water");
private final static Tag BUILDING_TAG = new Tag("building", "yes");
private final static Tag HIGHWAY_MAIN_TAG = new Tag("highway", "secondary");
private final static Tag HIGHWAY_MAJOR_TAG = new Tag("highway", "primary");
private final static Tag HIGHWAY_STREET_TAG = new Tag("highway", "residential");
private final static Tag HIGHWAY_RAIL_TAG = new Tag("railway", "rail");
//private final Tag[] mFallbackTag = new Tag[] { new Tag("debug", "way") };
// private int mClipped;
static class Feature extends Inlist<Feature> { static class Feature extends Inlist<Feature> {
short[] tags; short[] tags;
int numTags; int numTags;
@ -511,16 +512,17 @@ public class MapDatabase implements IMapDatabase {
} else if (type == TAG_GEOM_UNKNOWN) } else if (type == TAG_GEOM_UNKNOWN)
elem.startPoints(); elem.startPoints();
int cnt = 0;
boolean even = true; boolean even = true;
float scale = mScaleFactor; float scale = mScaleFactor;
byte[] buf = lwHttp.buffer; byte[] buf = lwHttp.buffer;
int pos = lwHttp.bufferPos; int pos = lwHttp.bufferPos;
lwHttp.bufferPos += bytes;
int end = pos + bytes; int end = pos + bytes;
int val; int val;
int curX = 0; int curX = 0;
int curY = 0; int curY = 0;
int prevX = 0; int prevX = 0;
@ -528,10 +530,12 @@ public class MapDatabase implements IMapDatabase {
int cmd = 0; int cmd = 0;
int num = 0; int num = 0;
boolean first = true; boolean first = true;
boolean lastClip = false; boolean lastClip = false;
boolean isOuter = true; // test bbox for outer..
boolean isOuter = mTile.zoomLevel < 14;
int xmin = Integer.MAX_VALUE, xmax = Integer.MIN_VALUE; int xmin = Integer.MAX_VALUE, xmax = Integer.MIN_VALUE;
int ymin = Integer.MAX_VALUE, ymax = Integer.MIN_VALUE; int ymin = Integer.MAX_VALUE, ymax = Integer.MIN_VALUE;
@ -596,16 +600,21 @@ public class MapDatabase implements IMapDatabase {
elem.startHole(); elem.startHole();
} }
} }
} else { continue;
}
// zigzag decoding // zigzag decoding
int s = ((val >>> 1) ^ -(val & 1)); int s = ((val >>> 1) ^ -(val & 1));
if (even) { if (even) {
// get x coordinate
even = false; even = false;
curX = lastX = lastX + s; curX = lastX = lastX + s;
} else { continue;
even = true; }
// get y coordinate and add point to geometry
num--;
even = true;
curY = lastY = lastY + s; curY = lastY = lastY + s;
int dx = (curX - prevX); int dx = (curX - prevX);
@ -617,12 +626,13 @@ public class MapDatabase implements IMapDatabase {
// dont clip at tile boundaries // dont clip at tile boundaries
|| (curX <= 0 || curX >= 4095) || (curX <= 0 || curX >= 4095)
|| (curY <= 0 || curY >= 4095)) { || (curY <= 0 || curY >= 4095)) {
prevX = curX; prevX = curX;
prevY = curY; prevY = curY;
elem.addPoint(curX / scale, curY / scale); elem.addPoint(curX / scale, curY / scale);
lastClip = false; lastClip = false;
if (isPoly) { if (isOuter) {
if (curX < xmin) if (curX < xmin)
xmin = curX; xmin = curX;
if (curX > xmax) if (curX > xmax)
@ -632,19 +642,13 @@ public class MapDatabase implements IMapDatabase {
ymin = curY; ymin = curY;
if (curY > ymax) if (curY > ymax)
ymax = curY; ymax = curY;
} }
} else { continue;
}
lastClip = true; lastClip = true;
} }
num--;
cnt++;
}
}
}
if (isPoly && isOuter && !testBBox(xmax - xmin, ymax - ymin)) { if (isPoly && isOuter && !testBBox(xmax - xmin, ymax - ymin)) {
//Log.d(TAG, "skip small poly "+ elem.indexPos + " > " //Log.d(TAG, "skip small poly "+ elem.indexPos + " > "
// + (xmax - xmin) * (ymax - ymin)); // + (xmax - xmin) * (ymax - ymin));
@ -655,18 +659,13 @@ public class MapDatabase implements IMapDatabase {
} else { } else {
elem.type = GeometryType.NONE; elem.type = GeometryType.NONE;
} }
lwHttp.bufferPos += bytes;
return 0; return 0;
} }
if (isLine && lastClip) if (isLine && lastClip)
elem.addPoint(curX / scale, curY / scale); elem.addPoint(curX / scale, curY / scale);
lwHttp.bufferPos = pos; return 1;
return cnt;
} }
private static boolean testBBox(int dx, int dy) { private static boolean testBBox(int dx, int dy) {