简体   繁体   English

使用 GeoDjango 在坐标系之间转换

[英]Convert between coordinate systems with GeoDjango

I'm trying to add coordinate information to my database, adding django.contrib.gis support to my app.我正在尝试将坐标信息添加到我的数据库中,将django.contrib.gis支持添加到我的应用程序中。 I'm writing a south data migration that takes the addresses from the database, and asks Google for the coordinates (so far I think my best bet is to use geopy for this).我正在编写一个south数据迁移,它从数据库中获取地址,并向谷歌询问坐标(到目前为止,我认为我最好的选择是为此使用geopy )。

Next I need to convert the returned coordinates from WGS84:4326 , Google's coordinate system, to WGS84:22186 , my coordinate system.接下来,我需要将返回的坐标从 Google 的坐标系WGS84:4326转换为我的坐标系WGS84:22186

I'm lost among the GeoDjango docs trying to find a way to do this.我迷失在 GeoDjango 文档中,试图找到一种方法来做到这一点。 This far, I gather I need to do this:到目前为止,我认为我需要这样做:

gcoord = SpatialReference("4326")
mycoord = SpatialReference("22186")
trans = CoordTransform(gcoord, mycoord)

but then, I don't know how to use that CoordTransform object.. seems to be used by GDAL's data objects, but that's overkill for what I want to do..但是,我不知道如何使用那个CoordTransform object .. 似乎被 GDAL 的数据对象使用,但这对于我想要做的事情来说太过分了..

If you have all your libraries installed correctly there is no need to use the CoordTransform object, the point object's transform method will do the work for you if you know your desired srid value.如果您正确安装了所有库,则无需使用CoordTransform object,如果您知道所需的srid值,点对象的transform方法将为您完成工作。

>>> from django.contrib.gis.geos import Point
>>> pnt = Point(30, 50, srid=4326)
>>> desired_srid = 22186
>>> pnt.transform(desired_srid)
>>> pnt.ewkt
u'SRID=22186;POINT (11160773.5712331663817167 19724623.9116888605058193)'

CoordTransform wouldn't work without GDAL that's true.如果没有 GDAL,CoordTransform 将无法工作,这是真的。 But the rest of it is simple enough:但是它的 rest 很简单:

>>> from django.contrib.gis.gdal import SpatialReference, CoordTransform
>>> from django.contrib.gis.geos import Point
>>> gcoord = SpatialReference(4326)
>>> mycoord = SpatialReference(22186)
>>> trans = CoordTransform(gcoord, mycoord)

>>> pnt = Point(30, 50, srid=4326)
>>> print 'x: %s; y: %s; srid: %s' % (pnt.x, pnt.y, pnt.srid)
x: 30.0; y: 50.0; srid: 4326
>>> pnt.transform(trans)
>>> print 'x: %s; y: %s; srid: %s' % (pnt.x, pnt.y, pnt.srid)
x: 11160773.5712; y: 19724623.9117; srid: 22186

Note that point is transformed in place.请注意,该点已就地转换。

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

相关问题 Numpy - 坐标系之间的转换 - Numpy - Transformations between coordinate systems 如何使用 `cv2.warpPolar` 在笛卡尔坐标系和极坐标系之间正确转换图像? - How to properly convert image between Cartesian and polar coordinate systems using `cv2.warpPolar`? 在坐标系之间平移坐标 opencv python - Translate coordinates between coordinate systems opencv python GeoDjango OSMWidget坐标更改 - GeoDjango OSMWidget coordinate change 如何在欧拉角的帮助下使用 Scipy 旋转在坐标系之间转换方向? - How to use Scipy Rotation for transforming Orientations between Coordinate Systems with the help of euler angles? Matplotlib - 结合文本/注释坐标系 - Matplotlib - Combine text/annotation coordinate systems GeoDjango:ValueError,无法将字符串转换为浮点数 - GeoDjango: ValueError, could not convert string to float 将utm坐标转换为参考相邻区域的坐标 - convert utm coordinate to coordinate in reference to neighboring zone geodjango管理地图未显示坐标点,尽管该点显然已正确保存 - geodjango admin map not displaying coordinate point, point is apparently saved correctly though 标准 Anaconda 安装程序中是否有转换地球坐标系的功能? - Are there functions for converting Earth coordinate systems within the standard Anaconda installer?
 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM