Skip to content

Instantly share code, notes, and snippets.

View kalombos's full-sized avatar

Nikolay kalombos

View GitHub Profile
@kalombos
kalombos / google_maps_polygon.py
Last active August 31, 2023 21:48
This is a solution for polygon selection in google maps. Some polygons can across antimeridian which will be getting wrong by postgis when you make ST_Within query, for example. So, this function allows to split polygon to multipolygon, parts of wich are contained in both hemispheres if needs
# -*- coding: utf-8 -*-
from django.contrib.gis.geos import MultiPolygon, GEOSGeometry
from django.db import connection
def is_crossed_antimeridian(polygon):
crossed = False
coords = []
for polygon_set in polygon:
for (lng, lat) in polygon_set: