I have a Region model (deriving from django.contrib.gis.db.models.Model), with a geom field, which is a django.contrib.gis.db.models.MultiPolygonField.

I'd like to compute the intersection of this model (representing a set of polygonal regions stored in PostGIS) with a GeoJSON polygonal query (in the context of a web service):

from django.contrib.gis.geos import GEOSGeometry

query = GEOSGeometry(

I tried many things:

results = Region.objects.all().intersection(query) 


from django.contrib.gis.db.models.functions import Intersection

results = Intersection(Region.objects.all(), query)

but it seems I don't have the right approach.

Note that I do not want to simply compute the subset of regions which intersect with the query, but rather their exact intersection (in other words the resulting set of polygons should have the exact same bounding box as the query).


You are quite close.

A good approach would be to loop through all the objects that intersect with the query geom and append their intersection to a list of results:

intersection_geom = []

for region in Region.objects.filter(geom__intersects=query):

Then you can manipulate that list as it suits you.

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service, privacy policy and cookie policy

Not the answer you're looking for? Browse other questions tagged or ask your own question.