A method for quickly determining the relationship between a line segment and a coastline

By using rasterized map data and distance thresholds, combined with the Haversine formula and the geometry.intersects function, the problem of long calculation time in determining the relationship between line segments and coastlines was solved, and an efficient and accurate calculation method was achieved.

CN121455957BActive Publication Date: 2026-06-26TIANJIN YUNYAO AEROSPACE TECH CO LTD +3
View PDF 1 Cites 0 Cited by

Patent Information

Application Number
CN202610007540.5
Authority / Receiving Office
CN · China
Patent Type
Patents(China)
Current Assignee / Owner
Filing Date
2026-01-06
Publication Date
2026-06-26
Estimated Expiration
2046-01-06

AI Technical Summary

Technical Problem

Existing technologies cannot effectively shorten the calculation time for determining the relationship between line segments and coastlines while ensuring calculation accuracy, and are particularly inefficient in big data computing.

Method used

The distance threshold is calculated using rasterized map data and the Haversine formula. When the distance is below the threshold, the raster method is used to determine the relationship between the line segment and the land. When the distance is above the threshold, the geometry.intersects function is used to determine the relationship. The calculation process is optimized to improve efficiency.

Benefits of technology

While ensuring accuracy, it significantly reduces running time, especially improving program efficiency and saving computing resources in big data computing.

✦ Generated by Eureka AI based on patent content.

Smart Images

  • Figure CN121455957B_ABST
    Figure CN121455957B_ABST
Patent Text Reader

Abstract

The application provides a method for quickly judging the relationship between a line segment and a coastline, comprising the following steps: rasterizing map data; judging the relationship between the line segment and land; if the distance between two points is less than a distance threshold value, using a rasterization method to calculate; if the distance is greater than the threshold value, using a geometry.intersects function to judge; and calculating the distance threshold value. The application has the beneficial effects that the application combines the characteristics of different distances across land, proposes a method for quickly judging the relationship between two points and land, can reduce the running time on the premise of ensuring the accuracy, and improves the program running efficiency in large data operation.
Need to check novelty before this filing date? Find Prior Art

Description

Technical Field

[0001] This invention belongs to the field of AIS data processing, and in particular relates to a method for quickly determining the relationship between a line segment and a coastline. Background Technology

[0002] AIS data processing to generate route networks is a classic application of AIS data. However, in actual operation, the generated results may cross land, so accurately identifying whether a route crosses land is the foundation of a route network.

[0003] Currently, the main methods for determining whether a point crosses land include: intersection detection based on vector data from Geographic Information Systems (GIS) and spatial analysis; judgment using ray casting; judgment using existing geographic APIs; and functions available in some programming languages. However, the success depends not only on the calculation method but also on the accuracy of the vector data. As data accuracy increases, computation time and efficiency increase exponentially. Existing methods cannot meet the requirements for computational accuracy and runtime. Therefore, this invention proposes a method for quickly determining the relationship between a line segment and a coastline. Summary of the Invention

[0004] In view of this, the present invention aims to propose a method for quickly determining the relationship between a line segment and a coastline, so as to solve the problems of insufficient calculation accuracy and running time in the prior art.

[0005] To achieve the above objectives, the technical solution of the present invention is implemented as follows:

[0006] A method for quickly determining the relationship between a line segment and a coastline includes the following steps:

[0007] S1, rasterized map data;

[0008] S2. Determine the relationship between the line segment and the land;

[0009] S3. If the distance between two points is less than the distance threshold, the rasterization method is used for calculation.

[0010] S4. If the value is greater than the threshold, use the geometry.intersects function to determine the result.

[0011] S5. Calculate the distance threshold.

[0012] Furthermore, in step S1, the range is selected as an integer multiple of the raster resolution using a geographic information tool; the converted result is saved as a binary file.

[0013] Furthermore, in step S2, determining the relationship between the line segment and the land includes:

[0014] S21. Use the np.fromfile function to read the raster data file, and use the reshape function to convert the data into a two-dimensional array according to the resolution and store it in the land_grid variable;

[0015] S22. Use the math.radians function in Python to convert latitude and longitude to radians, and calculate the distance between two points using the Haversine formula.

[0016] Furthermore, in step S3, if the distance between two points is less than a distance threshold, a rasterization method is used for calculation, including the following steps:

[0017] S31. Call the get_line_grid_indices() function to calculate the raster indexes on the line from the start point to the end point. The get_line_grid_indices() function calculates a list of raster indexes for all points on the line using the start point, end point, and raster resolution.

[0018] S32. Circularly query the index list, checking whether each point is on land according to land_grid(lon_idx,lat_idx);

[0019] S33. If the loop ends on land and returns to TRUE, then the line connecting the two points crosses the land.

[0020] S34. If not on land, continue the loop until the loop ends, then return to FALSE. In this case, the line connecting the two points does not cross land.

[0021] Furthermore, in step S31, the get_line_grid_indices() function is called to calculate the grid indices on the line from the start point to the end point, including the following steps:

[0022] S311. Call the `coord_to_grid_inde` function to calculate the raster index on the line segment from the start point to the end point. The `coord_to_grid_inde` function converts latitude and longitude coordinates into a two-dimensional array index and returns it. The conversion relationship is shown in the formula:

[0023] Lon_idx = round(lon - origin_lon) / ratio;

[0024] Lat_idx = round(lat - origin_lat) / ratio;

[0025] The `round` function is used to round numerical values. `Lon_idx` represents the index of longitude in the two-dimensional array, `Lat_idx` represents the index of latitude in the two-dimensional array, `lon` and `lat` represent the latitude and longitude coordinates of the point to be calculated, `origin_lon` and `origin_lat` represent the starting longitude and latitude of the original raster data, respectively, and `ratio` represents the resolution of the raster data.

[0026] S312. Calculate the number of sampling points required, num_points, using the formula shown below:

[0027] num_points = int(round(math.hypot((end_lon - start_lon), (end_lat -start_lat)) / ratio));

[0028] The int function is the integer function in Python, the math.hypot function is used to calculate the Euclidean distance, and end_lon, start_lon, end_lat, and start_lat are the latitude and longitude coordinates of the starting and ending points, respectively.

[0029] S313. The index of each sampling point is calculated by calling the coord_to_grid_index function in sequence through a loop, and an index list is generated.

[0030] S314. Remove duplicate values ​​from the list, add the starting and ending indices to the beginning and end positions respectively, and return the final index list.

[0031] Furthermore, in step S5, the distance threshold is calculated, including:

[0032] The calculation time and judgment results of different methods for the same two points are statistically analyzed. The accuracy rate is calculated based on the highest accuracy as the benchmark, and the time-distance curve and the accuracy-distance curve are obtained. The distance threshold is determined according to the results and actual needs.

[0033] Compared with existing technologies, the method for quickly determining the relationship between a line segment and a coastline described in this invention has the following advantages:

[0034] (1) The present invention provides a method for quickly determining the relationship between a line segment and a coastline. Combining the characteristics of crossing land at different distances, the present invention proposes a method for quickly determining the relationship between two points and the land. This method can reduce the running time while ensuring accuracy and improve the program running efficiency in big data operations.

[0035] (2) The method for quickly determining the relationship between a line segment and a coastline as described in this invention proposes a distance threshold selection calculation method based on different cases. Different time-distance curves are generated to determine the threshold. When the distance is below the threshold, a method is proposed to rasterize the map data, use data indexing, and query the relationship between points on the line segment and the land to determine whether the line segment crosses the land. When the distance is above the threshold, traditional methods are used for calculation, optimizing calculation time and accuracy. Attached Figure Description

[0036] The accompanying drawings, which form part of this invention, are used to provide a further understanding of the invention. The illustrative embodiments of the invention and their descriptions are used to explain the invention and do not constitute an undue limitation of the invention. In the drawings:

