Database Reference
In-Depth Information
Handling
batch
importing
and
exporting of datasets
InmanyGISworkflows,thereisatypicalscenariowheresubsetsofaPostGIStable
mustbedeployedtoexternalusersinafilesystemformat(mosttypically,shapefiles
oraspatialitedatabase).Often,thereisalsothereverseprocess,wheredatasetsre-
ceived from different users have to be uploaded to the PostGIS database.
Inthisrecipe,wewillsimulatebothofthesedataflows.Youwillfirstcreatethedata
flowforprocessingtheshapefilesoutofPostGIS,andthenthereversedataflowfor
uploading the shapefiles.
You will do it using the power of bash scripting and the ogr2ogr command.
Getting ready
Ifyoudidn'tfollowalltheotherrecipes,besuretoimportthehotspotsandthecoun-
triesdatasetinPostGIS.Thefollowingishowtodoitwith ogr2ogr (youshouldim-
port both the datasets in their original SRID, 4326, to make spatial operations faster):
1. ImportinPostGISthe Global_24h.csv fileusingthe global_24.vrt vir-
tual driver you created in a previous recipe:
$ ogr2ogr -f PostgreSQL
PG:"dbname='postgis_cookbook' user='me'
password='mypassword'" -lco SCHEMA=chp01
global_24h.vrt -lco OVERWRITE=YES -lco
GEOMETRY_NAME=the_geom -nln hotspots
2. Import the countries shapefile using ogr2ogr :
$ ogr2ogr -f PostgreSQL -sql "SELECT ISO2,
NAME AS country_name FROM
'TM_WORLD_BORDERS-0.3'" -nlt MULTIPOLYGON
PG:"dbname='postgis_cookbook' user='me'
password='mypassword'" -nln countries -lco
SCHEMA=chp01 -lco OVERWRITE=YES -lco
Search WWH ::




Custom Search