python - How to get overlapping objects in geodjango? -
i'm creating app using geodjango
.
have model so:
class worldborder(models.model): name = models.charfield(max_length=50) mpoly = models.multipolygonfield()
there can 2 or more objects overlapping borders in database.
how can determine if objects have overlapping borders?
how can queryset of objects overlapping borders?
thanks
you have 2 options, depending on want achieve:
option 1: can use
__overlaps
lookup: example of use:
an_mpoly = worldborder.objects.get(name='a_name').mpoly overlapping_mpolys = worldborder.objects.filter(mpoly__overlaps=an_mpoly)
now overlapping_mpolys
queryset, containing every worldborder
object who's mpoly
overlaps mpoly
of worldborder
object name='a_name'
.
option 2: if need
object object
overlap check, can utilize geos api overlaps
method: example of use:
mpoly_1 = worldborder.objects.get(name='name_1').mpoly mpoly_2 = worldborder.objects.get(name='name_2').mpoly if mpoly_1.overlaps(mpoly_2): print("{} , {} overlapping".format(mpoly_1, mpoly_2))
Comments
Post a Comment