[0037] Figure 1 This is a schematic diagram of the method described in an embodiment of the present invention;

[0038] Figure 2 This is a schematic diagram of the time-distance curve described in an embodiment of the present invention;

[0039] Figure 3 This is a schematic diagram of the accuracy-distance curve according to an embodiment of the present invention. Detailed Implementation

[0040] It should be noted that, unless otherwise specified, the embodiments and features described in the present invention can be combined with each other.

[0041] In the description of this invention, it should be understood that the terms "center," "longitudinal," "lateral," "upper," "lower," "front," "rear," "left," "right," "vertical," "horizontal," "top," "bottom," "inner," and "outer," etc., indicating orientations or positional relationships based on the orientations or positional relationships shown in the accompanying drawings, are only for the convenience of describing the invention and simplifying the description, and do not indicate or imply that the device or element referred to must have a specific orientation, or be constructed and operated in a specific orientation, and therefore should not be construed as a limitation of the invention. Furthermore, the terms "first," "second," etc., are used for descriptive purposes only and should not be construed as indicating or implying relative importance or implicitly specifying the number of indicated technical features. Thus, a feature defined with "first," "second," etc., may explicitly or implicitly include one or more of that feature. In the description of this invention, unless otherwise stated, "a plurality of" means two or more.

[0042] In the description of this invention, it should be noted that, unless otherwise explicitly specified and limited, the terms "installation," "connection," and "linking" should be interpreted broadly. For example, they can refer to a fixed connection, a detachable connection, or an integral connection; they can refer to a mechanical connection or an electrical connection; they can refer to a direct connection or an indirect connection through an intermediate medium; and they can refer to the internal connection of two components. Those skilled in the art will understand the specific meaning of the above terms in this invention based on the specific circumstances.

[0043] The present invention will now be described in detail with reference to the accompanying drawings and embodiments.

[0044] like Figures 1 to 3 As shown, a method for quickly determining the relationship between a line segment and a coastline includes the following steps:

[0045] S1, Raster map data:

[0046] Map rasterization can be directly converted using geographic information tools. To ensure computational efficiency and memory usage, it is recommended to select an integer multiple of the raster resolution when choosing the range to reduce index calculation errors. After conversion, the result should be saved as a binary file to improve the program's reading efficiency.

[0047] This invention combines the characteristics of different distances across land to propose a method for quickly determining the distance between two points and land. It can reduce running time while ensuring accuracy and improve program running efficiency in big data computing.

[0048] S2. Determine the relationship between the line segment and the land:

[0049] S21. Use the np.fromfile function to read the raster data file, and use the reshape function to convert the data into a two-dimensional array according to the resolution and store it in the land_grid variable.

[0050] S22. Use the math.radians function in Python to convert latitude and longitude to radians, and calculate the distance between two points using the Haversine formula.

[0051] In this embodiment, these two steps together form the prerequisite for distance threshold determination: rasterization provides fast query capability in low-distance scenarios, while Haversine distance calculation is the basis for threshold determination. The combination of the two achieves a balance between accuracy and efficiency.

[0052] S3. If the distance between two points is less than the distance threshold, the rasterization method proposed in this invention is used for calculation.

[0053] S31. Call the get_line_grid_indices() function to calculate the raster indexes on the line from the start point to the end point. This function is a user-defined function, and its main function is to calculate a list of raster indexes for all points on the line using the start point, end point, and raster resolution.

[0054] S311. Call the `coord_to_grid_inde` function to calculate the raster index on the line segment from the start point to the end point. This function is a user-defined function, and its main function is to convert latitude and longitude coordinates into a two-dimensional array index and return it. The conversion relationship is shown in the formula:

[0055] Lon_idx = round(lon - origin_lon) / ratio;

[0056] Lat_idx = round(lat - origin_lat) / ratio;

