首先利用google earth,描出河段中心线,并导出kml文件
提取kml内的经纬度信息
import kml2geojson as k2g import geopandas as gpd import fiona import os import pandas as pd import numpy as np file_name = 'F:/CADfiles/river/river.kml' # google earth的kml文件路径 geoname = os.path.splitext(file_name)[0]+'.geojson' # 改变kml文件后缀名,转换为geopandas能够识别的json文件 file_outpath = 'F:/CADfiles/river/xy.xls' # 经纬度坐标输出的xls文件路径 fiona.drvsupport.supported_drivers['LIBKML'] = 'rw' #指明drivers,否则会报错 k2g.convert(file_name, geoname) # 利用kml2geojson程序库,将kml转为json文件 gdf = gpd.read_file(file_name, encoding='gbk') x_array = gdf['geometry'].apply(lambda geo: np.array([coord[0] for coord in geo.coords]))[0] #经度 y_array = gdf['geometry'].apply(lambda geo: np.array([coord[1] for coord in geo.coords]))[0] #纬度 z_array = gdf['geometry'].apply(lambda geo: np.array([coord[2] for coord in geo.coords]))[0] #高程值(大概 length = x_array.shape[0] xy = { "lon": pd.Series(x_array, index = np.arange(length)), "lat": pd.Series(y_array, index = np.arange(length)), } xy_df = pd.DataFrame(xy) xy_df.to_excel(file_outpath, sheet_name="Sheet1",index=False) #将经纬度输出到xls文件 print(xy_df)
将python生成的xls文件导入arcmap,并查看属性信息
提取成功!