Skip to Content
Python 用于地理空间数据分析
book

Python 用于地理空间数据分析

by Bonny P. McClain
May 2025
Intermediate to advanced
282 pages
4h 2m
Chinese
O'Reilly Media, Inc.
Content preview from Python 用于地理空间数据分析

第 7 章 GeoPandas 和空间统计

本作品已使用人工智能进行翻译。欢迎您提供反馈和意见:translation-feedback@oreilly.com

地图是美丽的。它们所讲述的故事可以如此吸引人,以至于人们很容易无意中忽略了其中的地理空间统计数据。但地理空间地图并不是简单的静态图像。它们中蕴含着信息,如 GIS 图层中与特定特征相关的属性或光栅图像中观察到的像素密度。

Python 有多种用于处理地理空间数据的软件包。如果你熟悉 Python,那么你可能知道Pandas,这是一个专门为 Python 开发的数据分析工具。 Pandas 允许我们将各种数据类型读入数据帧:一组包含行(表示记录)和列(表示属性)的表格。GeoPandas是 pandas 的扩展,可以让您使用所谓的GeoDataFrame(地理数据帧)来处理几何和地理空间数据地理空间数据帧中的每一行都是一个空间特征,如点、线或多边形。

本章将向您介绍如何使用 GeoPandas 和 GeoDataFrames 以及其他一些重要软件包(如用于可视化数据的matplotlib和人口普查数据 API)分析数据和创建地图。您还将学习如何访问地理空间文件,并通过创建和比较人口分布图深入研究人口数据。

安装 GeoPandas

要安装 GeoPandas,需要在终端中使用condaconda-forge 。 与前几章一样,我还将向你展示如何为处理本章数据所需的所有文件创建一个环境。

安装 GeoPandas 可能有点棘手。把它想象成一个喜怒无常的青少年。它经常想先下手为强(导入),喜欢最新的潮流(注意依赖关系的版本)。它还喜欢一个响亮的昵称:通常,GeoPandas 被称为gpd ,但有时代码会写出geopandas 。请注意并调整您的变量。

要设置 环境,请从以下步骤开始:

conda create --name geop_env python = 3.X 

您可以在这里添加您的 Python 版本。

MacBook-Pro-8:~ USERNAME$ conda activate geop_env

现在,您可以开始将文件安装到geop_env

conda install -c conda-forge geopandas

现在,您可以添加任何想访问的软件包到geop_env 。如果你想要地理空间分析软件包集,我建议你下载地理空间软件包,但 ,如果你愿意,现在可以单独添加软件包:

conda install -c conda-forge geospatial

GeoPandas 简化了在 Python 中处理地理空间数据的工作。让我们来探索扩展操作,让您能够对几何数据执行空间操作。

使用 GeoJSON 文件

GeoPandas 可让您处理 GeoJSON 文件。您可能听说过 JSON 这种常见的数据交换格式。GeoJSON 是一种基于 JSON 的数据交换格式,专门用于表示地理数据结构及其非空间属性。使用 GeoJSON 文件可以非常简单地确定地图的坐标和位置。

图 7-1显示了来自geojson.io 的地图。Geojson.io是一款开源工具,可简化地图的创建、查看和共享。您可以在互联网上执行各种功能,而无需向计算机下载任何数据。

Zooming in on Paris’s 1st Arrondissement and selecting boundaries to create a GeoJSON file
图 7-1. 放大巴黎第一区并选择边界以创建 ...
Become an O’Reilly member and get unlimited access to this title plus top books and audiobooks from O’Reilly and nearly 200 top publishers, thousands of courses curated by job role, 150+ live events each month,
and much more.

Read now

Unlock full access

More than 5,000 organizations count on O’Reilly

AirBnbBlueOriginElectronic ArtsHomeDepotNasdaqRakutenTata Consultancy Services

QuotationMarkO’Reilly covers everything we've got, with content to help us build a world-class technology community, upgrade the capabilities and competencies of our teams, and improve overall team performance as well as their engagement.
Julian F.
Head of Cybersecurity
QuotationMarkI wanted to learn C and C++, but it didn't click for me until I picked up an O'Reilly book. When I went on the O’Reilly platform, I was astonished to find all the books there, plus live events and sandboxes so you could play around with the technology.
Addison B.
Field Engineer
QuotationMarkI’ve been on the O’Reilly platform for more than eight years. I use a couple of learning platforms, but I'm on O'Reilly more than anybody else. When you're there, you start learning. I'm never disappointed.
Amir M.
Data Platform Tech Lead
QuotationMarkI'm always learning. So when I got on to O'Reilly, I was like a kid in a candy store. There are playlists. There are answers. There's on-demand training. It's worth its weight in gold, in terms of what it allows me to do.
Mark W.
Embedded Software Engineer

You might also like

实用 Linux 系统管理

实用 Linux 系统管理

Kenneth Hess
ppk on JavaScript

ppk on JavaScript

Peter-Paul Koch
高效R语言编程

高效R语言编程

Colin Gillespie, Robin Lovelace

Publisher Resources

ISBN: 9798341659025