[0057] The `round` function is used to round numerical values. `Lon_idx` represents the index of longitude in the two-dimensional array, `Lat_idx` represents the index of latitude in the two-dimensional array, `lon` and `lat` represent the latitude and longitude coordinates of the point to be calculated, `origin_lon` and `origin_lat` represent the starting longitude and latitude of the original raster data, respectively, and `ratio` represents the resolution of the raster data.

[0058] S312. Calculate the number of sampling points required, num_points, using the formula shown below:

[0059] num_points = int(round(math.hypot((end_lon - start_lon), (end_lat -start_lat)) / ratio));

[0060] The `int` function is a rounding function in Python, the `math.hypot` function is used to calculate the Euclidean distance (i.e., the length of the hypotenuse of a right triangle), and `end_lon`, `start_lon`, `end_lat`, and `start_lat` are the latitude and longitude coordinates of the starting and ending points, respectively.

[0061] S313. The coord_to_grid_index function is called sequentially in a loop to calculate the index of each sampling point and generate an index list.

[0062] S314. Remove duplicate values ​​from the list, add the starting and ending indices to the beginning and end positions respectively, and return the final index list.

[0063] S32. Circularly query the index list, checking whether each point is on land according to land_grid(lon_idx,lat_idx).

[0064] S33. If the loop ends on land, return to TRUE, meaning the line connecting the two points crosses the land.

[0065] S34. If not on land, continue the loop until the loop ends, then return to FALSE, meaning the line connecting the two points does not cross land.

[0066] In this embodiment, step S3 can significantly improve the program's running efficiency when processing large amounts of data; it can reduce memory usage and computational complexity through rasterization; and it can achieve accurate spatial calculations by combining the Haversine formula and Euclidean distance. This algorithm is particularly suitable for application scenarios that require processing large amounts of AIS trajectory data, and can significantly improve computational efficiency while ensuring the accuracy of judgment.

[0067] S4. If the value exceeds the threshold, use the `geometry.intersects` function to determine the intersection. This function is the core method in the GeoPandas and Shapely libraries for determining spatial relationships, used to check if two geometric objects have spatial intersection.

[0068] S5. Calculate the distance threshold:

[0069] The calculation time and judgment results of different methods for the same two points are statistically analyzed. The accuracy rate is calculated based on the highest accuracy as the benchmark, and the time-distance curve and the accuracy-distance curve are obtained. The distance threshold is determined according to the results and actual needs.

[0070] Currently, the basic logic for determining the relationship between a line segment and a coastline is to determine the relationship between the line and a polygon. However, the higher the precision of the coastline, the more complex the polygon becomes, and the time required for each determination increases exponentially. With the development of artificial intelligence and big data, a single calculation may involve millions of data judgments. Therefore, considering the calculation characteristics under different distances and computer logic, this invention proposes a distance threshold-based calculation method. Different time-distance curves are generated to determine the threshold. When the distance is below the threshold, the map data is rasterized, and a data index is used to query the relationship between points on the line segment and land to determine whether the line segment crosses land. When the distance is above the threshold, traditional methods are used for calculation, optimizing calculation time and accuracy.

[0071] Example 1

[0072] A method for quickly determining the relationship between a line segment and a coastline includes the following steps:

[0073] S1, Raster map data:

[0074] Map rasterization can be directly converted using geographic information systems (GIS) tools. To ensure computational efficiency and memory usage, it is recommended to select an integer multiple of the raster resolution when choosing the range to reduce index calculation errors. The converted result should be saved as a binary file to improve program reading efficiency. This invention downloads coastline data from the website soest.hawaii.edu, including five resolutions: full resolution (complete data resolution), high resolution (size and quality reduced by approximately 80%), medium resolution (reduced by approximately 80% compared to high resolution), low resolution (reduced by approximately 80% compared to medium resolution), and simplified resolution (reduced by approximately 80% compared to low resolution). The coastline data is rasterized using ArcGIS (Geographic Information System platform) at full resolution, and the data is saved in binary format with a resolution of 0.01.

