ST_Contains
时间: 2023-06-21 22:14:28 浏览: 62
ST_Contains是PostGIS中的一个函数,用于判断一个几何对象是否包含另一个几何对象。它的语法如下:
```
ST_Contains(geometry A, geometry B);
```
其中A和B都是几何对象,可以是点、线、面等。如果A包含B,则返回true,否则返回false。
需要注意的是,ST_Contains函数判断的是完全包含,即A包含B的每一个点都在A中,而不是部分包含。如果要判断部分包含,可以使用ST_Intersects函数。
相关问题
postgresql st_contains
`ST_Contains` is a PostGIS function that checks if a geometry (such as a point, line or polygon) is completely inside another geometry. It returns true if the first geometry is completely inside the second geometry, otherwise it returns false.
Here's an example usage of `ST_Contains` in PostgreSQL:
```
SELECT *
FROM table1
WHERE ST_Contains(table1.geom, table2.geom);
```
This query selects all records from `table1` where the geometry in the `geom` column of `table1` is completely inside the geometry in the `geom` column of `table2`.
Note that `ST_Contains` only works with two-dimensional geometries. If you are working with three-dimensional geometries, you should use `ST_3DContains` instead.
ST_Contains使用实例
ST_Contains是一个常用的PostGIS函数,用于判断一个几何对象是否包含另一个几何对象。下面是一个使用ST_Contains函数的示例:
假设我们有一个名为"cities"的表,其中包含一些城市的位置信息。我们还有一个名为"states"的表,其中包含每个州的边界信息。现在我们想要找出哪些城市位于特定州的边界内,我们可以使用ST_Contains函数来实现。
首先,我们需要查询州的边界信息,假设我们要查询的是加利福尼亚州。我们可以使用以下查询语句:
```sql
SELECT geom FROM states WHERE name = 'California';
```
这将返回加利福尼亚州的边界几何对象。
接下来,我们需要查询位于加利福尼亚州边界内的城市。我们可以使用以下查询语句:
```sql
SELECT cities.name FROM cities, states WHERE states.name = 'California' AND ST_Contains(states.geom, cities.geom);
```
这将返回一个包含所有位于加利福尼亚州边界内的城市名称的列表。在这个查询中,我们使用了ST_Contains函数来判断每个城市的几何对象是否位于加利福尼亚州的边界内。
注意,这个例子中假设了"cities"表和"states"表都包含一个名为"geom"的几何列,如果你的表结构不同,需要做相应的修改。
相关推荐
![zip](https://img-home.csdnimg.cn/images/20210720083736.png)
![](https://csdnimg.cn/download_wenku/file_type_ask_c1.png)
![](https://csdnimg.cn/download_wenku/file_type_ask_c1.png)
![](https://csdnimg.cn/download_wenku/file_type_ask_c1.png)
![](https://csdnimg.cn/download_wenku/file_type_ask_c1.png)
![](https://csdnimg.cn/download_wenku/file_type_ask_c1.png)
![](https://csdnimg.cn/download_wenku/file_type_ask_c1.png)
![](https://csdnimg.cn/download_wenku/file_type_ask_c1.png)
![](https://csdnimg.cn/download_wenku/file_type_ask_c1.png)
![](https://csdnimg.cn/download_wenku/file_type_ask_c1.png)
![](https://csdnimg.cn/download_wenku/file_type_ask_c1.png)
![](https://csdnimg.cn/download_wenku/file_type_ask_c1.png)
![](https://csdnimg.cn/download_wenku/file_type_ask_c1.png)
![](https://csdnimg.cn/download_wenku/file_type_ask_c1.png)
![](https://csdnimg.cn/download_wenku/file_type_ask_c1.png)