[OSM-dev] OSM data import using osm2pgsql... what's next.

Christian Quest cquest at openstreetmap.fr
Wed Jul 30 17:29:18 UTC 2014

2014-07-29 22:51 GMT+02:00 Loic Duros <loic.duros at gmail.com>:

> I am completely new to both OSM data and PostGIS, and I have a few
> questions, which I thought would be best asked in this mailing list. If you
> can think of another mailing list where these questions would be more
> appropriate, please let me know.
> I am currently using osm2pgsql to import the planet osm data. This is
> taking a while, expectedly, and I'm using --flat-nodes in order to save
> space, as well as -k, which according to -h is for the hstore.
> For reference, this is the full command I am running:
> osm2pgsql -c -d mapdatabase -U myuser -W --slim -C 18000 -k
> --flat-nodes=/var/planet/planet_nodes.cache --number-processes 4 -v
> I would like to use my server later on for tile-serving purposes (using
> Mapnik and mod-tile, and/or TileStache), but I would also like to be able
> to run queries that give me interesting data for an Android app I will
> build.
> Because I am using flat-nodes, will I still be able to make queries to
> calculate distances, find points of interest (such as detecting hills
> around a point, ...)
> The PostGIS in Action book has an interesting example of query:
> "Suppose the task at hand is to find the total length of all interstate
> highways in the state of Utah. We search for two tables: one with the
> polygons for all the states and one with all interstate highways in the
> United States, represented as linestrings. Next we extract the polygon that
> represents Utah from the states table and perform an SQL join with the
> highways table using
> the geometric intersects function as the join operator and geometric
> intersection as
> our output function. The output of that query would be those portions of
> all highways
> within the state of Utah."
> Is such a query doable with the postgis database generated by osm2pgsql?


It is not designed for that, but I regularly use it that way.
Be aware that osm2pgsql does not keep all OSM data and tags. This is
controlled by the style file (or style LUA script) during import.
Be aware also of the map projection. By default osm2pgsql will reproject
OSM lat/lon into web mercator coordinates. Doing real distance based
queries will require reprojection...

> I understand osm2pgsql is focused on tile rendering, but I'm curious to
> see how much can be done in terms of analysis with it, not just for roads
> but for looking for distinct features in the environment (forest, parks,
> hills, ...) within a given range. Does using flat-nodes for the import
> limit the capability to do spatial queries in any way?
The flat-nodes file is only used during import and diff update process. It
is just a raw storage of lat/lon without any other detail.

Once osm2pgsql has processed OSM data, you have 4 tables containing
geometries (points, lines, polygons + roads which is a light version of the
line table using for the first zoom level of rendering).
In the "slim" tables (nodes, ways, rels) you have no geometries, and
postgis queries are useless on them.

> Finally, I would also like to create a custom design for rendering tiles.
> I have taken a look at osm.xml located in my local directory, and it looks
> like this is the right file to override to design tiles a little
> differently in terms of look and feel. However, I've also tried using
> TileMill, and was wondering if this is something that can be used with
> Mapnik as well.

TileMill is a GUI on top of Mapnik. Use TileMill to create your style, then
export it as an XML mapnik file to use it directly with any mapnik enabled
software (like mod_tile/renderd).

> Thank you for your interest and for your guidance.
> Loic Duros

Christian Quest - OpenStreetMap France
-------------- next part --------------
An HTML attachment was scrubbed...
URL: <http://lists.openstreetmap.org/pipermail/dev/attachments/20140730/468578cd/attachment.html>

More information about the dev mailing list