Skip to Content
使用 Apache Sedona 进行云原生地理空间分析 (Chinese Edition)
book

使用 Apache Sedona 进行云原生地理空间分析 (Chinese Edition)

by Pawel Tokaj, Jia Yu, Mo Sarwat
December 2025
Beginner to intermediate
325 pages
4h 23m
Chinese
O'Reilly Media, Inc.
Content preview from 使用 Apache Sedona 进行云原生地理空间分析 (Chinese Edition)

第三章·将 地理空间数据加载到Apache Sedona

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

多年来,的shapefile格式一直是主要的地理空间文件格式。对于小型数据集以及在本地机器上分析数据时,它表现良好。然而随着现代技术快速发展和数据量激增,shapefile因无法支持数组等复杂数据类型、文件维护困难、缩放问题、列名限制等多重缺陷,已难以满足需求。 为突破shapefile瓶颈,业界尝试引入的GeoJSON和的GeoPackage等新格式。这些格式在特定场景下适用,但同样存在局限。近年来,GeoParquet作为地理空间分析数据存储标准崭露头角,成功激活了Apache Parquet和Apache Iceberg格式原生的地理空间支持能力。

任何成熟的分析系统都必须支持用户从最常见的数据格式加载数据,Sedona 提供了这一能力。然而,此处提及的部分数据格式并未针对分布式系统进行优化设计。

本章将探讨地理空间数据格式的核心原理,包括二进制格式与文本格式等数据序列化技术,并分析在分布式环境中高效处理数据时应选用何种格式。

本章前半部分将探讨存储表格化向量数据格式的挑战,随后回顾向量数据序列化技术,并解析Apache Sedona如何实现其内部数据模型的序列化。最后将分步演示如何将主流向量数据格式加载至空间数据框。

第二部分聚焦栅格数据格式,重点讲解如何将GeoTIFF文件加载至Apache Sedona。该部分最后一个示例将展示如何在Apache Sedona中轻松融合栅格与向量数据。

从数据库读取数据是数据工程领域常见任务,第三部分将对此进行阐述。本章最后将实践所学知识,为纽约出租车数据集编写分析代码。

加载向量数据格式

存储地理空间数据固然困难,但精炼描述这类数据更为棘手。考虑到可能需要分析数据框中的数十亿条记录,我们必须确保数据写入速度相对较快,同时尽可能减少网络传输和磁盘存储所需的空间。存储地理空间数据时存在若干复杂性:

  • 巨型多边形或线串可能包含的点数。

  • 存储多维数据。

  • 在复杂几何形状中,多边形可能包含多个孔洞,这些都需要进行编码处理。

  • 多种几何类型:点、多边形、线串、圆、三角形。

  • 坐标参考系统(CRS)(不同CRS的数据不可直接比较)。

在逐步讲解如何将数据加载到地理空间数据框之前,我们将介绍常用的地理空间 序列化方法,以及Apache Sedona如何适配这些技术。理解这些常用方法至关重要,因为当您处理不熟悉且Sedona不支持的数据源时,它们可能提供重要帮助。

本书中"加载"与"读取"可互换使用。

向量数据序列化

向量数据序列化是将地理空间对象转换为字节数组的过程。向量数据的两种主流存储方式是:广义文本(WKT) 和广义二进制(WKB)。开放地理空间联盟(OGC)最初在其简单特征访问规范中定义并描述了这些格式。当前标准定义见于ISO/IEC 13249-3:2016 标准。

WKT采用字符串以简洁易读的方式表示几何图形,可描述二维、三维或四维空间中的多边形、多线串或点等对象。

WKT字符串示例如下:

LINESTRING (
  20.9972017 52.1696936,
  20.9971687 52.1696659,
  20.997156 52.169644,
  20.9971487 52.1696213
)

因篇幅限制,我们不得不将WKT字符串拆分为多行;多数库可解析此格式,但并非全部。

WKB采用二进制格式表示地理空间数据,有助于缩减存储和传输数据的体积。它支持多种形状,如多边形、线串、点、圆、曲线等。WKB还能存储坐标参考系统(CRS)信息,与WKT类似,其扩展版本以E为前缀(如EWKB、EWKT)。 ...

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

What Successful Brick-and-Mortar Retailers Get Right

What Successful Brick-and-Mortar Retailers Get Right

Rob Angell
A Five-Step Guide to Improving Your Employer Brand

A Five-Step Guide to Improving Your Employer Brand

Kimberly A. Whitler, Richard Mosley
Three Essentials for Agentic AI Security

Three Essentials for Agentic AI Security

Paolo Dal Cin, Daniel Kendzior, Yusof Seedat, Renato Marinho
What Successful Project Managers Do

What Successful Project Managers Do

W. Scott Cameron, Jeffrey S. Russell, Edward J. Hoffman, Alexander Laufer

Publisher Resources

ISBN: 0642572292300