转换点几何到列表

2024-09-30 16:41:36 发布

您现在位置:Python中文网/ 问答频道 /正文

我有以下脚本来创建点几何体。如何将此点几何图形转换为仅包含坐标的列表,使其看起来像[258432.79138201929, 1001957.4394514663]?在

>>> import ogr
>>> driver = ogr.GetDriverByName('ESRI Shapefile')
>>> pointshp = driver.Open('U:/My Documents/Tool/shp/point.shp', 0)

>>> pointlyr = pointshp.GetLayer()

>>> point_geom = point.GetGeometryRef()

>>> print point_geom

POINT (258432.79138201929 1001957.4394514663)

Tags: import脚本列表mydriveropendocumentspoint
2条回答

通常点对象具有xyz坐标。在

[point_geom.x, point_geom.y]

假设点geom是"POINT (258432.79138201929 1001957.4394514663)"(即字符串)

您可以:

map(float,point_geom[7:-1].split(' '))

point_geom[7:-1]给出{} point_geom[7:-1].split(' ')给出{} map(float,point_geom[7:-1].split(' '))将字符串强制为浮点

相关问题 更多 >