A method for determining the positional relationship between a point and a complex polygon and a storage medium

The method optimizes grid sizing and storage allocation for point-polygon relationship judgments by dividing polygons into zones and using hash tables, addressing inefficiencies in existing methods and reducing storage and computational overhead.

CN115619971BActive Publication Date: 2025-07-15GUANGZHOU KETENG INFORMATION TECH
View PDF 2 Cites 0 Cited by

Patent Information

Application Number
CN202211307058.1
Authority / Receiving Office
CN · China
Patent Type
Patents(China)
Current Assignee / Owner
Filing Date
2022-10-24
Publication Date
2025-07-15
Estimated Expiration
2042-10-24

AI Technical Summary

Technical Problem

When judging the positional relationship between a large number of polygons and points, the prior art has problems such as large amount of calculation and waste of storage space. Especially when the size and number of polygons are uneven, the efficiency and storage overhead of the ray method and the grid preprocessing method are difficult to balance.

Method used

The mesh interval division and hash storage are used to sort polygons into different intervals by size, and the mesh size is reasonably designed on each interval, and the mesh information is stored and reduced to reduce the performance loss and space waste caused by too large or too small mesh.

Benefits of technology

It realizes the efficient judgment of the positional relationship between points and complex polygons under low storage overhead, reducing the waste of computing and storage space.

✦ Generated by Eureka AI based on patent content.

Smart Images

  • Figure CN115619971B_ABST
    Figure CN115619971B_ABST
Patent Text Reader

Abstract

The present invention discloses a method for judging the positional relationship between a point and a complex polygon and a storage medium. The method includes: step (1) dividing grid intervals and allocating polygons; step (2) generating grids on each interval; step (3) polygon cutting and division; step (4) grid data reduction; step (5) judging the position of the target point and the polygon. The method for judging the positional relationship between a point and a complex polygon according to the present invention distributes a large number of polygons to different grid intervals and reasonably designs the grid sizes on different intervals, greatly reducing the performance loss or space waste caused by grids being too large or too small. On the other hand, the present invention uses hash storage to store grid information and performs reduction and deletion. Compared with the prior art that directly stores grids, the space occupied by grid storage is greatly reduced.
Need to check novelty before this filing date? Find Prior Art

Description

Technical Field

[0001] The present invention relates to the GIS field, and in particular to a method and a storage medium for determining the positional relationship between a point and a complex polygon, in order to achieve low storage overhead and better determination efficiency. Background Art

[0002] In the field of GIS, determining the positional relationship between points and polygons is a common application scenario, for example: determining whether a vehicle is within the electronic fence to send a warning to the driver, determining whether a pedestrian has entered the business district to push business district advertisements to pedestrians, etc. The industry generally uses the ray method to make judgments, that is, select a point within the polygon, connect it with the target point to form a ray, and calculate the number of intersections between the ray and the polygon edge. If the number of intersections is an odd number, the target point is within the polygon, otherwise the target point is outside the polygon.

[0003] If the polygon has a large number of sides, the grid method will be used for preprocessing: a grid is constructed to cut the polygon, and then the relationship between each grid and the polygon is calculated one by one, and the grids are distributed to three sets P (grids are completely covered by polygons), Q (grids are completely not covered by polygons), and R (grids are partially covered by polygons). Then, if the target point falls on a grid in set P or Q, there is no need to calculate whether the point is inside the polygon. If the target point falls on set R, it is only necessary to use the ray method to calculate whether the part of R covered by the polygon intersects with the target point, which greatly reduces the amount of calculation.

[0004] However, in practical applications, it is often necessary to determine the position of the target point and multiple polygons. The ray method and its grid preprocessing method have certain defects when facing a large number of polygons. The width and height of the grid of the cut grid are obtained by empirical formulas, but when faced with a large number of grids of different sizes, the determination of the width and height is easy to lose sight of the overall situation. If the width and height values are too large, almost all small polygons will fall into the set R, resulting in an increase in the amount of calculation. If the width and height values are too small, too many grids will be cut out of the polygon, wasting too much storage space and preprocessing time. Summary of the invention

