地理空间文件格式:shapefile(最常见)、GeoJSON、KML和GPKG

文件读取

# Read in the data
full_data = gpd.read_file("../input/geospatial-learn-course-data/DEC_lands/DEC_lands/DEC_lands.shp")# View the first five rows of the data
full_data.head()

坐标参考系由欧洲石油勘探集团(EPSG)规范引用。

这个GeoDataFrame使用的是EPSG 32630,它通常被称为“墨卡托”投影。此投影保留角度(使其对航海有用)并稍微扭曲区域。

但是,当从CSV文件创建GeoDataFrame时,我们必须设置CRS。EPSG 4326对应于经纬度坐标。

# Create a DataFrame with health facilities in Ghana
facilities_df = pd.read_csv("../input/geospatial-learn-course-data/ghana/ghana/health_facilities.csv")# Convert the DataFrame to a GeoDataFrame
facilities = gpd.GeoDataFrame(facilities_df, geometry=gpd.points_from_xy(facilities_df.Longitude, facilities_df.Latitude))# Set the coordinate reference system (CRS) to EPSG 4326
facilities.crs = {'init': 'epsg:4326'}

DataFrame常用参数

regions.geometry.length # 线长度
regions.geometry.area # 区域面积

画图

静态

# 1.简单的图层叠加
# Define a base map with county boundaries
ax = counties.plot(figsize=(10,10), color='none', edgecolor='gainsboro', zorder=3) # Add wild lands, campsites, and foot trails to the base map
wild_lands.plot(color='lightgreen', ax=ax)
campsites.plot(color='maroon', markersize=2, ax=ax)
trails.plot(color='black', markersize=1, ax=ax)# 2.考虑坐标参考的一致性
ax = regions.plot(figsize=(8,8), color='whitesmoke', linestyle=':', edgecolor='black')
facilities.to_crs(epsg=32630).plot(markersize=1, ax=ax)

交互式地图

相关参数:

  • location 地图最中心的位置
  • tiles 地图的样式
  • zoom_start 初始的放大倍数,越大越接近原地图
