Database Reference
In-Depth Information
rome=# CREATE VIEW rome_trees ASSELECT
way, tags FROM planet_osm_polygonWHERE
(tags -> 'landcover') = 'trees';
7. Open the view with a Desktop GIS that supports PostGIS views, such as
QGIS, and add your
rome_trees
view. The preceding screenshot shows
you how it looks.
How it works...
OpenStreetMap is a popular collaborative project for creating a free map of the
world. Every user participating in the project can edit data; at the same time, it is
possibleforeveryonetodownloadthosedatasetsin
.osm
datafiles(anXMLformat)
underthetermsofthe
Open Data Commons Open Database License
(
ODbL
)at
the time of writing.
The
osm2pgsql
command is a command-line tool that can import
.osm
datafiles
(eventually zipped) to the PostGIS database. For using the command, it is enough
to give the PostgreSQL connection parameters and the
.osm
file to import.
It ispossible to import only features having certain tags in the spatial database, as
definedinthe
default.style
configurationfile.Youcandecidetocommentinor
outfromthisfiletheOSMtaggedfeaturesthatyouwouldliketoimportornot.The
command by default exports all the nodes and ways to linestring, point, and geo-
metry PostGIS geometries.
Itishighlyrecommendedtoenablethe
hstore
supportinthePostgreSQLdatabase
and use the
-hstore
option of
osm2pgsql
when importing the data. Having en-
abledthissupport,theOSMtagsforeachfeaturewillbestoredinan
hstore
Post-
greSQLdatatype,whichisoptimizedforstoring(andretrieving)setsofkey/values
pairs in a single field. This way it will be possible to query the database as follows
SELECT way, tags FROM planet_osm_polygonWHERE
(tags -> 'landcover') = 'trees';