Warning: file_get_contents(/data/phpspider/zhask/data//catemap/2/python/352.json): failed to open stream: No such file or directory in /data/phpspider/zhask/libs/function.php on line 167

Warning: Invalid argument supplied for foreach() in /data/phpspider/zhask/libs/tag.function.php on line 1116

Notice: Undefined index: in /data/phpspider/zhask/libs/function.php on line 180

Warning: array_chunk() expects parameter 1 to be array, null given in /data/phpspider/zhask/libs/function.php on line 181

Warning: file_get_contents(/data/phpspider/zhask/data//catemap/4/wpf/14.json): failed to open stream: No such file or directory in /data/phpspider/zhask/libs/function.php on line 167

Warning: Invalid argument supplied for foreach() in /data/phpspider/zhask/libs/tag.function.php on line 1116

Notice: Undefined index: in /data/phpspider/zhask/libs/function.php on line 180

Warning: array_chunk() expects parameter 1 to be array, null given in /data/phpspider/zhask/libs/function.php on line 181
Python 距离单位_Python_Distance_Units Of Measurement_Gdal_Ogr - Fatal编程技术网

Python 距离单位

Python 距离单位,python,distance,units-of-measurement,gdal,ogr,Python,Distance,Units Of Measurement,Gdal,Ogr,我使用Python中的OGR距离来确定点和线之间的最短距离。我的结果与使用QGIS得到的结果完全不同。我假设OGR使用的单位取决于坐标系?可能是OGR使用学位吗?如果是这样的话,我怎样才能把这些转换成米呢? 我的代码如下所示: import ogr driver = ogr.GetDriverByName('ESRI Shapefile') roads = driver.Open('G:/Basedata/OR/infra/TigerRoads2010/OR_TIGERroads_2010_

我使用Python中的OGR距离来确定点和线之间的最短距离。我的结果与使用QGIS得到的结果完全不同。我假设OGR使用的单位取决于坐标系?可能是OGR使用学位吗?如果是这样的话,我怎样才能把这些转换成米呢? 我的代码如下所示:

import ogr

driver = ogr.GetDriverByName('ESRI Shapefile')

roads = driver.Open('G:/Basedata/OR/infra/TigerRoads2010/OR_TIGERroads_2010_merge.shp', 0)
point = driver.Open('U:/My Documents/Tool/shp/testareacentro.shp', 0)

roadslayer = roads.GetLayer()
pointl = point.GetLayer()

roadsfeature = roadslayer.GetNextFeature()
pointf = pointl.GetNextFeature()

roadgeom = roadsfeature.GetGeometryRef()
pointgeom = pointf.GetGeometryRef()

dist = pointgeom.Distance(roadgeom)

print dist

我的距离变短的原因是因为我只比较了第一个特征。 该代码将给出与QGIS中相同的结果:

import ogr

driver = ogr.GetDriverByName('ESRI Shapefile')

lineshp = driver.Open('U:/My Documents/Tool/shp/line.shp', 0)
linelyr = lineshp.GetLayer()

pointshp = driver.Open('U:/My Documents/Tool/shp/point.shp', 0)
pointlyr = pointshp.GetLayer()

linefeat = linelyr.GetNextFeature()
pointfeat = pointlyr.GetNextFeature()

point_geom = pointfeat.GetGeometryRef()

distlist = []
while linefeat:
    line_geom = linefeat.GetGeometryRef()
    dist = point_geom.Distance(line_geom)
    distlist.append(dist)
    linefeat.Destroy()
    linefeat = linelyr.GetNextFeature()

print min(distlist)

我希望这些单位是输入的单位。我怎样才能知道输入的单位是什么?你必须看看输入是从哪里来的。如果以元组形式给出一个点,数字代表什么?该点是一个形状文件。数据源和/或其文档应指定形状文件中坐标的含义。