[OSM-dev] OGR driver for OSM data

Jukka Rahkonen jukka.rahkonen at latuviitta.fi
Fri Mar 9 15:05:38 GMT 2012


Josh Doe wrote:
> On Thu, Mar 8, 2012 at 5:10 PM, Jochen Topf <jochen at remote.org> wrote:
>> The problem is not so much the geometries. Its the open tagging scheme
which
>> doesn't fit the fixed attribute names/types of the traditional GIS
world.
>> As a simple example, you might want to map "oneway=yes" and
>> "oneway=true" and
>> other versions to a simple boolean field. Real life examples are much
more
>> complex. OSM data basically always needs this cleanup and
>> canonicalization
>> and mapping step.
>
> True, that's an issue as well, but I'm thinking of the simplest
> mapping possible, just one to one (by default at least). Plenty of
non-OSM data sources need cleaning up as well, so I don't see that as a
specific issue with OSM data. Again, if someone wants more control, they
can use other tools like Osmium.

It would be rather easy to deliver a fair subset of OSM data in a format
that is understood by OGR by setting up a WFS service on top of PostGIS
and osm2pgsql tables.  The new GDAL version 1.9.0 supports WFS service as
one of the OGR vector source.

The WFS service below contains at the moment more than 60 WFS layers from
Finland. 4 of them come from OSM data (osm_point, osm_line, osm_polygon
and osm_address). Most other layers contain public (attribution only)
spatial data from Finnish state agencies.

The following example requests should work with GDAL 1.9.0.

This command lists all the layers which exist in the service:
ogrinfo wfs:http://188.64.1.61/cgi-bin/tinyows

If someone wants to see the WFS GetCapabilities XML-document comes with
this request:
ogrinfo wfs:http://188.64.1.61/cgi-bin/tinyows WFSGetCapabilities

Let's convert all the pubs from osm_point layer into local shapefile. The
command to use is:
ogr2ogr -f "ESRI Shapefile" osm_pub.shp
wfs:http://188.64.1.61/cgi-bin/tinyows -sql "select * from osm_point where
amenity='pub'"

The command will reveal some restrictions of shapefile format.
Format (-f) can be any of those which GDAL can write (creation=yes in
http://gdal.org/ogr/ogr_formats.html). Most of the ogr2ogr options can be
used http://gdal.org/ogr2ogr.html and GDAL support for SQL is pretty good.

Osm_address is an exprerimental synthetic layer which combines all
osm_points with some address tags and centroids of osm_polygons with
address tags so that the result is a plain point layer. The following
command converts all the addresses into shapefile (73836 points if my
server manages to do the job).

ogr2ogr -f "ESRI Shapefile" osm_address.shp
wfs:http://188.64.1.61/cgi-bin/tinyows osm_address

The count of fetched features and some other metadata can then be checked
with ogrinfo

ogrinfo -al -so osm_pub.shp
ogrinfo -al -so osm_address.shp

In addition to GDAL, the service is tested to work with Quantum GIS,
gvSIG, Kosmo GIS, MapInfo, ArcGIS, Gaia and Cadcorp SIS Map Browser.

The server is down every now and then. It is a very lean virtual Linux box
with only 500 MB of memory and it cannot even run osm2pgsql with the
Finland.bz2 file so I must run it on home computer and update the database
on the server side through PostgreSQL dump files.


-Jukka Rahkonen-





More information about the dev mailing list