PostGIS 多面(MultiPolygon)挖洞

现象

在应用过程中,“我认为的”,1个点明明落在了2个多面上,结果却不同。其实你会发现,坐标点的数据是一样的,但是定义的方法不同,导致结果不同。

--基础数据--
CREATE TABLE public.test_geometry_4490 (
	id serial4 NOT NULL PRIMARY KEY,
	geom public.geometry(geometry, 4490) NULL
);
--线行环(挖洞)
insert into test_geometry_4490 values (2,'MULTIPOLYGON (((1 5, 5 5, 5 1, 1 1, 1 5), (2 3,2 4,4 4,4 3,2 3)))')
--多面
insert into test_geometry_4490 values (1,'MULTIPOLYGON (((1 5, 5 5, 5 1, 1 1, 1 5)), ((2 3,2 4,4 4,4 3,2 3)))')


--查询--
select ST_Intersects(geom,ST_GeomFromText('POINT(3.5 3.5)',4490)) from test_geometry_4490

结果是:第一行不相交(挖洞了),第二行相交(多面以最大为主)。请继续往下看

1f
2t

可能只看坐标点不够直观,大家看下图

 其实使用web呈现来看,2个图是一样的,因为多面不管如何定义,转成web的geojson都一样,所以这也不怪web端。但是在数据库中的拓扑关系容不得一点马虎。

名词解释

postgis官方文档

4.1.1.4. 多边形(Polygon)

多边形是二维平面区域,它有一个外部边界(壳)和零个或多个内部边界(孔)分隔,每个边界都是线性环

POLYGON (
    (0 0 ,4 0 ,4 4 ,0 4 ,0 0 ),--多边形外环
    (1 1 ,2 1 ,2 2 ,1 2 ,1 1) --多边形内环
)

 通俗来说,这种多边形定义方式就是2个环,前面大,后面小,后面在前面的中间“挖洞”,“洞”里的空间不属于这个多边形。

如图所示,像这种“挖洞”的双环,大环是A边界,小环是B的边界,挖出的洞就是B边界内的空间。

所以说B空间内的区域,和这个多边形“不相交” 

这个多边形的面积就是A边界和B边界内的空间。

4.1.1.7. 多面(MultiPolygon)

多面是非重叠、不相邻多边形的集合。集合中的多边形只能在有限数量的点处接触。

注意,多面的定义有2种,

第1种是“挖洞”,就是上面Polygon多边形定义。

第2种定义是都个面。

他们的区别就是括号的位置。出现2对(())是一个图形。1对()就是“挖洞”多边形。

“挖洞”定义:

MULTIPOLYGON ((
    (0 0 ,4 0 ,4 4 ,0 4 ,0 0 ),--第一个多边形环
    (1 1 ,2 1 ,2 2 ,1 2 ,1 1)  --第二个多边形环
))

多面定义

MULTIPOLYGON (
    ((1 5, 5 5, 5 1, 1 1, 1 5)), --这是第一个多边形
    ((6 5, 9 1, 6 1, 6 5))     --这是第二个多边形
)

 多面定义意义在于,每个(())里面都是一个完整的多边形,这里定义了2个多边形。

如果定义的2个多边形存在包含,那么以做大的为主。

总结

引用chatgpt的回答,我觉得很准确。

所以这也解释了为什么,我的POINT落在2条“数据一样”的多面上,结果却不同。

  • 0
    点赞
  • 0
    收藏
    觉得还不错? 一键收藏
  • 0
    评论
Create and manage spatial data with PostGIS Key Features Import and export geographic data from the PostGIS database using the available tools Maintain, optimize, and fine-tune spatial data for long-term viability Utilize the parallel support functionality that was introduced in PostgreSQL 9.6 Book Description PostGIS is a spatial database that integrates the advanced storage and analysis of vector and raster data, and is remarkably flexible and powerful. PostGIS provides support for geographic objects to the PostgreSQL object-relational database and is currently the most popular open source spatial databases. If you want to explore the complete range of PostGIS techniques and expose related extensions, then this book is for you. This book is a comprehensive guide to PostGIS tools and concepts which are required to manage, manipulate, and analyze spatial data in PostGIS. It covers key spatial data manipulation tasks, explaining not only how each task is performed, but also why. It provides practical guidance allowing you to safely take advantage of the advanced technology in PostGIS in order to simplify your spatial database administration tasks. Furthermore, you will learn to take advantage of basic and advanced vector, raster, and routing approaches along with the concepts of data maintenance, optimization, and performance, and will help you to integrate these into a large ecosystem of desktop and web tools. By the end, you will be armed with all the tools and instructions you need to both manage the spatial database system and make better decisions as your project's requirements evolve. What you will learn Import and export geographic data from the PostGIS database using the available tools Structure spatial data using the functionality provided by a combination of PostgreSQL and PostGIS Work with a set of PostGIS functions to perform basic and advanced vector analyses Connect PostGIS with Python Learn to use programming frameworks around PostGIS Maintain, optimize, and fine-tune spatial data for long-term viability Explore the 3D capabilities of PostGIS, including LiDAR point clouds and point clouds derived from Structure from Motion (SfM) techniques Distribute 3D models through the Web using the X3D standard Use PostGIS to develop powerful GIS web applications using Open Geospatial Consortium web standards Master PostGIS Raster Who This Book Is For This book is for developers who need some quick solutions for PostGIS. Prior knowledge of PostgreSQL and spatial concepts would be an added advantage. Table of Contents Chapter 1. MOVING DATA IN AND OUT OF POSTGIS Chapter 2. STRUCTURES THAT WORK Chapter 3. WORKING WITH VECTOR DATA THE BASICS Chapter 4. WORKING WITH VECTOR DATA ADVANCED RECIPES Chapter 5. WORKING WITH RASTER DATA Chapter 6. WORKING WITH PGROUTING Chapter 7. Into the Nth Dimension Chapter 8. POSTGIS PROGRAMMING Chapter 9. POSTGIS AND THE WEB Chapter 10. MAINTENANCE OPTIMIZATION AND PERFORMANCE TUNING Chapter 11. USING DESKTOP CLIENTS Chapter 12. Introduction to Location Privacy Protection Mechanisms

“相关推荐”对你有帮助么?

  • 非常没帮助
  • 没帮助
  • 一般
  • 有帮助
  • 非常有帮助
提交
评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值