use WayData container to pass geometry and tags to TileGenerator

This commit is contained in:
Hannes Janetzek
2013-04-02 11:21:13 +02:00
parent bef8e125fb
commit b7ca00ae8f
8 changed files with 152 additions and 85 deletions

View File

@@ -25,6 +25,35 @@ import org.oscim.database.mapfile.MapDatabase;
* references to any arrays after callback function returns.
*/
public interface IMapDatabaseCallback {
public class WayData{
public WayData(){
}
public WayData(GeometryBuffer geom, Tag[] tags) {
this.geom = geom;
this.tags = tags;
}
public GeometryBuffer geom;
// closed == geometry is polygon
public boolean closed;
// osm layer of the way.
public int layer;
// osm tags of the way.
public Tag[] tags;
// building tags
public int height;
public int minHeight;
// unused
public int priority;
}
/**
* Renders a single point of interest node (POI).
*
@@ -32,10 +61,6 @@ public interface IMapDatabaseCallback {
* the layer of the node.
* @param tags
* the tags of the node.
* @param latitude
* the latitude of the node.
* @param longitude
* the longitude of the node.
*/
void renderPOI(byte layer, Tag[] tags, GeometryBuffer geom);
@@ -45,23 +70,10 @@ public interface IMapDatabaseCallback {
void renderWaterBackground();
/**
* Renders a single way or area (closed way).
* Renders a single way or area.
*
* @param layer
* the osm layer of the way.
* @param tags
* the tags of the way.
* @param wayNodes
* the geographical coordinates of the way nodes in the order
* longitude/latitude or x/y depending on the projection.
* @param wayLength
* length of way data in wayNodes
* @param closed
* wheter the way is an polygon.
* @param prio TODO
*/
void renderWay(byte layer, Tag[] tags, GeometryBuffer geom,
boolean closed, int prio);
void renderWay(WayData way);
// /**
// * TBD: check if way will be rendered before decoding - MUST be called before renderWay!

View File

@@ -979,7 +979,7 @@ public class MapDatabase implements IMapDatabase {
&& mGeom.points[1] == mGeom.points[l - 1];
projectToTile(mGeom.points, mGeom.index);
mapDatabaseCallback.renderWay(layer, curTags, mGeom, closed, 0);
/// FIXME mapDatabaseCallback.renderWay(layer, curTags, mGeom, closed, 0);
}
}

View File

@@ -28,6 +28,7 @@ import org.oscim.core.Tag;
import org.oscim.core.Tile;
import org.oscim.database.IMapDatabase;
import org.oscim.database.IMapDatabaseCallback;
import org.oscim.database.IMapDatabaseCallback.WayData;
import org.oscim.database.MapInfo;
import org.oscim.database.MapOptions;
import org.oscim.database.OpenResult;
@@ -74,6 +75,8 @@ public class MapDatabase implements IMapDatabase {
private final boolean debug = false;
private LwHttp lwHttp;
private final WayData mWay = new WayData();
@Override
public QueryResult executeQuery(JobTile tile, IMapDatabaseCallback mapDatabaseCallback) {
QueryResult result = QueryResult.SUCCESS;
@@ -228,7 +231,9 @@ public class MapDatabase implements IMapDatabase {
private static final int TAG_ELEM_INDEX = 12;
private static final int TAG_ELEM_COORDS = 13;
private static final int TAG_ELEM_LAYER = 21;
private static final int TAG_ELEM_PRIORITY = 31;
private static final int TAG_ELEM_HEIGHT = 31;
private static final int TAG_ELEM_MIN_HEIGHT = 32;
private static final int TAG_ELEM_PRIORITY = 41;
private short[] mTmpKeys = new short[100];
private final Tag[] mTmpTags = new Tag[20];
@@ -335,8 +340,7 @@ public class MapDatabase implements IMapDatabase {
int end = mBytesProcessed + bytes;
int indexCnt = 1;
int layer = 5;
int prio = 0;
//int layer = 5;
boolean skip = false;
boolean fail = false;
@@ -347,6 +351,11 @@ public class MapDatabase implements IMapDatabase {
mGeom.index[0] = 2;
}
mWay.layer = 5;
mWay.priority = 0;
mWay.height = 0;
mWay.minHeight = 0;
while (mBytesProcessed < end) {
// read tag and wire type
int val = decodeVarint32();
@@ -382,11 +391,19 @@ public class MapDatabase implements IMapDatabase {
break;
case TAG_ELEM_LAYER:
layer = decodeVarint32();
mWay.layer = decodeVarint32();
break;
case TAG_ELEM_HEIGHT:
mWay.height= decodeVarint32();
break;
case TAG_ELEM_MIN_HEIGHT:
mWay.minHeight = decodeVarint32();
break;
case TAG_ELEM_PRIORITY:
prio = decodeVarint32();
mWay.priority = decodeVarint32();
break;
default:
@@ -402,15 +419,20 @@ public class MapDatabase implements IMapDatabase {
return false;
}
mWay.geom = mGeom;
mWay.tags = tags;
switch (type) {
case TAG_TILE_LINE:
mMapGenerator.renderWay((byte) layer, tags, mGeom, false, prio);
mWay.closed = false;
mMapGenerator.renderWay(mWay);
break;
case TAG_TILE_POLY:
mMapGenerator.renderWay((byte) layer, tags, mGeom, true, prio);
mWay.closed = true;
mMapGenerator.renderWay(mWay);
break;
case TAG_TILE_POINT:
mMapGenerator.renderPOI((byte) layer, tags, mGeom);
mMapGenerator.renderPOI((byte) mWay.layer, tags, mGeom);
break;
}

View File

@@ -41,6 +41,7 @@ import org.oscim.core.Tag;
import org.oscim.core.Tile;
import org.oscim.database.IMapDatabase;
import org.oscim.database.IMapDatabaseCallback;
import org.oscim.database.IMapDatabaseCallback.WayData;
import org.oscim.database.MapInfo;
import org.oscim.database.MapOptions;
import org.oscim.database.OpenResult;
@@ -102,6 +103,8 @@ public class MapDatabase implements IMapDatabase {
private static final int MAX_TAGS_CACHE = 100;
private final WayData mWay = new WayData();
private static Map<String, Tag> tagHash = Collections
.synchronizedMap(new LinkedHashMap<String, Tag>(
MAX_TAGS_CACHE, 0.75f, true) {
@@ -451,7 +454,12 @@ public class MapDatabase implements IMapDatabase {
if (layer == 0)
layer = 5;
mMapGenerator.renderWay((byte) layer, tags, mGeom, polygon, 0);
mWay.geom = mGeom;
mWay.tags = tags;
mWay.layer = layer;
mWay.closed = polygon;
mMapGenerator.renderWay(mWay);
return true;
}

View File

@@ -30,6 +30,7 @@ import org.oscim.core.Tag;
import org.oscim.core.WebMercator;
import org.oscim.database.IMapDatabase;
import org.oscim.database.IMapDatabaseCallback;
import org.oscim.database.IMapDatabaseCallback.WayData;
import org.oscim.database.MapInfo;
import org.oscim.database.MapOptions;
import org.oscim.database.OpenResult;
@@ -71,6 +72,9 @@ public class MapDatabase implements IMapDatabase {
new HashMap<Entry<String, String>, Tag>(100);
private PreparedStatement prepQuery = null;
private final WayData mWay = new WayData();
private boolean connect() {
Connection conn = null;
String dburl = "jdbc:postgresql://city.informatik.uni-bremen.de:5432/gis-2.0";
@@ -187,7 +191,12 @@ public class MapDatabase implements IMapDatabase {
if (mGeom.index.length > mGeom.indexPos)
mGeom.index[mGeom.indexPos] = -1;
mapDatabaseCallback.renderWay((byte) 0, mTags, mGeom, polygon, 0);
mWay.geom = mGeom;
mWay.tags = mTags;
mWay.layer = 0;
mWay.closed = polygon;
mapDatabaseCallback.renderWay(mWay);
}
}
} catch (SQLException e) {

View File

@@ -20,6 +20,7 @@ import org.oscim.core.Tag;
import org.oscim.core.Tile;
import org.oscim.database.IMapDatabase;
import org.oscim.database.IMapDatabaseCallback;
import org.oscim.database.IMapDatabaseCallback.WayData;
import org.oscim.database.MapInfo;
import org.oscim.database.MapOptions;
import org.oscim.database.OpenResult;
@@ -51,6 +52,7 @@ public class MapDatabase implements IMapDatabase {
null);
private boolean mOpenFile = false;
private final WayData mWay = new WayData();
@Override
public QueryResult executeQuery(JobTile tile, IMapDatabaseCallback mapDatabaseCallback) {
@@ -105,7 +107,12 @@ public class MapDatabase implements IMapDatabase {
index[2] = 10;
index[3] = 0;
mapDatabaseCallback.renderWay((byte) 0, mTags, mGeom, true, 0);
mWay.geom = mGeom;
mWay.tags = mTags;
mWay.layer = (byte)0;
mWay.closed = true;
mapDatabaseCallback.renderWay(mWay);
index[0] = 4;
index[1] = -1;
@@ -115,43 +122,43 @@ public class MapDatabase implements IMapDatabase {
points[1] = size / 2;
points[2] = size;
points[3] = size / 2;
mapDatabaseCallback.renderWay((byte) 0, mTagsWay, mGeom, false, 0);
mapDatabaseCallback.renderWay(mWay);
// center up
points[0] = size / 2;
points[1] = -size / 2;
points[2] = size / 2;
points[3] = size / 2;
mapDatabaseCallback.renderWay((byte) 0, mTagsWay, mGeom,
false, 0);
mapDatabaseCallback.renderWay(mWay);
// center down
points[0] = size / 2;
points[1] = size / 2;
points[2] = size / 2;
points[3] = size / 2 + size;
mapDatabaseCallback.renderWay((byte) 0, mTagsWay, mGeom, false, 0);
mapDatabaseCallback.renderWay(mWay);
mWay.layer = (byte)1;
// left-top to center
points[0] = size / 2;
points[1] = size / 2;
points[2] = 10;
points[3] = 10;
mapDatabaseCallback.renderWay((byte) 1, mTagsWay, mGeom, false, 0);
mapDatabaseCallback.renderWay(mWay);
// middle horizontal
points[0] = 0;
points[1] = 10;
points[2] = size;
points[3] = 10;
mapDatabaseCallback.renderWay((byte) 1, mTagsWay, mGeom, false, 0);
mapDatabaseCallback.renderWay(mWay);
// middle horizontal
points[0] = 10;
points[1] = 0;
points[2] = 10;
points[3] = size;
mapDatabaseCallback.renderWay((byte) 1, mTagsWay, mGeom, false, 0);
mapDatabaseCallback.renderWay(mWay);
// lon1 = size / 2;
// lat1 = size / 2;