Mathare Building import

From Map Kibera

(Difference between revisions)
Jump to: navigation, search
(Import OSM data to the db)
(Find collisions between OSM and the import candidate)
Line 39: Line 39:
* planet_osm_ways
* planet_osm_ways
-
== Find collisions between OSM and the import candidate ==  
+
== Find collisions between OSM and the import candidate ==
 +
Very few buildings have already been mapped in OSM in Mathare (139 as of 2011.05.09). Yet, we should be careful whilst importing the dataset from aerial imagery extraction. While we can discard the geometry of the existing buildings, we shall preserve their attributes.
 +
 
 +
Basically, we shall check for geometries that overlaps and apply the attributes of the OSM element to the imported one.
 +
 
 +
'''Note:''' I can see two tricky corner cases, which I don't need to worry about right now since this import does not feature them. However, overlooking these issues in another import will likely result in a loss of data:
 +
* nodes of the buildings bear attributes
 +
* multipolygons
 +
 
 +
We identify the overlapping elements with this query:
 +
mathare#= select o.osm_id, g.gid from planet_osm_polygon as o, "groundtruthed-wgs84" as g where ST_Intersects(g.the_geom, o.way) ORDER BY g.gid;
== Tagging scheme ==
== Tagging scheme ==
== Generate the OSM data to be imported ==
== Generate the OSM data to be imported ==

Revision as of 17:26, 9 May 2011

In this page, I (Sébastien) will describe how to import the data of the building extraction of Mathare that we've got from AAAS. See Primož's blog for the initial analysis.


Contents

Changing the SRS

The data was made available as shapefiles in WGS84 Web Mercator Auxiliary Sphere projection, which is known as Web Mercator, spherical Mercator, Google Mercator and is referenced by various ids: EPSG:900913, EPSG:3785 (obsolete), EPSG:3857, ESRI WKID 102100... In QGIS, it's known as Google Mercator, EPSG:900913, ID 3644.

Before working with the data, we need to change the Spatial Reference System (SRS) to be compatible with OSM, that is moving to non-projected WGS84.
In QGIS: menu Vector -> Data Management Tools -> Export to new projection. Then choose the output CRS to be WGS84, EPSG:4326, ID 3452.
The two files that we're going to import are GroundTruthed-wgs84.shp and BuildingsOnTop-wgs84.shp

Setup PostGIS database

PostGIS is relatively easy to install on Ubuntu. I might describe it further later. Anyway, the current environment is PostgreSQL 8.4, PostGIS 1.5.
I found this script from GeoDjango very convenient to create a postgis db template:

$ ./create_template_postgis-debian.sh
$ createdb -T template_postgis mathare

Import the shapefiles to the db

Each shapefile will be imported a separate table with shp2pgsql:

shp2pgsql -s 4326 -c -g the_geom -I -S -W UTF-8 -N skip Groundtruthed-wgs84.shp | psql mathare
shp2pgsql -s 4326 -c -g the_geom -I -S -W UTF-8 -N skip BuildingsOnTop-wgs84.shp | psql mathare

Import OSM data to the db

In this case, we're only interested in buildings from OSM.

Get fresh data from OSM:

osmosis \
--read-api left=36.8425655 right=36.881876 top=-1.2480512 bottom=-1.2696752999999998 outPipe.0=1 \
--way-key keyList=building inPipe.0=1 outPipe.0=2 \
--used-node inPipe.0=2 outPipe.0=3 \
--write-xml file=mathare_building.osm inPipe.0=3

Import it to the database:

osm2pgsql -c -d mathare -l -s mathare_building.osm

The following tables will be created:

  • planet_osm_line
  • planet_osm_nodes
  • planet_osm_point
  • planet_osm_polygon
  • planet_osm_rels
  • planet_osm_roads
  • planet_osm_ways

Find collisions between OSM and the import candidate

Very few buildings have already been mapped in OSM in Mathare (139 as of 2011.05.09). Yet, we should be careful whilst importing the dataset from aerial imagery extraction. While we can discard the geometry of the existing buildings, we shall preserve their attributes.

Basically, we shall check for geometries that overlaps and apply the attributes of the OSM element to the imported one.

Note: I can see two tricky corner cases, which I don't need to worry about right now since this import does not feature them. However, overlooking these issues in another import will likely result in a loss of data:

  • nodes of the buildings bear attributes
  • multipolygons

We identify the overlapping elements with this query:

mathare#= select o.osm_id, g.gid from planet_osm_polygon as o, "groundtruthed-wgs84" as g where ST_Intersects(g.the_geom, o.way) ORDER BY g.gid;

Tagging scheme

Generate the OSM data to be imported

Personal tools