I have a PostgreSQL database set up and am using Geodjango to interact with the geometry saved in this database. My use case is as follows:
Sample code:
region = Shapefile.objects.get(pk=1)
region_boundaries = region.geometry # this contains the boundaries for the region
all_parks_in_country = Shapefile.objects.get(pk=2)
parks = all_parks_in_country.geometry # and this one now has all the national parks
sliced_geometry = ...
# .... And here is where I am stuck!
I am providing visuals below. Note that I am trying to get the sliced geometry in the views, in Python -- once I have it there I will then use it as needed (show it in the HTML files or whatever is needed).
The first map shows the entire country and in green the national parks.
The second map shows, in purple outline, the boundaries of my region.
Third map showing in red those (parts of!) the national parks multi-polygon that should ideally be 'cut out' of the national geometry.
Since you have isolated the geometries you can use the GEOS API intersection
method on them.
The method:
Returns a GEOSGeometry representing the points shared by this geometry and "other".
So you can take the "sliced" geom as follows:
sliced_geometry = parks.intersection(region_boundaries)