Point_in_polygon - ObjectVision/GeoDMS GitHub Wiki
Geometric functions point_in_polygon

- point_in_polygon(point_data_item, polygon_data_item)
point_in_polygon(point_data_item, polygon_data_item) results for each point of the point_data_item in a relation towards the domain unit of the polygon_data_item in which the point is located.
The resulting values unit is the domain unit of the polygon_data_item.
If a point is not located in any polygon, the function results in a null value (the yellow point in the image). If a point is located in multiple polygons, the function results in one of them, and which one is not specified: it is the first one that the function's spatial index finds, which follows from how that index is built and can differ between versions of GeoDMS. A configuration, and a test, must not depend on which one it is. If you want to choose among overlapping polygons, use the point_in_ranked_polygon function; with a constant rank, that takes the polygon with the lowest index.
The first one found is kept because it is fast: a search that stops at the first polygon containing the point does not have to look at the rest. Choosing the lowest index instead made this function about 7 times slower on polygons that do not overlap.
Since GeoDMS 20.23.1 the spatial index splits its nodes at another size (#1289), and that changed which of several overlapping polygons is found first: a point in 14 identical polygons (numbered 1 to 14) got polygon 14 where it got polygon 3. A configuration with overlapping polygons can therefore get other results for the points in the overlap after upgrading; a point in one polygon only gets the same result as before.
The point_in_polygon function was used in earlier versions of the GeoDMS to rasterize polygon data. Since version 6.025, it is advised to use the poly2grid function for this purpose.
O(n log p + n * k) where n = number of points, p = number of polygons, and k = average polygon complexity. Builds a spatial index on polygons for efficient lookup. For large-scale rasterization, prefer poly2grid.
- a data item point_data_item with Point value type
- a data item polygon_data_item with composition type type polygon and Point value type
attribute<district> district_rel (ADomain) := point_in_polygon(Adomain/point, district/geometry);
| point | district_rel |
|---|---|
| xy(115135; 401331) | 6 |
| xy(111803; 399476) | 4 |
| xy(114903; 399289) | 1 |
| xy(111353; 401729) | 5 |
| xy(111741; 398696) | null |
ADomain, nr of rows = 5
| District/geometry |
|---|
| {21:xy(113810; 403025),{4 |
| {17:xy(113269; 400990),{4 |
| {19:xy(115099; 403128),{4 |
| {23:xy(113703; 402174),{4 |
| {30:xy(114646; 401531),{4 |
| {13:xy(114546; 402757),{4 |
| {54:xy(113562; 405282),{4 |
domain District, nr of rows = 7