如何在geoDjango模型字段中指定空间参考?

时间:2019-06-29 10:47:04

标签: geodjango

我正在使用GeoDjango处理Django中的GIS字段。我在前端有以下点对象:-

extent: undefined
hasM: false
hasZ: true
latitude: 28.49387824220977
longitude: 77.48524779960519
m: undefined
spatialReference: Object
isGeographic: false
isWGS84: false
isWebMercator: true
isWrappable: true
latestVcsWkid: undefined
latestWkid: 3857
vcsWkid: undefined
wkid: 102100
wkt: null
constructed: true
destroyed: false
initialized: true
__accessor__: b {…}
__proto__: Object
type: "point"
x: 8625618.329042671
y: 3311384.441150026
z: 199.01291322830033
constructed: true
destroyed: false
initialized: true

当我将上述点存储在数据库中时,它不在我指定的位置。

这可能是由于空间参考的差异。我试图通过如下编写模型字段来解决此问题:-

models.py

location = models.PointField(geography=True, null=True, blank=True, srid=3857)
plg = models.PolygonField(geography=True, null=True, srid=3857)

views.py

...
Site.objects.create(
            location=Point(float(data['latitude']), float(site_data['longitude'])),
            plg=Polygon(data['roof'])
        )
...

但这似乎不起作用,并且出现以下错误:-

django.db.utils.DataError: Geometry SRID (4326) does not match column SRID (102100)

0 个答案:

没有答案