GIS Intersection是什么
Intersection(相交)是GIS空间分析和空间叠加分析中非常重要的一种操作。
它用于计算两个Geometry之间共同存在的空间部分。
简单来说:
Intersection就是找出两个空间对象重叠或者共同存在的部分。
例如两个Polygon:
Polygon A
┌──────────────┐
│ │
│ ┌──────────────┐
│ │ │ │
└───────┼──────┘ │
│ │
└──────────────┘
Polygon B
执行:
Intersection(A, B)
得到:
┌───────┐
│ │
│共同区域│
│ │
└───────┘
也就是:
两个Geometry共同拥有的空间部分。
Intersection能够做什么
Intersection常用于:
- 空间叠加分析
- 区域重叠分析
- 土地利用分析
- 行政区分析
- 道路影响范围分析
- 河流保护区分析
- 地理围栏
- 空间查询
- GIS数据裁剪
例如:
找出城市建设用地与行政区的重叠区域。
可以:
建设用地
↓
Intersection
↑
行政区
↓
共同区域
Intersection的基本原理
Intersection的核心流程:
Geometry A
+
Geometry B
↓
Intersection
↓
共同空间部分
可以理解成集合中的:
A ∩ B
其中:
∩
表示两个集合的交集。
因此:
GIS中的Intersection本质上就是Geometry空间集合的交集运算。
Polygon与Polygon Intersection
Polygon与Polygon是Intersection最常见的场景。
例如:
Polygon A
┌───────────────┐
│ │
│ ┌────────┼────────┐
│ │ │ │
└──────┼────────┘ │
│ │
└─────────────────┘
Polygon B
执行:
Intersection(A, B)
得到:
┌────────┐
│ │
│共同区域│
│ │
└────────┘
结果就是两个Polygon重叠的区域。
Polygon与Polygon的典型应用
例如:
找出洪水风险区与居民区的重叠部分。
数据:
洪水风险区
+
居民区
执行:
Intersection
得到:
受洪水影响的居民区域
可以进一步计算:
面积
人口
建筑数量
Polygon与LineString Intersection
Polygon与LineString也可以执行Intersection。
例如:
│
│
│
────────┼────────
│
│
│
假设:
Polygon
是一个区域:
┌──────────────┐
│ │ │
│ │ │
│ │ │
└──────────────┘
Line
执行Intersection后:
│
│
│
得到的可能是:
LineString
即:
LineString位于Polygon内部的部分。
Polygon与LineString的应用
例如:
找出穿过某个行政区的道路。
流程:
道路
+
行政区
↓
Intersection
↓
行政区内部道路
还可以用于:
- 河流穿越行政区
- 铁路穿越保护区
- 管线穿越地块
- 道路穿越规划区
Polygon与Point Intersection
Point与Polygon进行Intersection时,结果取决于Point是否位于Polygon空间范围内。
例如:
┌──────────────┐
│ │
│ ● │
│ │
└──────────────┘
Point位于Polygon内部:
Intersection
↓
Point
如果Point位于Polygon外:
Intersection
↓
Empty Geometry
因此:
Point与Polygon的Intersection可以用于提取位于区域内的点。
Point与Point Intersection
两个完全相同的Point执行Intersection:
Point A
●
Point B
●
如果位置完全相同:
Intersection
↓
Point
如果位置不同:
● A
● B
则:
Intersection
↓
Empty
LineString与LineString Intersection
两条线可能:
相交
例如:
/
/
────●────
/
/
Intersection可能得到:
Point
因为两条线共同存在的空间位置是一个点。
也可能两条线存在重叠:
────────────
────────────
这种情况下Intersection可能得到:
LineString
因此:
Intersection的结果Geometry类型取决于两个输入Geometry实际相交的方式。
Intersection结果类型
Intersection不是固定返回Polygon。
例如:
Polygon ∩ Polygon
↓
Polygon
Polygon ∩ LineString
↓
LineString
Polygon ∩ Point
↓
Point
LineString ∩ LineString
↓
Point / LineString
如果没有共同空间部分:
Intersection
↓
Empty Geometry
因此:
Intersection的输出类型取决于输入Geometry以及它们之间的空间关系。
Intersection与Intersects的区别
这是GIS中非常容易混淆的一组概念。
Intersects
Intersects是一个空间关系判断。
它回答:
两个Geometry是否相交?
例如:
Intersects(A, B)
返回:
true
或者:
false
Intersection
Intersection是一个空间几何运算。
它回答:
两个Geometry相交的具体部分是什么?
例如:
Intersection(A, B)
返回:
Geometry
所以:
Intersects
↓
true / false
而:
Intersection
↓
Geometry
可以简单记住:
Intersects负责判断,Intersection负责计算结果。
Intersection与Contains
Contains回答:
A是否包含B?
例如:
┌──────────────┐
│ ● │
│ │
└──────────────┘
Contains(A, B)
↓
true
而Intersection:
Intersection(A, B)
↓
Point
所以:
Contains
↓
空间关系判断
Intersection
↓
空间几何结果
Intersection与Within
Within回答:
A是否位于B内部?
例如:
Point
●
↓
Polygon
Within(Point, Polygon)
↓
true
而Intersection:
Intersection(Point, Polygon)
↓
Point
Intersection与Touches
Touches表示两个Geometry接触边界,但内部没有共同区域。
例如:
┌────────┐┌────────┐
│ A ││ B │
└────────┘└────────┘
二者边界接触:
Touches
↓
true
Intersection可能得到:
LineString
或者:
Point
取决于接触方式。
因此:
两个Geometry存在Intersection并不一定意味着它们有面积重叠。
Intersection与Overlaps
Overlaps表示两个同维度Geometry存在部分重叠,但彼此都不是完全包含对方。
例如:
┌────────────┐
│ A │
│ ┌────────────┐
└──────┤ B │
└────────────┘
存在共同区域:
A ∩ B
所以:
Overlaps
↓
true
同时:
Intersection
↓
共同区域
Intersection与Difference
Intersection:
A ∩ B
得到:
A和B共同部分。
Difference:
A - B
得到:
A中不属于B的部分。
例如:
A
┌──────────────┐
│ ┌──────┼──────┐
│ │ B │ │
└───────┴──────┘ │
└─────────────┘
Intersection:
共同区域
Difference:
A中除去共同区域后的部分
因此:
Intersection
↓
共同部分
Difference
↓
剩余部分
Intersection与Union
Union表示两个Geometry的并集。
例如:
A
┌────────┐
│ │
└────────┘
B
┌────────┐
│ │
└────────┘
Intersection:
A ∩ B
只保留重叠部分。
Union:
A ∪ B
保留两个Geometry全部区域,并将重叠部分合并。
因此:
Intersection
↓
重叠部分
Union
↓
全部部分
Intersection与Symmetric Difference
Symmetric Difference表示:
A和B中不属于两者共同部分的区域。
集合关系:
A △ B
可以理解为:
Union
-
Intersection
即:
(A ∪ B) - (A ∩ B)
因此常见Overlay操作可以理解为:
Union
Intersection
Difference
Symmetric Difference
Intersection与Buffer
Buffer和Intersection经常组合使用。
例如:
找出道路100米范围内的建筑。
第一步:
Road
↓
Buffer 100m
得到:
Road Buffer
第二步:
Road Buffer
+
Buildings
↓
Intersection
得到:
道路100米范围内的建筑
因此典型流程:
Road
↓
Buffer
↓
Polygon
↓
Intersection
↓
Buildings
Intersection与空间裁剪
Intersection也经常用于Clip操作。
例如:
全国道路数据
+
北京市行政区
↓
Intersection
↓
北京市道路
也就是:
使用一个Polygon区域提取另一个图层中位于该区域内的空间数据。
这也是GIS中非常常见的数据裁剪方式。
Intersection应用:行政区分析
例如:
统计每个行政区中的土地利用情况。
数据:
行政区
+
土地利用
执行:
Intersection
得到:
行政区
+
土地利用
的空间重叠结果。
然后可以统计:
住宅用地面积
商业用地面积
工业用地面积
农业用地面积
Intersection应用:道路影响分析
例如:
分析道路两侧500米范围内的居民区。
流程:
道路
↓
Buffer 500m
↓
影响范围
↓
Intersection
↓
居民区
最终得到:
道路影响范围内居民区
Intersection应用:河流保护
例如:
找出河流保护范围内的建筑。
流程:
河流
↓
Buffer 200m
↓
保护范围
↓
Intersection
↓
建筑物
结果:
保护范围内建筑
Intersection应用:洪水风险分析
例如:
洪水风险区
+
居民区
↓
Intersection
↓
受影响居民区
进一步:
受影响区域
↓
统计人口
↓
风险人口
Intersection应用:土地利用分析
例如:
规划区
+
土地利用图层
↓
Intersection
得到:
规划区内土地
然后计算:
土地面积
占比
类型
Intersection应用:点数据筛选
例如:
找出某行政区内所有医院。
数据:
医院Point
+
行政区Polygon
执行:
Intersection
或者使用:
Within
即可得到:
行政区内医院
对于简单的点筛选,空间关系查询通常比直接生成Intersection结果更加合适。
Intersection应用:线数据裁剪
例如:
获取某个城市范围内的道路。
数据:
全国道路
+
城市Polygon
执行:
Intersection
得到:
城市内部道路
原本一条跨越城市边界的道路:
───────────────
城市
┌───────┐
─────┤ ├─────
└───────┘
Intersection后:
┌───────┐
│ │
└───────┘
只保留城市内部部分。
Intersection与Geometry
Intersection本质上是Geometry之间的空间运算:
Geometry A
+
Geometry B
↓
Intersection
↓
Geometry C
因此它属于:
Geometry Operation
常见Geometry操作还包括:
Buffer
Intersection
Union
Difference
Centroid
Convex Hull
Simplify
Intersection与CRS
执行Intersection时,两个Geometry必须使用兼容的空间参考系统。
例如:
Geometry A
CRS = EPSG:4326
Geometry B:
CRS = EPSG:3857
直接进行空间叠加通常是不正确的。
应该先:
Geometry A
↓
Coordinate Transform
↓
EPSG:3857
然后:
Geometry A
+
Geometry B
↓
Intersection
因此:
进行Intersection之前,需要确保参与计算的Geometry使用正确且一致的CRS。
Intersection中的Geometry有效性
无效Geometry可能导致Intersection失败。
例如Polygon存在:
自相交
重复节点
错误环
异常坐标
可能出现:
Intersection
↓
Error
因此实际GIS处理中经常需要:
Geometry
↓
Validate
↓
Repair
↓
Intersection
Intersection与空Geometry
两个Geometry没有共同空间部分时:
Intersection
↓
Empty Geometry
例如:
Polygon A
┌────────┐
┌────────┐
│ B │
└────────┘
二者完全分离:
Intersects
↓
false
因此:
Intersection
↓
Empty
在程序处理中,需要考虑这种情况。
Intersection的结果维度
Intersection结果的维度可能发生变化。
例如:
Polygon ∩ Polygon
↓
Polygon
Polygon ∩ LineString
↓
LineString
LineString ∩ LineString
↓
Point
所以:
Intersection的输出Geometry类型不能简单地根据第一个输入Geometry确定。
实际GIS库中还可能返回:
GeometryCollection
来表示多个不同维度的相交结果。
Intersection与GeometryCollection
复杂空间关系可能产生:
GeometryCollection
例如:
Intersection
↓
GeometryCollection
├── Point
├── LineString
└── Polygon
这通常发生在复杂Geometry之间存在不同类型的共同空间部分时。
因此开发GIS工具时,需要正确处理:
Point
LineString
Polygon
Multi*
GeometryCollection
Empty
Intersection与WKT
WKT非常适合表示Intersection的输入和输出。
例如:
POLYGON ((...))
与:
POLYGON ((...))
执行:
Intersection
输出:
POLYGON ((...))
流程:
WKT
↓
Geometry
↓
Intersection
↓
Geometry
↓
WKT
因此可以使用WKT工具进行Intersection测试。
Intersection与GeoJSON
GeoJSON也非常适合表示Intersection结果。
例如:
GeoJSON
↓
Geometry
↓
Intersection
↓
GeoJSON
这在Web GIS应用中非常常见。
例如:
Polygon A
+
Polygon B
↓
Intersection
↓
Polygon C
然后可以直接在地图上显示结果。
Intersection数据处理流程
一个完整的GIS Intersection流程可以是:
输入Geometry A
↓
检查Geometry
↓
检查CRS
↓
输入Geometry B
↓
检查Geometry
↓
统一CRS
↓
Intersection
↓
检查Empty
↓
输出Geometry
↓
GeoJSON / WKT / GeoPackage
Intersection常见问题
Intersection和Intersects有什么区别?
最重要的区别:
Intersects
↓
判断是否相交
↓
true / false
而:
Intersection
↓
计算相交部分
↓
Geometry
可以记住:
Intersects问“有没有”,Intersection回答“是什么”。
为什么Intersection没有结果?
可能是:
两个Geometry完全不相交
也可能是:
CRS不一致
或者:
Geometry无效
为什么Intersection结果不是Polygon?
因为结果Geometry类型取决于实际相交方式。
例如:
Polygon ∩ Line
↓
Line
Line ∩ Line
↓
Point
所以不能认为Intersection一定返回Polygon。
为什么Intersection计算失败?
常见原因包括:
CRS错误
Geometry无效
坐标异常
数据量过大
复杂Geometry
通常可以先:
Validate
以及:
Repair
再执行Intersection。
Intersection知识结构
可以把Intersection总结为:
Intersection
│
├── Point
│ ├── Point
│ ├── Line
│ └── Polygon
│
├── LineString
│ ├── Point
│ ├── Line
│ └── Polygon
│
└── Polygon
├── Point
├── Line
└── Polygon
核心关系:
Geometry A
+
Geometry B
↓
Intersection
↓
共同空间部分
常见Overlay操作:
Intersection
Union
Difference
Symmetric Difference
Intersection与空间分析
Intersection经常与:
Buffer
Distance
Within
Contains
Intersects
Touches
Overlaps
组合使用。
例如:
道路
↓
Buffer 500m
↓
Intersection
↓
建筑物
或者:
行政区
+
土地利用
↓
Intersection
↓
土地统计
因此:
Intersection是GIS空间叠加分析的核心操作之一。
总结
Intersection(相交)用于计算两个Geometry之间共同存在的空间部分。
核心关系:
Geometry A
+
Geometry B
↓
Intersection
↓
共同空间部分
它与Intersects需要特别区分:
Intersects
↓
是否相交
↓
true / false
Intersection
↓
相交在哪里
↓
Geometry
Intersection可以用于:
空间叠加
区域裁剪
土地分析
行政区分析
道路分析
河流保护
风险分析
空间查询
常见组合:
Buffer
↓
Intersection
↓
空间对象筛选
例如:
道路
↓
Buffer 500m
↓
道路影响范围
↓
Intersection
↓
建筑物
最终得到:
道路500米范围内的建筑物。
可以记住:
Intersection就是“取两个Geometry共同拥有的空间部分”。
在GIS空间分析中,最重要的一组集合运算可以理解为:
Intersection
↓
共同部分
Union
↓
全部部分
Difference
↓
A中不属于B的部分
Symmetric Difference
↓
不属于共同部分的区域
相关工具
使用 IYATools 在线工具快速处理 GIS 数据