4 Working with real data

 

This chapter covers

  • PostGIS backup and restore utilities
  • Utilities for downloading and uncompressing files
  • Importing and exporting Esri shapefile data
  • Importing and exporting vector data using ogr2ogr
  • Querying external data using foreign data wrappers
  • Importing and exporting raster data
  • PostGIS raster output functions

In this chapter we’ll look at how you can load real-world data into PostGIS and export it. We’ll point you to specific data sources for the examples in this chapter, but if you’re interested in other sources, see the list we’ve compiled in appendix A. We encourage you to explore on your own and report back on any discoveries of interesting data sources at our Manning author forum: www.manning.com/obe3.

Note

Geographic data that covers a swath of areas on our spheroidal earth needs special attention. You need to understand, at least on a rudimentary level, ellipsoids, datums, and projections in order to understand the pros and cons of different spatial reference systems so that you can determine which ones suit your use. The fundamentals we provided in the previous chapter should guide you in the right direction.

4.1 PostgreSQL built-in tools

4.1.1 Psql

4.1.2 pgAdmin4

4.1.3 Pg_dump and pg_restore

4.2 Downloading files

4.3 Extracting files

4.4 Importing and exporting shapefiles

4.4.1 Importing with shp2pgsql

4.4.2 Importing and exporting with shp2pgsql-gui

4.4.3 Exporting with pgsql2shp

4.5 Importing and exporting vector data with ogr2ogr

4.5.1 Environment variables in ogr2ogr