python读取excel经纬度并在地图上显示
时间: 2023-04-04 16:01:06 浏览: 1251
可以使用 pandas 库中的 read_excel() 方法读取 excel 文件中的经纬度数据,然后使用 folium 库中的 Map() 方法创建地图,并使用 Marker() 方法在地图上标记经纬度位置。具体实现方法可以参考相关教程和文档。
相关问题
用python读取excel中的经纬度和航向,用不同颜色分别绘制出向南和向北的路线
可以使用Python中的pandas和matplotlib库来读取excel中的经纬度和航向,并绘制向南和向北的路线。具体实现方式可以参考以下代码:
```
import pandas as pd
import matplotlib.pyplot as plt
# 读取excel文件中的数据
df = pd.read_excel('data.xlsx')
# 根据航向分类,分别绘制向南和向北的路线
north_df = df[df['航向'] >= 0]
south_df = df[df['航向'] < 0]
# 绘制向南的路线
plt.plot(south_df['经度'], south_df['纬度'], color='red')
# 绘制向北的路线
plt.plot(north_df['经度'], north_df['纬度'], color='blue')
# 显示图形
plt.show()
```
注意,此代码只是一个示例,具体实现方式要根据你的数据格式和需求进行调整。
通过Python读取Excel表中某一列的经纬度坐标,并将多组经纬度坐标生成多个矢量面文件
要通过Python读取Excel表中某一列的经纬度坐标,并将多组经纬度坐标生成多个矢量面文件,您可以使用pandas库来读取Excel文件,并结合GDAL库来生成矢量面文件。下面是一个示例代码:
```python
import pandas as pd
from osgeo import ogr
# 读取Excel文件
data = pd.read_excel('input.xlsx')
# 获取经纬度列数据
lon_lat_data = data['经纬度']
# 遍历每组经纬度坐标
for i, coordinates in enumerate(lon_lat_data):
# 创建Shapefile数据源
driver = ogr.GetDriverByName('ESRI Shapefile')
data_source = driver.CreateDataSource(f'output_{i}.shp')
# 创建图层
layer = data_source.CreateLayer('polygon', geom_type=ogr.wkbPolygon)
# 创建字段
field_defn = ogr.FieldDefn('id', ogr.OFTInteger)
layer.CreateField(field_defn)
# 创建多边形
ring = ogr.Geometry(ogr.wkbLinearRing)
# 分割经纬度坐标
coordinates = coordinates.split(';')
# 添加经纬度坐标点
for coordinate in coordinates:
lon, lat = coordinate.split(',')
ring.AddPoint(float(lon), float(lat))
# 创建多边形对象
polygon = ogr.Geometry(ogr.wkbPolygon)
polygon.AddGeometry(ring)
# 创建要素
feature_defn = layer.GetLayerDefn()
feature = ogr.Feature(feature_defn)
feature.SetGeometry(polygon)
feature.SetField('id', i+1)
# 将要素添加到图层
layer.CreateFeature(feature)
# 清理资源
feature = None
data_source = None
```
请将代码中的'input.xlsx'替换为您实际的Excel文件路径。此示例代码假设Excel文件中有一列名为'经纬度',其中包含多个经纬度坐标,每个经纬度坐标之间使用分号进行分隔,经度和纬度之间使用逗号进行分隔。
代码将遍历每组经纬度坐标,为每组坐标创建一个单独的Shapefile文件,文件名将使用索引编号进行命名,例如"output_0.shp","output_1.shp"等。
请确保已安装pandas和GDAL库,可以使用以下命令进行安装:
```
pip install pandas
pip install gdal
```
注意:在使用GDAL库之前,还需要安装GDAL的Python绑定,可以通过Anaconda进行安装,或者下载GDAL二进制文件进行安装。
阅读全文
相关推荐














