A common GIS use case is clipping a big dataset into small portions (subsets), with each perhaps representing an area of interest. In this recipe, you will export from a PostGIS layer representing the rivers in the world, with one distinct shapefile composed of rivers for each country. For this purpose, you will use the ST_Intersection
function.
Be sure that you have imported in PostGIS the same river dataset (a shapefile) that was used in the previous recipe.
The steps you need to take to complete this recipe are as follows:
- First, you will create a view to clip the river geometries for each country using the
ST_Intersection
andST_Intersects
functions. Name the viewrivers_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 ...