Вы можете использовать SRID 3857 для 1 м декартовой сетки:
models.py
:
class Place(models.Model):
geom = models.PointField(srid=3857, dim=3)
def __str__(self):
return str(self.geom.coords)
Однако GeoDjango не поддерживает трехмерные вычисления расстояния изкоробка.Например:
from django.contrib.gis.geos import Point
from django.contrib.gis.measure import Distance
from myapp.models import Place
p = Point(100, 100, 0)
Place.objects.create(geom=p)
Place.objects.create(geom=Point(150, 100, 0))
Place.objects.create(geom=Point(100, 100, 22))
Place.objects.create(geom=Point(100, 100, 500))
Place.objects.create(geom=Point(150, 150, 0))
Place.objects.create(geom=Point(250, 250, 0))
for o in Place.objects.filter(geom__distance_lte=(p, Distance(m=100))):
print(o.geom.coords, p.distance(o.geom))
Вывод:
(100.0, 100.0, 0.0) 0.0
(150.0, 100.0, 0.0) 50.0
(100.0, 100.0, 22.0) 0.0
(100.0, 100.0, 500.0) 0.0
(150.0, 150.0, 0.0) 70.71067811865476
В чистом PostGIS сравните ST_Distance
и ST_3DDistance
:
SELECT *
FROM (
SELECT
"myapp_place"."id",
ST_Distance("myapp_place"."geom",
ST_GeomFromEWKT('SRID=3857;POINT(100 100 0)')) d,
ST_AsEWKT("myapp_place"."geom")
FROM "myapp_place"
) t
WHERE d <= 100.0
с
SELECT *
FROM (
SELECT
"myapp_place"."id",
ST_3DDistance("myapp_place"."geom",
ST_GeomFromEWKT('SRID=3857;POINT(100 100 0)')) d,
ST_AsEWKT("myapp_place"."geom")
FROM "myapp_place"
) t
WHERE d <= 100.0