Database Reference
In-Depth Information
postgis_cookbook=# CREATE EXTENSION
pg_trgm;
CREATE EXTENSION
4. You will need to download some OSM datasets to use. Download the area
tp://download.gfoss.it/osm/osm/regioni/
ifyouwanttogowiththerecipeand
getsimilarresults(youcanfindacopyofthisfileinthe
data/chp08
book's
dataset directory).
5. IfyouareusingWindows,besuretohaveinstalledtheOSGeo4Wsuiteas
suggested in the initial instructions of this chapter.
6. IfyouareusingLinux,followtheinitialinstructionsofthischapterandcreate
aPythonvirtualenvironmentinordertokeepaPython-isolatedenvironment
to be used for all the Python recipes of this topic. Then activate it as follows:
$ source postgis-cb-env/bin/activate
7. Oncetheenvironmenthasbeenactivated,ifyoustillhaven'tdoneit,youcan
install the Python packages needed for this recipe:
(postgis-cb-env)$ pip install gdal
(postgis-cb-env)$ pip install psycopg2
How to do it...
Carry out the following steps:
1. First,checkouthowtheOSM
.pbf
fileisbuiltusing
ogrinfo
.PBFisabin-
ary format intended as an alternative to the OSM XML format, mainly be-
causeitismuchsmaller.Asyoumusthavenoticed,itiscomposedofseveral
layers—youwillexportthe
lines
layertoPostGISasthatlayercontainsthe
street names that you will use for the overall geocoding process:
$ ogrinfo lazio.pbfHad to open data
source read-only.INFO: Open of
`lazio.pbf'using driver `OSM'
successful.1: points (Point)2: lines
(Line String)3: multilinestrings (Multi