How to do it...

The steps you need to take to complete this recipe are as follows:

  1. First, you will create a view to clip the river geometries for each country using the ST_Intersection and ST_Intersects functions. Name the view rivers_clipped_by_country:
       postgis_cookbook=> CREATE VIEW chp03.rivers_clipped_by_country AS 
         SELECT r.name, c.iso2, ST_Intersection(r.the_geom,           c.the_geom)::geometry(Geometry,4326) AS the_geom         FROM chp03.countries AS c 
         JOIN chp03.rivers AS r 
         ON ST_Intersects(r.the_geom, c.the_geom); 
  1. Create a directory named rivers as follows:
      mkdir working/chp03/rivers
  1. Create the following scripts to export a rivers shapefile for each country.

The following is the Linux version (name it export_rivers.sh):

 #!/bin/bash for ...

Get PostGIS Cookbook - Second Edition now with the O’Reilly learning platform.

O’Reilly members experience books, live events, courses curated by job role, and more from O’Reilly and nearly 200 top publishers.