0

我是 Python 和 QGIS 的新手,我正在尝试编写一个用于 QGIS v3.6.0 的 Python 插件。

我正在尝试使用 QgsDistanceArea().convertLengthMeasurement 转换测量值

我尝试使用此链接中的代码(滚动到接近末尾的提示#2)https://www.e-education.psu.edu/geog489/node/2360

qda = QgsDistanceArea()
qda.setEllipsoid('EPSG') #not sure if this is required (the project CRS is EPSG:27700)

#set input measurement
m = 1000 #not sure if the unit type needs to be set

#convert the measurement
converted = qda.convertLengthMeasurement(m, QgsUnitTypes.DistanceKilometers)

print("measure: ", m)
print("converted: ", converted)

我希望输出是:

m: 1000
converted: 1

但实际输出是:

m: 1000
converted: 111319.49079327358

在 QGIS v2 中,convertLengthMeasurement 似乎需要一个参数来描述输入单元类型。但是在 QGIS v3(​​我正在使用的版本)中,只需要输出单元类型。

我知道我可以简单地除以 1000 来将米转换为公里,但我想使用 convertLengthMeasurement。

任何帮助将非常感激。

4

1 回答 1

0

经过进一步搜索,EPSG:27700 似乎使用 WGS84 椭球。“EPSG”不是有效的 ellipsoidAcronym。

添加以下行:

qda.setEllipsoid('WGS84')

似乎使它正常工作。

于 2019-09-10T13:32:27.013 回答