-
Notifications
You must be signed in to change notification settings - Fork 73
Spatialite layer
Nutiteq edited this page May 22, 2013
·
14 revisions
AdvancedMap3D includes pre-compiled version of Spatialite (version 3.0)
There are following components:
- JNI Java wrapper for SQLite: jsqlite package. Note it is different from Android built-in SQLite API.
- Pre-built arm library libproj.so, should be in your project libs/armeabi folder.
- Layer to add data easily to Nutiteq 3D SDK: SpatialiteLayer.java
- Database helper class: SpatialLiteDb.java opens database, requests list of table spatial metadata and enables BBOX-based queries with projection transformations if needed
- Database file used in following sample code: Romainan OSM dataset (284 MB)
Following code shows usage of the layer, with several tables in one view:
// minimum zoom to show data
int minZoom = 10;
// open database connection, query metadata
SpatialLiteDb spatialLite = new SpatialLiteDb(dbPath);
Vector<DBLayer> dbMetaData = spatialLite.qrySpatialLayerMetadata();
// print spatial tables, their geometry columns
for (DBLayer dbLayer : dbMetaData) {
Log.debug("layer: "+dbLayer.table+" "+dbLayer.type+" geom:"+dbLayer.geomColumn);
}
// define styles for all 3 object types: point, line and polygon
StyleSet<PointStyle> pointStyleSet = new StyleSet<PointStyle>();
Bitmap pointMarker = UnscaledBitmapLoader.decodeResource(getResources(), R.drawable.point);
PointStyle pointStyle = PointStyle.builder().setBitmap(pointMarker).setSize(0.05f).setColor(Color.BLACK).build();
pointStyleSet.setZoomStyle(minZoom, pointStyle);
StyleSet<LineStyle> lineStyleSet = new StyleSet<LineStyle>();
lineStyleSet.setZoomStyle(minZoom, LineStyle.builder().setWidth(0.1f).setColor(Color.GREEN).build());
StyleSet<LineStyle> lineStyleSetHw = new StyleSet<LineStyle>();
lineStyleSetHw.setZoomStyle(minZoom, LineStyle.builder().setWidth(0.07f).setColor(Color.GRAY).build());
PolygonStyle polygonStyle = PolygonStyle.builder().setColor(Color.BLUE).build();
StyleSet<PolygonStyle> polygonStyleSet = new StyleSet<PolygonStyle>(null);
polygonStyleSet.setZoomStyle(minZoom, polygonStyle);
// define layers - one layer per table
SpatialiteLayer spatialiteLayerPt = new SpatialiteLayer(proj, dbPath, "pt_tourism",
"GEOMETRY", new String[]{"name"}, 500, pointStyleSet, null, null);
mapView.getLayers().addLayer(spatialiteLayerPt);
SpatialiteLayer spatialiteLayerLn = new SpatialiteLayer(proj, dbPath, "ln_railway",
"GEOMETRY", new String[]{"sub_type"}, 500, null, lineStyleSet, null);
mapView.getLayers().addLayer(spatialiteLayerLn);
SpatialiteLayer spatialiteLayerHw = new SpatialiteLayer(proj, dbPath, "ln_highway",
"GEOMETRY", new String[]{"name"}, 500, null, lineStyleSetHw, null);
mapView.getLayers().addLayer(spatialiteLayerHw);
SpatialiteLayer spatialiteLayerPoly = new SpatialiteLayer(proj, dbPath, "pg_boundary",
"GEOMETRY", new String[]{"name"}, 500, null, null, polygonStyleSet);
mapView.getLayers().addLayer(spatialiteLayerPoly);