[0005] Aiming at the scenario of determining the positional relationship between a point and a complex polygon, the present invention provides a method and a storage medium for determining the positional relationship between a point and a complex polygon, so as to achieve low storage overhead and better determination efficiency.

[0006] The technical solution of the present invention is:

[0007] A method for determining the positional relationship between a point and a complex polygon comprises the following steps:

[0008] Step (1) Divide the grid area and assign polygons

[0009] Calculate the minimum bounding rectangle (Envelope) of each polygon, and the width w and height h of the Envelope, and record And sort all polygons in ascending order according to their s values, and record the smallest s value as s min , and record the largest s value as s max .

[0010] Input the number of intervals en, then the interval width Therefore, construct the intervals

[0011] E1 = [s min , s min + ew),

[0012] E2 = [s min + ew, s max + 2 * ew),

[0013] ...,

[0014] E i = [s min + (i - 1) * ew, s max + i * ew),

[0015] ...,

[0016] E en = [s min + (en - 1) * ew, s max

[0017] Traverse each polygon. If the s value of a polygon is within the value range of interval i, then assign this polygon to interval i.

[0018] Step (2) Generate grids on each interval

[0019] Traverse each interval. For interval E i , input the grid height h i and width w i , and record the map coordinate range as [(xmin, ymin), (xmax, ymax)]. Then the number of grid rows is The number of grid columns is where floor is rounding down. The grid coordinate range is:

[0020] [((xmax - xmin) * c), ((ymax - ymin) * r), ((xmax - xmin) * (r + 1)), ((ymax - ymin) * (c + 1))]

[0021] where r is the grid row number and c is the grid column number. Assign sets P and R to each grid. ​

[0022] Step (3) Polygon cutting and partitioning

[0023] For each interval, traverse the polygons assigned to this interval and each grid cell in the interval: If the cell is completely covered by a polygon, add the polygon number to the set P on the cell; if the cell is not completely covered by a polygon, add the polygon number to the set R on the cell.

[0024] Step (4) Grid data reduction

[0025] Traverse each interval, assign hash tables HP and HR to it. The keys of the hash tables are the row number and column number, and the values are linked lists storing polygon numbers. Traverse each grid cell in this interval, add the polygon numbers in set P in the cell to the linked list of the hash value in HP with the row and column numbers of the cell as the key, add the polygon numbers in set R in the cell to the linked list of the hash value in HR with the row and column numbers of the cell as the key, and then remove the space occupied by P and R. After the traversal, each grid data is reduced to the hash table on its interval.

[0026] Step (5) Judgment of the position of the target point and the polygon

[0027] Input a target point, denote the coordinates of the input target point as (x, y), and denote RES as the set of polygon numbers covering the target point. Traverse each interval, for interval E i , whose grid height is h i , and the grid width is w i , then the row number of the grid where the target point belongs is row = floor((y - ymin) * h i / (ymax - ymin)), and the column number is col = floor((x - xmin) * w i / (xmax - xmin)). Retrieve the linked list of polygon numbers from hash table HP according to the row and column numbers, add the numbers in the linked list to set RES. Retrieve the linked list of polygon numbers from hash table HR according to the row and column numbers, traverse each number, and use the ray method to calculate whether the part of the polygon corresponding to the number in this cell covers the target point. If so, add the number to set RES. After the traversal, the numbers in set RES are the polygon numbers to which the target point belongs. Conversely, the numbers not in set RES are the polygon numbers that do not intersect with the target point.

[0028] Furthermore, in the said step (1), the number of input intervals en is calculated using an empirical formula, and the calculation formula is: where δ s is the variance of s, and n is the total number of polygons. This formula aims to make the number of intervals positively correlated with the number of polygons and positively correlated with the scattered distribution (i.e., variance) of the polygon sizes.

[0029] Furthermore, for the grid width and height input in step (2), the calculation formula in the literature "Jing Li and Wencheng Wang. 2014. Point-In-Polygon Tests by Applying the Ray Crossing Method Locally Via Grid Center Points. International Journal of Electrical Engineering 21, 3 (2014), 85-92." is referred to:

[0030]

[0031] Among them, the reference defines W as the width of the circumscribed rectangle of the polygon, H as the height of the circumscribed rectangle of the polygon, M as the number of sides of the polygon, and k as an empirical coefficient; since multiple polygons in the interval need to be considered in step (2) to determine the grid width and height, the parameters are optimized in this paper as follows: W is the median of the widths of the circumscribed rectangles of each polygon in interval i, H is the median of the heights of the circumscribed rectangles of each polygon in interval i, M is the median of the number of sides of each polygon in interval i, and k = (a - σ a ) / a (where a is the average value of the areas of the polygons in the interval, and σ a is the standard deviation of the areas of the polygons in the interval. The optimization of k aims to adjust the grid width and height negatively correlated according to the balance degree of the areas).

[0032] Furthermore, in step (4), useless hashes and intervals can be further deleted to further reduce the space occupation. The deletion method is as follows: after step (4) ends, traverse each interval and check its hash HP. If the number of elements contained in HP is 0, then delete the hash HP. Determine and delete the hash HR according to the same method. If both HP and HR in this interval are deleted, then delete this interval.

[0033] A computer-readable storage medium, on which a computer program is stored, characterized in that the computer program can be executed by a processor to implement the steps of the method for judging the positional relationship between a point and a complex polygon of the present invention.

[0034] Compared with the prior art, the present invention has the following beneficial effects:

[0035] The method for judging the positional relationship between a point and a complex polygon according to the present invention distributes a large number of polygons into different grid intervals and reasonably designs the grid sizes in different intervals, greatly reducing the performance loss or space waste caused by grids being too large or too small. On the other hand, the present invention uses hash storage for grid information and performs contraction and deletion, greatly reducing the space occupied by grid storage compared with the direct storage of grids in the prior art. Brief Description of the Drawings

[0036] Figure 1 : Schematic flowchart of the method of the present invention.

[0037] Figure 2 : Schematic diagram of grid contraction. Detailed Description of the Embodiments

[0038] The technical solutions of the present invention will be further described in detail below in conjunction with embodiments, but the present invention is not limited to the following technical solutions.

[0039] Embodiment 1: The method supports the tower retrieval service in the icing area

[0040] Before the arrival of autumn and winter seasons in the power grid industry, it is necessary to obtain the icing area based on comprehensive considerations such as meteorological information and previous year's data, and calculate which towers are located in the icing area in order to arrange subsequent ice prevention and removal work. The icing area generally consists of hundreds of thousands of polygons, and on average, each polygon has thousands of sides. Facing such complex icing area polygon data, it is difficult to meet the performance requirements using conventional database spatial analysis solutions such as oracle spatial and postgis.

[0041] The present method realizes the tower retrieval service in the icing area according to the following steps:

[0042] Step (1) Divide grid intervals and distribute polygons

[0043] Calculate the minimum bounding rectangle (Envelope) of each icing area polygon, and the width w and height h of the Envelope, denoted as And sort all polygons in ascending order according to their s values, the smallest s value is denoted as s min , the largest s value is denoted as s max .

[0044] Denote the number of intervals as en, then where δ s is the variance of s, n is the total number of polygons, and this formula aims to make the number of intervals positively correlated with the number of polygons and positively correlated with the scattered distribution of polygon sizes (i.e., variance).

[0045] Then the interval width Therefore, construct the interval

[0046] E1 = [s min , s min + ew),

[0047] E2 = [s min + ew, s max + 2 * ew),

[0048] ...,

[0049] E i = [s min +(i - 1) * ew, s max + i * ew),

[0050] ...,

[0051] E en = [s min +(en - 1) * ew, s max

[0052] Traverse each polygon. If the s value of a polygon falls within the value range of interval i, then assign this polygon to interval i.

[0053] Step (2) Generate grids on each interval

[0054] Traverse each interval. For interval E i , denote the grid height as h i and the grid width as w i , then

[0055]

[0056] where W is the median of the widths of the circumscribed rectangles of the polygons in interval i, H is the median of the heights of the circumscribed rectangles of the polygons in interval i, M is the median of the number of sides of the polygons in interval i, k = (a - σ a ) / a (where a is the average value of the areas of the polygons in the interval, and σ a is the standard deviation of the areas of the polygons in the interval).

[0057] Denote the map coordinate range as [(xmin, ymin), (xmax, ymax)], then the number of grid rows is The number of grid columns is where floor is rounding down, and the grid coordinate range is:

[0058] [((xmax - xmin) * c), ((ymax - ymin) * r), ((xmax - xmin) * (r + 1)), ((ymax - ymin) * (c + 1))]

[0059] ​where r is the grid row number and c is the grid column number. The sets P and R are assigned to each grid.

[0060] [((xmax - xmin) * c), ((ymax - ymin) * r), ((xmax - xmin) * (c + 1)), ((ymax - ymin) * (r + 1))]

[0061] Step (3) Division of the icing area polygon

[0062] For each interval, traverse the polygons assigned to this interval and each grid cell on the interval: If the cell is completely covered by the polygon, add the polygon number to the set P on the cell; if the cell is not completely covered by the polygon, add the polygon number to the set R on the cell.

[0063] Step (4) Reduction of grid data

[0064] Traverse each interval, assign hash tables HP and HR to it. The keys of the hash tables are the row number and column number, and the values are linked lists storing polygon numbers. Traverse each grid cell on this interval, add the polygon numbers in the set P in the cell to the linked list of the hash value in HP with the grid row and column numbers as the key, and add the polygon numbers in the set R in the cell to the linked list of the hash value in HR with the grid row and column numbers as the key. Then remove the space occupied by P and R, check the hash table HP. If the number of elements contained in HP is 0, delete the hash table HP. Determine and delete the hash table HR in the same way. If both HP and HR in this interval are deleted, delete this interval. After the traversal, each grid data is reduced to the hash table on its interval. The reduction effect is as shown in the appendix Figure 2 as shown.

[0065] Step (5) Judgment of the position of the tower and the polygon

[0066] Input the coordinates (x, y) of a tower, and denote RES as the set of icing area polygon numbers covering the target tower. Traverse each interval. For interval E i , its grid height is h i , and the grid width is w i , then the grid row number where the tower is located is row = floor((y - ymin) * h i / (ymax - ymin)), and the column number is col = floor((x - xmin) * w i / (xmax - xmin)), take out the linked list of polygon numbers from the hash HP according to the row and column numbers, add the numbers in the linked list to the set RES, take out the linked list of polygon numbers from the hash HR according to the row and column numbers, traverse each number, and use the ray method to calculate whether the part of the polygon corresponding to the number in this grid covers the target point. If so, add the number to the set RES. After the traversal, if the set RES is empty, this tower is not in the icing area, otherwise this tower is in the icing area. Take out all the polygon numbers in RES, that is, the icing area numbers, and use the icing area numbers to query information such as the icing thickness and geographical environment of the icing area in the database to generate an icing analysis report for subsequent use.

Claims

1. A method for determining the positional relationship between a point and a complex polygon, characterized in that, Including the following steps: Step (1) Divide the grid intervals and allocate polygons, including: Calculate the minimum bounding rectangle Envelope of each polygon, as well as the width w and height h of the Envelope, and record And sort all polygons in ascending order according to their s values. Denote the smallest s value as s min , and denote the largest s value as s max ; The number of input intervals en, interval width Construct intervals: E1 = [s min , s min + ew), E2 = [s min + ew,s max + 2 * ew), ..., E i = [s min + (i - 1) * ew,s max + i * ew), ..., E en = [s min + (en - 1) * ew,s max ​ Traverse each polygon. If the s value of a polygon falls within the value range of interval i, then allocate this polygon to interval i; Step (2) Generate grids on each interval, including: Traverse each interval. For interval E i , input the grid height h i and width w i . Denote the map coordinate range as [(xmin, ymin), (xmax, ymax)], the number of grid rows as the number of grid columns as where floor is rounding downwards. The grid coordinate range is as follows: [((xmax - xmin) * c), ((ymax - ymin) * r), ((xmax - xmin) * (r + 1)), ((ymax - ymin) * (c + 1))] Where r is the grid row number and c is the grid column number. Allocate sets P and R to each grid; Step (3) Polygon cutting and division, including: For each interval, traverse the polygons allocated on this interval and traverse each grid cell on the interval; If the grid is completely covered by a polygon, add the polygon number to the set P on the grid; If the grid is not completely covered by a polygon, add the polygon number to the set R on the grid; Step (4) Grid data reduction, including: Traverse each interval, allocate hash tables HP and HR for it. The keys of the hash tables are the row number and column number, and the values of the hash tables are linked lists storing polygon numbers. Traverse each grid cell on this interval, add the polygon numbers in the set P in the grid cell to the linked list of the hash value in hash table HP with the grid row and column numbers as the key, add the polygon numbers in the set R in the grid cell to the linked list of the hash value in hash table HR with the grid row and column numbers as the key, and then remove the space occupied by P and R; After the traversal ends, each grid data is reduced to the hash table on its interval; Step (5) Determine the position of the target point and the polygon, including: Input a target point, denote the coordinates of the input target point as (x, y), and denote RES as the set of polygon numbers covering the target point; Traverse each interval. For interval E i , whose grid height is h i , and grid width is w i , the row number of the grid where the target point belongs is row = floor((y - ymin) * h i / (ymax - ymin)), and the column number is col = floor((x - xmin) * w i / (xmax - xmin)). Retrieve the linked list of polygon numbers from the hash HP according to the row and column numbers, add the numbers in the linked list to the set RES. Retrieve the linked list of polygon numbers from the hash HR according to the row and column numbers, traverse each number, and use the ray method to calculate whether the part of the polygon corresponding to the number within this grid covers the target point. If so, add the number to the set RES; After the traversal ends, the numbers in the set RES are the polygon numbers to which the target point belongs. Conversely, the numbers not in the set RES are the polygon numbers that do not intersect with the target point.

2. The method according to claim 1, wherein In the said step (1), the number of input intervals en is calculated using an empirical formula, and the calculation formula is: where: δ s is the variance of s, and n is the total number of polygons. This formula aims to make the number of intervals positively correlated with the number of polygons and positively correlated with the scattered distribution of the polygon sizes (i.e., variance).

3. The method according to claim 1, characterized in that, In the said step (2), the calculation formulas for the width and height of the grid are: where: W is the median of the widths of the circumscribed rectangles of the polygons in interval i, H is the median of the heights of the circumscribed rectangles of the polygons in interval i, M is the median of the number of sides of the polygons in interval i, and k = (a - σ a ) / a Where: a is the average value of the polygon areas within the interval, and σ a is the standard deviation of the polygon areas within the interval.

4. The method according to claim 1, wherein In the said step (4), delete the useless hash tables and intervals to further reduce the space occupancy. The deletion method is: After step (4) ends, traverse each interval, check its hash table HP. If the number of elements contained in HP is 0, then delete hash table HP. Determine and delete hash table HR according to the same method. If both HP and HR in this interval are deleted, then delete this interval.

5. A computer-readable storage medium having a computer program stored thereon, characterized in that, The said computer program can be executed by a processor to implement the steps of the method for judging the positional relationship between a point and a complex polygon as described in any one of claims 1 - 4.

Citation Information

Patent Citations

  • Method for querying nearest neighbor of efficient space combined by Voronoi Diagram and virtual grids

    CN103559209A

  • Method and device for determining relationship between point and fence and electronic device

    CN108846882A