[0075] S2. Determine the relationship between the line segment and the land:

[0076] (1) Use the np.fromfile function to read the raster data file, and use the reshape function to convert the data into a two-dimensional array according to the resolution and save it in the land_grid variable.

[0077] (2) Use the math.radians function in Python to convert latitude and longitude to radians, and calculate the distance between two points using the Haversine formula.

[0078] S3. If the distance between two points is less than the distance threshold, the rasterization method proposed in this invention is used for calculation.

[0079] (1) Call the get_line_grid_indices function to calculate the grid index on the line from the start point to the end point. This function is a user-defined function, and its main function is to calculate the grid index list of all points on the line using the start point, end point and grid resolution.

[0080] a. Call the `coord_to_grid_inde` function to calculate the raster index on the line segment from the start point to the end point. This function is a user-defined function, and its main function is to convert latitude and longitude coordinates into a two-dimensional array index and return it. The conversion relationship is shown in the formula:

[0081] Lon_idx = round(lon - origin_lon) / ratio;

[0082] Lat_idx = round(lat - origin_lat) / ratio;

[0083] The `round` function is used to round numerical values. `Lon_idx` represents the index of longitude in the two-dimensional array, `Lat_idx` represents the index of latitude in the two-dimensional array, `lon` and `lat` represent the latitude and longitude coordinates of the point to be calculated, `origin_lon` and `origin_lat` represent the starting longitude and latitude of the original raster data, respectively, and `ratio` represents the resolution of the raster data.

[0084] b. Calculate the number of sampling points required, num_points, using the formula shown below:

[0085] num_points = int(round(math.hypot((end_lon - start_lon), (end_lat -start_lat)) / ratio));

[0086] The `int` function is a rounding function in Python, the `math.hypot` function is used to calculate the Euclidean distance (i.e., the length of the hypotenuse of a right triangle), and `end_lon`, `start_lon`, `end_lat`, and `start_lat` are the latitude and longitude coordinates of the starting and ending points, respectively.

[0087] c. The index of each sampling point is calculated by calling the coord_to_grid_index function in a loop, generating an index list.

[0088] d. Remove duplicate values ​​from the list, add the starting and ending indices to the beginning and end positions respectively, and return the final index list.

[0089] (2) Circulate the index list and query whether the points are on land in order of land_grid(lon_idx,lat_idx).

[0090] (3) If the loop ends on land, return to TRUE, that is, the line connecting the two points crosses the land.

[0091] (4) If not on land, continue the loop until the loop ends and return to FALSE, that is, the line connecting the two points does not cross the land.

[0092] S4. If the value exceeds the threshold, use the `geometry.intersects` function for judgment. This function is the core method in the GeoPandas and Shapely libraries for spatial relationship judgment, used to check whether two geometric objects (such as points, lines, and polygons) have spatial intersection (i.e., whether they intersect). It is a basic method in this field and will not be described in detail.

[0093] S5. Calculate the distance threshold:

[0094] This invention uses real data aggregated from AIS tracks for testing, comparing the computation time and judgment results of this method and different resolutions for the same two points. The computation time was calculated 1000 times, and the average of 10 calculations was taken to obtain the time-distance curve as shown below. Figure 2 As shown; using full resolution as a benchmark, the accuracy-distance curve is calculated, as follows. Figure 3 As shown. After comprehensive analysis, a distance threshold of 4000 kilometers was selected. Data smaller than the distance threshold was rasterized, while data larger than the threshold was processed using low-resolution data. In actual operation, this method saved 40% of the time compared to simply using medium resolution.

[0095] The above description is only a preferred embodiment of the present invention and is not intended to limit the present invention. Any modifications, equivalent substitutions, improvements, etc., made within the spirit and principles of the present invention should be included within the protection scope of the present invention.

Claims