# 1.地图背景
m_1 = folium.Map(location=[42.32,-71.0589], tiles='openstreetmap', zoom_start=10)
# Display the map
m_1# 2.标记图
m_2 = folium.Map(location=[42.32,-71.0589], tiles='cartodbpositron', zoom_start=13)
# Add points to the map
for idx, row in daytime_robberies.iterrows():Marker([row['Lat'], row['Long']]).add_to(m_2)
# Display the map
m_2# 3.可变化的标记图
# Create the map
m_3 = folium.Map(location=[42.32,-71.0589], tiles='cartodbpositron', zoom_start=13)
# Add points to the map
mc = MarkerCluster()
for idx, row in daytime_robberies.iterrows():if not math.isnan(row['Long']) and not math.isnan(row['Lat']):mc.add_child(Marker([row['Lat'], row['Long']]))
m_3.add_child(mc)
# Display the map
m_3# 4.圆点图
m_4 = folium.Map(location=[42.32,-71.0589], tiles='cartodbpositron', zoom_start=13)
def color_producer(val):if val <= 12:return 'forestgreen'else:return 'darkred'
# Add a bubble map to the base map
for i in range(0,len(daytime_robberies)):folium.Circle(location=[daytime_robberies.iloc[i]['Lat'], daytime_robberies.iloc[i]['Long']],radius=20,color=color_producer(daytime_robberies.iloc[i]['HOUR'])).add_to(m_4)
# Display the map
m_4# 5.热图
m_5 = folium.Map(location=[42.32,-71.0589], tiles='cartodbpositron', zoom_start=12)
# Add a heatmap to the base map
HeatMap(data=crimes[['Lat', 'Long']], radius=10).add_to(m_5)
# Display the map
m_5# 6.分级统计图
m_6 = folium.Map(location=[42.32,-71.0589], tiles='cartodbpositron', zoom_start=12)
# Add a choropleth map to the base map
Choropleth(geo_data=districts.__geo_interface__, # 传入geojsondata=plot_dict,  # 染色数据区域key_on="feature.id",  # geojson区域idfill_color='YlGnBu',  # 颜色样式legend_name='Major criminal incidents (Jan-Aug 2018)' # 图例名).add_to(m_6)
# Display the map
m_6


由于图片未加载完全,所以后面5张图注重效果,不注重背景,请您谅解

地理编码

地理编码是将一个地方或地址的名称转换为地图上的一个位置的过程,以下是其代码实现

# 基本使用:提供地址名称和地理供应者,得到地址的经纬度和包含完整地址的信息
from geopandas.tools import geocode
result = geocode("The Great Pyramid of Giza", provider="nominatim")
result

实操如下:

# 加载欧洲前100大学的名称
universities = pd.read_csv("../input/geospatial-learn-course-data/top_universities.csv")def my_geocoder(row):try:point = geocode(row, provider='nominatim').geometry.iloc[0]return pd.Series({'Latitude': point.y, 'Longitude': point.x, 'geometry': point})except:return Noneuniversities[['Latitude', 'Longitude', 'geometry']] = universities.apply(lambda x: my_geocoder(x['Name']), axis=1)print("{}% of addresses were geocoded!".format((1 - sum(np.isnan(universities["Latitude"])) / len(universities)) * 100))# Drop universities that were not successfully geocoded
universities = universities.loc[~np.isnan(universities["Latitude"])]
universities = gpd.GeoDataFrame(universities, geometry=universities.geometry)
universities.crs = {'init': 'epsg:4326'}

DataFrame的属性连接和空间连接

有关地理坐标的属性连接(信息合并)最好使用gpd.GeoDataFrame.merge()的方法,如下所示

# 已知欧洲城市地理边界和相关统计信息europe_boundaries.head()和europe_stats.head()
# 对两个数据DataFrame进行信息合并
europe = europe_boundaries.merge(europe_stats, on="name")
europe.head()


空间连接即通过地理空间位置来进行匹配

如使用空间连接来将每个大学与相应的国家匹配,用gpd.sjoin()的方法,如下所示

# Use spatial join to match universities to countries in Europe
european_universities = gpd.sjoin(universities, europe)# Investigate the result
print("We located {} universities.".format(len(universities)))
print("Only {} of the universities were located in Europe (in {} different countries).".format(len(european_universities), len(european_universities.name.unique())))european_universities.head()

邻近性分析

# 测量两点间距离
distances = stations.geometry.distance(recent_release.geometry)# 创建缓冲区
two_mile_buffer = stations.geometry.buffer(2*5280)

【Kaggle 学习笔记】 | Geospatial Analysis相关推荐

  1. kaggle学习笔记——说是草稿纸也行

    文章目录 前言 主要内容 数据的导入和导出 查看数据的基础属性 对数据的简单预处理 对数字特征(numerical)列的处理 对分类特征(categorical)列的处理 流程化处理 XGBoost ...

  2. kaggle学习笔记-otto-baseline8-候选生成 + LGBM 排名器模型

    简介 我们尝试开发一个两阶段模型,其中包括候选生成模型(共同访问矩阵)和排名模型.这种做法自候选人一代以来在大型科技公司中广泛使用 应该注意的是,候选生成模型应以高召回率为目标,而排名模型应以最相关的 ...

  3. ES权威指南[官方文档学习笔记]-57 Analysis and analyzers

    2019独角兽企业重金招聘Python工程师标准>>> es:http://www.elasticsearch.org/guide/en/elasticsearch/guide/cu ...

  4. [ML学习笔记] 回归分析(Regression Analysis)

    [ML学习笔记] 回归分析(Regression Analysis) 回归分析:在一系列已知自变量与因变量之间相关关系的基础上,建立变量之间的回归方程,把回归方程作为算法模型,实现对新自变量得出因变量 ...

  5. 【学习笔记】kaggle案例之泰坦尼克号(基于R)

    kaggle案例之泰坦尼克号(基于R) 泰坦尼克号案例 数据预处理 决策树模型建立 泰坦尼克号案例 泰坦尼克号数据集为1912年泰坦尼克号撞击冰山沉没事件中一些乘客和船员的个人信息及是否幸存的状况.可 ...

  6. PCA(主成分分析-principal components analysis)学习笔记以及源代码实战讲解

    PCA(主成分分析-principal components analysis)学习笔记以及源代码实战讲解 文章目录 PCA(主成分分析-principal components analysis)学 ...

  7. 机器学习 cs229学习笔记4 EM for factor analysis PCA(Principal comp

    ============================================================================= EM FOR FACTOR ANALYSIS ...

  8. Kaggle教程 机器学习入门学习笔记

    机器学习入门学习笔记 [跳转]<Kaggle教程 机器学习入门>系列课程目录 >> 决策树 简介:是在已知各种情况发生概率的基础上,通过构成决策树来求取净现值的期望值大于等于零 ...

  9. 计算机视觉系列-全球小麦检测Kaggle比赛学习笔记(7)

    全球小麦检测-你能用图像分析帮助识别麦穗吗? 打开你的储藏室,你可能会发现一些小麦制品.事实上,你的早餐吐司或谷类食品可能依赖于这种普通谷物.它作为一种食品,使小麦得到广泛的研究.为了获得全球范围内麦 ...

最新文章

  1. SAP MM UB类型STO不能转供应商寄售库存?
  2. Fatal error:SQL Server 不存在或拒绝访问。
  3. [轉]JavaScript获取HTML DOM父,子,临近节点
  4. SQL注入之布尔盲注——sql-lab第八关
  5. python堆堆乐教程_python堆排序,详细过程图和讲解,这样做小白都会
  6. NYOJ 229 工程 二分+dp检验
  7. pstools psexec 执行文件
  8. Java面向对象入门
  9. thinkphp多表查询两表有重复相同字段解决方法
  10. Java中的Thread.sleep()– Java线程睡眠
  11. HDU 1512 Monkey King(左偏树模板题)
  12. long8.cc app.html,Potoshop 长投影扩展插件 Long Shadow Generator 支持CS6-CC2015
  13. 稚辉君的Clion搭建STM32教程的自己实现,以及相关记录
  14. 微信公众号如何上传文档附件_公众号添加Excel、PDF、PPT等附件教程
  15. cadence virtuoso画版图提示LUP.6错误
  16. Qt发布版本退出时错误处理“The inferior stopped because it received a signal from the operating system.”
  17. python 调试,Python 学习入门--pydev调试
  18. 频谱分析系列:1dB增益压缩点概述及测试
  19. Docker-镜像的优化
  20. Unity 多重材质球替换、多重材质球特定贴图替换、Materials替换

热门文章

  1. 自建 | gma库更新日志
  2. 怎么导入ARV和MRC的demo
  3. TCP拒绝服务攻击简述与实验
  4. 退役狗的高三生活-OI无关项
  5. Virtual Judge使用介绍
  6. 网易七鱼 web快速接入
  7. 蜗牛外挂 计算机的端口关闭资料
  8. [PaddleSpeech] 音色克隆之原神角色 <胡桃>
  9. C#中各种问号的使用
  10. 1168 -- 奋斗的小蜗牛