Redis database-based track management and drawing method
By adopting the Redis database-based track management and drawing methods in the chart software, the problem of lag in the chart software when processing a large amount of target track information is solved, and efficient real-time track drawing is achieved.
Patent Information
- Application Number
- CN202510070955.2
- Authority / Receiving Office
- CN · China
- Patent Type
- Applications(China)
- Current Assignee / Owner
- Filing Date
- 2025-01-16
- Publication Date
- 2025-05-30
AI Technical Summary
Existing chart software will cause lag or crash when processing large amounts of target track information, especially when the number of targets reaches thousands.
The track management and drawing method based on Redis database is adopted, and the target track information data structure is constructed by building a client-server relationship service program, using Redis services to build a target track information data structure, and receive real-time track point data through threads, establish a stored procedure and a target index table, and store the target into the database. The client program obtains the target track point data in real time and draws the track.
Through the key-value index of the Redis database, the complexity of the target search time is reduced to O(1). Combined with point extraction and dynamic drawing technology, the number of targets that need to be drawn at the same time is reduced, the program operation efficiency is improved, and the need for real-time drawing of tracks under a large number of target data.
Smart Images

Figure CN120067179A_ABST
Abstract
Description
Technical Field
[0001] The present invention belongs to the technical field of chart situation drawing, and particularly relates to a track management and drawing method based on a Redis database. Background Art
[0002] When drawing target situation information on a chart, track information can intuitively display the running track of a target, which has great reference significance for marine environment monitoring and special target identification. With the development of radar front-end detection equipment and the increase in the number of coastal vessels, the cumulative number of generated target points will be more and more, which will cause the chart software to become more and more stuck during operation.
[0003] For the storage and addressing of track information, data structures such as arrays or linked lists are often used. On the chart software, the software receives the point track information of the target in real time, including the target ID, longitude and latitude, arrival time, and specific parameter information of the target, and then matches the target according to the target ID information and performs drawing and updating. Therefore, for the front-end chart software, it is necessary to regularly receive data, match, and update the point track information of each target and redraw the ship target information on the chart. Practical use shows that when the number of targets is dozens or hundreds, it can barely meet the real-time requirements. When the number of targets reaches thousands, the chart software will obviously become stuck or even crash. Summary of the Invention
[0004] The purpose of the present invention is to solve the problems raised in the background art, and propose a track management and drawing method based on a Redis database.
[0005] In order to achieve the purpose of the present invention, the present invention discloses a track management and drawing method based on a Redis database, including the following steps:
[0006] S1. Construct a client-server relationship service program, and use a Redis service in the server program to construct a target track information data structure;
[0007] S2. The server program establishes a thread to receive real-time track point data through the network, and establishes a storage procedure and a target index table to store the target in the database;
[0008] S3. The client program obtains the target track point data in real time and sends it to the electronic chart for track drawing.
[0009] Further, the target track information data structure in S1 includes basic attribute information such as a unique identifier of the target ID, the current longitude and latitude of the target, the interception time, the target historical point information, and the target parameter information, such as the target recognition result.
[0010] Further, the specific steps of S2 are:
[0011] S21. For the target information, first check whether the target exists in the current database according to the target ID information.
[0012] S22. If the target already exists, update the target track information to the current track information and store the original target track information in the historical track information.
[0013] S23. If the target information does not exist, add a new target information in the database and update the index table.
[0014] Furthermore, the storage procedure in S2 is as follows: when storing into the database, call the storage procedure for storage and establish a data index table, including the data table name, start time, end time, and the current data volume of the table; the first table to be stored is T_info_0000001, and after storing 100,000 pieces of data, establish the table T_info_0000002, and so on and update the index table information.
[0015] Furthermore, batch the new targets to generate Redis nodes, and for the existing targets, associate them with the original target IDs in the database.
[0016] Furthermore, select the String type for the target data storage type and use the Hash type index table for the index table.
[0017] Furthermore, the track drawing in S3 is divided into two modes, namely the real-time mode and the playback mode; in the real-time mode, query the data in the database for the first thirty minutes before the current time, and obtain the information such as the target ID, location, and attribute parameters for drawing; in the playback mode, according to the playback screening parameters, including the time range, target attribute information, etc., query and return the historical data that meets the conditions, and draw according to the playback time in sequence.
[0018] Furthermore, in S3, generate the target navigation track information according to the target historical track information, generate the target location information according to the target current track information, generate the target type model according to the target type information, and rotate the target model direction according to the target heading information, and store the target drawing information in the drawing cache; when the electronic chart is zoomed and dragged, update the track information to be drawn in real time to reduce the consumption of drawing resources and reduce lags.
[0019] Furthermore, calculate the distance between adjacent target points according to the chart zoom ratio, and use the way of sampling points for drawing for the targets with too close distances; calculate whether the target is within the display box according to the chart dragging position, and do not draw the targets outside the display box; to reduce the resource overhead of drawing graphics.
[0020] Furthermore, S3 specifically includes the following steps:
[0021] S31. In the real-time mode, query the data in the database for the thirty minutes before the current time, obtain information such as the target ID, location, and attribute parameters for drawing.
[0022] S32. In the playback mode, according to the playback screening parameters, including the time range, target attribute information, etc., query and return the historical data that meets the conditions, and draw them in sequence according to the playback time.
[0023] S33. Confirm the chart display window range RECT(x0, y0, x1, y1) according to the chart display frame, where x0 and y0 are the starting longitude and latitude information, and x1 and y1 are the ending longitude and latitude information; for the track target information (x, y), first determine whether the target is within the RECT range, and then determine whether it needs to be drawn.
[0024] S34. Generate the adjacent target distance parameter N0 according to the chart scaling ratio. For the track target information S1(x1, y1) and S2(x2, y2), calculate the distance between the two targets as N. If N < N0, then do not draw the target S2 to reduce resource consumption.
[0025] Compared with the prior art, the significant progress of the present invention lies in: a method for managing and drawing target track information based on an electronic chart. Since a Redis database key-value index is established for the track information, the time complexity of target lookup is O(1). Secondly, through point extraction and dynamic drawing, the number of targets to be drawn at the same time is reduced, and the program operation efficiency is improved without affecting the display effect. Compared with the prior art, it ensures the smooth operation of the program without freezing when the number of track targets to be drawn is large.
[0026] To more clearly illustrate the functional characteristics and structural parameters of the present invention, the following further explains in conjunction with the drawings and specific embodiments. BRIEF DESCRIPTION OF THE DRAWINGS
[0027] The drawings described herein are used to provide a further understanding of the present invention, form a part of this application, and the schematic embodiments and descriptions of the present invention are used to explain the present invention and do not constitute an improper limitation of the present invention. In the drawings:
[0028] Figure 1 It is a flowchart of a method for managing and drawing target track information based on a Redis database of the present invention. DETAILED DESCRIPTION OF THE EMBODIMENTS
[0029] The following will clearly and completely describe the technical solutions in the embodiments of the present invention in conjunction with the accompanying drawings in the embodiments of the present invention. Obviously, the described embodiments are only a part of the embodiments of the present invention, rather than all the embodiments; based on the embodiments of the present invention, all other embodiments obtained by those of ordinary skill in the art without creative efforts shall fall within the protection scope of the present invention.
[0030] The present invention mainly realizes a method for managing and drawing target track information based on the Redis database. It is mainly used to solve the problem of lag in drawing track information when the amount of track data is large. Redis is a high-performance non-relational in-memory key-value database that can store the mapping between keys and five different types of values, and can persist the key-value pair data stored in memory to the hard disk. To solve the problem of lag in drawing tracks, the present invention proposes an optimized method for managing track information. Deploy a Redis database node on the local machine, process and store the track information with the target ID as the key value, and then retrieve the time of the target point position information, longitude and latitude values through the key value for drawing the track during drawing, optimizing the computational time complexity of matching the point track information with the target from O(n) to O(1), thereby significantly improving the running efficiency of the chart software and realizing the requirement of real-time track drawing under the condition of a large amount of target data.
[0031] As Figure 1 shown, the technical solutions mainly realized by the present invention include:
[0032] S1. Build a client-server relationship service program, and use the Redis service in the server program to build a target track information data structure;
[0033] Among them, the target track data structure in step S1 includes basic attribute information such as a unique identifier of the target ID, the current longitude and latitude of the target, the interception time, the target historical point information, and the target parameter information, such as the target recognition result.
[0034] S2. The server program establishes a thread to receive real-time track point data through the network, establish a storage process and a target index table, and store the target in the database;
[0035] Among them, for the storage process in step S2, the storage process is called for storage during storage, and a data index table is established, including the data table name, start time, end time, and the current amount of data in the table. The first table to be stored is T_info_0000001. After storing 100,000 pieces of data, the table T_info_0000002 is established, and so on, and the index table information is updated. Among them, for new targets, batches are compiled to generate Redis nodes, and for existing targets, they are associated with the original target IDs in the library.
[0036] S3. The client program obtains the target track point data in real time and sends it to the electronic chart for track plotting.
[0037] Among them, the track plotting in step S3 is mainly divided into two modes, namely the real-time mode and the playback mode. In the real-time mode, query the data in the database for the thirty minutes before the current time, and obtain information such as the target ID, location, and attribute parameters for plotting. In the playback mode, according to the playback screening parameters, including the time range, target attribute information, etc., query and return the historical data that meets the conditions, and plot them in sequence according to the playback time.
[0038] Among them, for the part of plotting the track in step S3, calculate the distance between adjacent target points according to the chart scale, and use the method of sampling points for plotting for targets with too close distances; calculate whether the target is within the display box according to the chart dragging position, and do not plot the targets outside the display box. To reduce the resource overhead of the plotted graphics.
[0039] Specifically, in one embodiment, the data structure of the target track information is as follows:
[0040]
[0041] Among them, the tail reserved word can add target attribute information according to the specific project.
[0042] Specifically, in one embodiment, the server program creates a thread to receive real-time track point data through the network, establishes a storage procedure and a target index table, and stores the targets in the database; the target data storage type is selected as the String type, and the table index uses a Hash type index table.
[0043] For the target information, first check whether the target exists in the current database according to the target ID information; if the target already exists, update the target point trace information to the current point trace information, and store the original target point trace information in the historical point trace information; if the target information does not exist, add a new target information in the database and update the index table.
[0044] Specifically, in one embodiment, the created index structure is as follows:
[0045]
[0046]
[0047] Specifically, in one embodiment, the client program obtains target track point data in real time and sends it to the electronic chart for track plotting; generates target navigation track information based on target historical point information, generates target position information based on target current point information, generates target type models according to target type information, such as airplanes, ships, etc., and rotates the target model direction according to the target heading information, and stores the target plotting information in the plotting cache. Among them, when the electronic chart is zoomed or dragged, the track information to be plotted is updated in real time to reduce the consumption of plotting resources and reduce lags.
[0048] Specifically, the track plotting code is as follows:
[0049]
[0050] m_tagRDWMsg[kk].m_TTI = info;
[0051] m_tagRDWMsg[kk].m_stTip = strTip;
[0052] m_tagRDWMsg[kk].usUpdateHistroyTrackInfo();
[0053] break;
[0054] }
[0055] }
[0056] In real-time mode, query the data in the database for the last thirty minutes before the current time, and obtain information such as target ID, position, and attribute parameters for plotting. In playback mode, according to the playback screening parameters, including time range, target attribute information, etc., query and return the historical data that meets the conditions, and plot them in sequence according to the playback time. Confirm the sea chart display window range RECT(x0, y0, x1, y1) according to the sea chart display frame, where x0 and y0 are the starting longitude and latitude information, and x1 and y1 are the ending longitude and latitude information. For the track target information (x, y), first determine whether the target is within the RECT range, and then determine whether it needs to be plotted. According to the sea chart scale, generate the adjacent target distance parameter N0. For the track target information S1(x1, y1) and S2(x2, y2), calculate the distance between the two targets as N. If N < N0, then target S2 is not plotted to reduce resource overhead.
[0057] It should be noted that in this text, relational terms such as first and second are only used to distinguish one entity or operation from another entity or operation, and do not necessarily require or imply any actual relationship or order between these entities or operations. Moreover, the term "comprising", "including" or any other variant thereof is intended to cover non-exclusive inclusion, so that a process, method, article or device comprising a series of elements not only includes those elements, but also includes other elements not expressly listed, or elements inherent to such process, method, article or device.
[0058] Although the embodiments of the present invention have been shown and described, those of ordinary skill in the art can understand that various changes, modifications, substitutions and variations can be made to these embodiments without departing from the principles and spirit of the present invention. The scope of the present invention is defined by the appended claims and their equivalents.
Claims
1. A track management and drawing method based on Redis database, characterized in that: The following steps are involved: S1. Build a client-server relationship service program, and use Redis service in the server program to build a target track information data structure; S2, the server program establishes a thread to receive real-time track point data through the network, and establishes a storage process and target index table to store the target in the database; S3. The client program obtains the target track point data in real time and sends it to the electronic chart for track drawing.
2. According to a method for track management and drawing based on Redis database in claim 1, it is characterized in that: The target track information data structure in S1 includes the target ID unique identifier, the target's current latitude and longitude, the interception time, the target's historical point information, and the target parameter information.
3. A track management and drawing method based on Redis database according to claim 1, characterized in that: The specific steps of S2 are: S21, for the target information, first search whether the target exists in the current database according to the target ID information; S22, if the target already exists, update the target point trace information to the current point trace information, and store the original target point trace information into the historical point trace information; S23. If the target information does not exist, add a new target information to the database and update the index table.
4. A track management and drawing method based on Redis database according to claim 1, characterized in that: The stored procedure in S2 is as follows: when data is entered into the database, the stored procedure is called to enter the database and a data index table is established, including the data table name, start time, end time and current table data volume; the first table entered into the database is T_info_0000001, and after storing 100,000 data items, table T_info_0000002 is established, and so on and so forth, and the index table information is updated.
5. A track management and drawing method based on Redis database according to claim 4, characterized in that: For new targets, batch them and generate Redis nodes. For existing targets, associate them with the original target IDs in the library.
6. A track management and drawing method based on Redis database according to claim 1, characterized in that: The target data storage type is String type, and the index table uses Hash type index table.
7. A track management and drawing method based on Redis database according to claim 1, characterized in that: Track drawing in S3 is divided into two modes, namely real-time mode and playback mode. In real-time mode, the database is queried for data thirty minutes before the current time, and the target ID, location, and attribute parameter information are obtained for drawing. In playback mode, according to the playback filtering parameters, including time range and target attribute information, the query returns the historical data that meets the conditions, and draws them in sequence according to the playback time.
8. A track management and drawing method based on Redis database according to claim 1, characterized in that: In S3, target navigation track information is generated according to target historical point information, target position information is generated according to target current point information, target type model is generated according to target type information, and the target model is rotated according to target heading information, and target drawing information is stored in drawing cache; When zooming and dragging the electronic chart, the track information that needs to be drawn is updated in real time to reduce drawing resource consumption and reduce lag.
9. A track management and drawing method based on Redis database according to claim 8, characterized in that: The distance between adjacent target points is calculated according to the chart zoom ratio. For targets whose distance is lower than the threshold, point sampling is used for drawing. The target is calculated whether it is within the display box according to the drag position of the chart. Targets outside the display box are not drawn to reduce the resource overhead of drawing graphics.
10. A track management and drawing method based on Redis database according to claim 8, characterized in that: S3 specifically includes the following steps: S31. In real-time mode, query the database for data thirty minutes before the current time, obtain target ID, location, attribute parameters and other information for drawing; S32, in playback mode, according to playback screening parameters, including time range, target attribute information, etc., query and return historical data that meets the conditions, and draw them in sequence according to playback time; S33. Confirm the chart display window range RECT(x0, y0, x1, y1) according to the chart display frame, where x0 and y0 are the starting longitude and latitude information, and x1 and y1 are the ending longitude and latitude information; for the track target information (x, y), first determine whether the target is within the RECT range, and then determine whether it needs to be drawn. S34. Generate the adjacent target distance parameter N0 according to the chart scale. For the track target information S1(x1, y1) and S2(x2, y2), calculate the distance between the two targets as N. If N < N0, then do not draw the target S2 to reduce resource consumption.