1. A method for quickly determining the relationship between a line segment and a coastline, characterized in that: Includes the following steps: S1, rasterized map data; S2. Determine the relationship between the line segment and the land, including: S3. If the distance between the two endpoints of a line segment is less than the distance threshold, the rasterization method is used for calculation. S4. If the distance between the two endpoints of a line segment is greater than the distance threshold, use the geometry.intersects function to determine the distance. In step S3, if the distance between the two endpoints of a line segment is less than a distance threshold, a rasterization method is used for calculation, including the following steps: S31. Call the get_line_grid_indices() function to calculate the raster indexes on the line from the start point to the end point. The get_line_grid_indices() function calculates a list of raster indexes for all points on the line using the start point, end point, and raster resolution. S32. Circularly query the index list, checking if a point is on land according to land_grid(lon_idx,lat_idx): If there exists a point on land that ends the loop and returns TRUE, then the line segment crosses the land. If a point is not on land, continue the loop until the loop ends, then return FALSE. If all points have been checked and none of them are on land, then the line segment does not cross the land. In step S31, the get_line_grid_indices() function is called to calculate the grid indices on the line from the start point to the end point, including the following steps: S311. Call the coord_to_grid_inde function to calculate the grid index on the line segment from the start point to the end point. The function of coord_to_grid_inde is to convert latitude and longitude coordinates into a two-dimensional array index and return it. S312. Calculate the number of sampling points required, num_points; S313. The index of each sampling point is calculated by calling the coord_to_grid_index function in sequence through a loop, and an index list is generated. S314. Remove duplicate values ​​from the list, add the starting and ending indices to the beginning and end positions respectively, and return the final index list.

2. The method for quickly determining the relationship between a line segment and a coastline according to claim 1, characterized in that: In step S1, the geographic information tool is used for conversion, and the range is selected as an integer multiple of the raster resolution; the converted result is saved as a binary file.

3. The method for quickly determining the relationship between a line segment and a coastline according to claim 1, characterized in that: In step S2, the relationship between the line segment and the land is determined, including: S21. Use the np.fromfile function to read the raster data file, and use the reshape function to convert the data into a two-dimensional array according to the resolution and store it in the land_grid variable; S22. Use the math.radians function in Python to convert latitude and longitude to radians, and calculate the distance between the two endpoints of the line segment using the Haversine formula.

4. The method for quickly determining the relationship between a line segment and a coastline according to claim 1, characterized in that: In step S311, the conversion relationship of the coord_to_grid_index function is shown in the formula: Lon_idx = round(lon - origin_lon) / ratio; Lat_idx = round(lat - origin_lat) / ratio; The `round` function is used to round numerical values. `Lon_idx` represents the index of longitude in the two-dimensional array, `Lat_idx` represents the index of latitude in the two-dimensional array, `lon` and `lat` represent the latitude and longitude coordinates of the point to be calculated, `origin_lon` and `origin_lat` represent the starting longitude and latitude of the original raster data, respectively, and `ratio` represents the resolution of the raster data.

5. The method for quickly determining the relationship between a line segment and a coastline according to claim 1, characterized in that: In step S312, the formula for calculating num_points is as follows: num_points = int(round(math.hypot((end_lon - start_lon), (end_lat - start_lat)) / ratio)); The `int` function is a rounding function in Python, the `math.hypot` function is used to calculate Euclidean distance, and `end_lon`, `start_lon`, `end_lat`, and `start_lat` are the latitude and longitude coordinates of the starting and ending points, respectively.

6. The method for quickly determining the relationship between a line segment and a coastline according to claim 1, characterized in that: Calculating the distance threshold includes: The calculation time and judgment results of different methods for the same two points are statistically analyzed. The accuracy rate is calculated based on the highest accuracy as the benchmark, and the time-distance curve and the accuracy-distance curve are obtained. The distance threshold is determined according to the results and actual needs.

Citation Information

Patent Citations

  • Point location judgment method applied to visual map rendering technology

    CN120104708A