GIS open source library GEOS library learning tutorial (3): spatial relationship/DE-9IM/predicate

1、DE-9IM

  To judge the relationship between two polygons, it actually belongs to the judgment of the spatial relationship of geometric figures. Geometric figures are not limited to polygons. They include any figure composed of points, lines, and surfaces. There are also many kinds of interrelationships between two pairs, so the spatial relationship is very complicated. According to previous studies, the DE-9IM model is summarized as a standard for judging spatial relationships.

  DE-9IM, the full name is Dimensionally Extended nine-Intersection Model (DE-9IM), is a topology model, a standard used to describe the spatial relationship between two geometric figures. In the professional field, each geometric figure is usually divided into three parts: exterior (exterior), boundary (boundary) and interior (interior). By analogy, what are the three parts of a rectangle? The judgment of the relationship between the two graphics is actually the judgment of the three parts separately, so there will be a 3*3 intersection matrix, which is the DE-9IM model, as shown in the figure below:

insert image description here
  Among them, a, b represent two faces respectively, and I, B, E represent its three parts respectively. The Dim() function represents the dimension of the intersection. If the intersecting part is a surface, it is two-dimensional, that is, dim()=2; if the intersecting part is a line, it is one-dimensional, dim()=1; if the intersecting part is some points, it is 0-dimensional, dim ()=0; if they do not intersect, then dim()=-1; read the matrix from top to bottom, from left to right, there will be a string, such as "212101212", which converts the relationship into a String, and finally judge the string on it. The above picture is just one of many relationships, and the drawing is an intersection situation, so there is no -1 situation.

  If we change the way of writing, we consider (0, 1, 2) as intersecting and write as T, and -1 as disjoint and write as F. Then "212101212" becomes "TTTTTTTTT". In fact, we only need to know a few of these 9 values ​​to make a judgment, not all of them. For example, as long as we know that the first digit is T, we can judge the intersection of the two, and we don't care what the next 8 digits are. We don't care what the value is, we will use * instead, so as long as we see "T********", we know that the two graphics intersect.

2. Predicate

  To express the relationship in professional terms, we call it a predicate, such as intersect, touch, overlap, contain, etc. There are many relationships and the definitions are very fine. We only consider the relationship between two surfaces (two polygons) here, so we only need to master several relationships. If you need to judge the relationship between points and lines, it is recommended to go to https://en.wikipedia.org/wiki/DE-9IM to take a closer look, the introduction is very detailed.

  There are two main types of relationship between faces: intersect and disengage (disjoint). Intersection is divided into contact, overlap, coverage and equality.
insert image description here
Coverage, Contact and Overlap
                 The above diagrams respectively represent: coverage, contact and overlap

In geos, these five relationships have corresponding functions, returning a BOOL value

a->equals(b)   //判断ab是否相等,返回
a->disjoint(b)  //判断ab是否脱离
a->touches(b) //判断ab是否接触
a->covers(b)   //判断ab是否覆盖,注意和contains的区别
a->overlaps(b) //判断两者是否有重叠部分
  • If ab is separated, you can use: a->distance(b) to calculate the shortest distance between the two.

  • If ab overlaps, you can use: a->intersection(b) returns the geometry of the intersection.

  • If you don't know the relationship between the two, you can use: a->relate(b) to return a string of strings, and then match the strings to see which relationship they belong to.

Guess you like

Origin blog.csdn.net/m0_37251750/article/details/130145703