A GDAL-based map drawing slicing method and device and readable medium
By dividing the map into objects to be drawn and performing batch tile drawing, the problems of large-scale drawing difficulties and repeated labeling in GDAL map tiling are solved, and a fast and efficient tiling process is achieved.
Patent Information
- Application Number
- CN202310665828.8
- Authority / Receiving Office
- CN · China
- Patent Type
- Patents(China)
- Current Assignee / Owner
- Filing Date
- 2023-06-07
- Publication Date
- 2026-11-27
- Estimated Expiration
- 2043-06-07
AI Technical Summary
Existing GDAL-based map tiling methods suffer from several problems, including the inability to draw large-scale maps in one go, repeated labeling of linear and area features in adjacent tiles, incomplete labeling of point features, and time-consuming repetitive operations during the drawing process.
The map to be drawn is divided into several objects to be drawn, virtual rows and virtual columns are set, batch tiles are drawn and tiles in virtual rows and columns are discarded, and GDAL is used to generate tile data.
It shortens the drawing time, avoids repeated labeling of linear and area features, improves slicing efficiency, reduces repetitive operations, and solves the problem of cross-boundary labeling.
Smart Images

Figure CN116757912B_ABST
Abstract
Description
Technical Field
[0001] This invention relates to the field of map tiling, and more specifically to a method, apparatus, and readable medium for map tiling based on GDAL. Background Technology
[0002] Currently, tile mapping technology has become a widely used model for public map services on the internet. Tile maps utilize map tiling technology to create image sets from vector data, stored in a pyramid grid format according to "levels, rows, and columns." These can be selectively and quickly loaded on web pages based on the user's chosen map level and view extent. However, the map tile generation process in current commercial GIS software is complex and extremely time-consuming. Therefore, how to conveniently, quickly, and efficiently generate map tiles using high-performance computing technology under the same conditions has become a crucial problem that must be solved.
[0003] Currently, map tiling methods mainly fall into the following categories:
[0004] 1. Utilize the computing power of GPUs for parallel acceleration to achieve tiled batch processing operations;
[0005] 2. By using a distributed cluster system, the slicing task is divided into multiple subtasks, and each subtask is performed simultaneously on multiple distributed nodes. This method can conveniently parallelize the original serial method.
[0006] 3. Based on multi-threaded parallel technology, each thread divides the task into multiple subtasks, and each subtask is performed simultaneously.
[0007] The tile map tiling scheme is the basis for calculating the "level, row, and column" of the tile map, mainly composed of the tile origin, tile resolution (scale), drawing area, and tile pixel size. The generation of each tile involves calculating the actual effective area using an algorithm, and then reading the data within that area into memory. GDAL is used to generate and save image data in a specified format, and the file is named and saved according to the current tile's level, row number, and column number.
[0008] In the implementation process, methods based on GDAL for calculating and drawing tiles, whether in parallel or distributed clusters, inevitably suffer from the following problems:
[0009] 1. When drawing based on GDAL, there is a size limit to the image objects it saves, making it impossible to draw large areas. Figure 1 One-time drawing.
[0010] 2. Linear and area features will be repeatedly labeled in adjacent tiles; there will be cases where linear or area features in the current map area are incomplete and are not labeled or are only partially labeled.
[0011] 3. Point-like labels only display part of their content in the slice they are in, but not in adjacent slices;
[0012] 4. Map drawing based on GDAL mainly involves loading map data, drawing map symbols, and calculating and drawing annotation positions. These operations need to be repeated for each tile during the tiling process, which is extremely time-consuming. Summary of the Invention
[0013] In view of the aforementioned technical problems, the purpose of the embodiments of this application is to provide a GDAL-based map tiling method, apparatus, and readable medium to solve the technical problems mentioned in the background section.
[0014] In a first aspect, the present invention provides a map tiling method based on GDAL, comprising the following steps:
[0015] S1: Obtain the vector layer and set the slicing parameters;
[0016] S2, in the vector layer, determine the coordinate range of the map to be drawn, calculate the size of each tile at the current tile level according to the tile parameters, and calculate the row and column numbers of the tiles corresponding to the boundary of the map to be drawn on the world map;
[0017] S3, divide the tiles within the boundary of the map to be drawn to obtain at least one object to be drawn. In each object to be drawn, a row and / or a column of the tiles on the edge other than the edge of the map to be drawn is set as a virtual row and / or a virtual column. Calculate the row and column numbers of the tiles corresponding to the boundary of each object to be drawn on the world map based on the row and column numbers of the tiles corresponding to the boundary of the map to be drawn on the world map.
[0018] S4. Calculate the drawing range based on the row and column numbers of the tiles corresponding to the boundary of each object to be drawn on the world map and the size of each tile. Slice each object within the drawing range according to the slicing parameters. During the slicing process, discard the tiles in the virtual rows and / or virtual columns of each object to be drawn to obtain the slice data.
[0019] Preferably, step S1 also includes setting the symbolization and annotation of the vector layer, and setting the visible scale of the annotation.
[0020] Preferably, the slicing parameters include tile boundaries, tile storage format, projection method, slicing level, and image size and type.
[0021] Preferably, step S2 specifically includes:
[0022] In response to the determination that the projection method is latitude and longitude projection, a map is generated in Tianditu format. The coordinate range on the world map is MinX, MaxX, MinY, MaxY, and the current tile level is Level. The number of tiles in each row and each column, TileMatrixWidth and TileMatrixHeight, are calculated using the following formulas:
[0023] TileMatrixWidth = 2 Level ;
[0024] TileMatrixHeight = 2 Level - 1 ;
[0025] The width (TileWidth) and height (TileHeight) of each tile at the current tile level are calculated using the following formula:
[0026] TileWidth = (MaxX - MinX) / (2 Level );
[0027] TileHeight = (MaxY - MinY) / (2 Level – 1 );
[0028] Define the coordinate range of the map to be drawn as minX, maxX, minY, maxY. Calculate the row and column numbers of the tiles corresponding to the boundaries of the map on the world map as firstrow, endrow, firstcol, endcol using the following formula:
[0029] firstrow = ⌊|MaxY - maxY| / TileHeight⌋;
[0030] endrow = ⌊|MaxY - minY| / TileHeight⌋;
[0031] firstcol =⌊|minX - MinX| / TileWidth⌋;
[0032] endcol = ⌊|maxX - MinX| / TileWidth⌋.
[0033] Preferably, the objects to be drawn contain RCount*CCount tiles, where RCount represents the number of rows of tiles in each object to be drawn, and CCount represents the number of columns of tiles in each object to be drawn. In response to the existence of at least two objects to be drawn, the two adjacent objects to be drawn overlap, and the overlapping area is the virtual row and / or virtual column corresponding to the overlapping edge of the two objects to be drawn that are arranged side by side in the adjacent direction.
[0034] Preferably, in step S3, the row and column numbers of the tiles corresponding to the boundary of each object to be drawn on the world map are calculated based on the row and column numbers of the tiles corresponding to the boundary of the map to be drawn. This specifically includes:
[0035] If we use indexR and indexC as the row and column numbers for the objects to be drawn, initially set to 0, and draw in a loop from row to column, then the row and column numbers of the tile corresponding to the boundary of each object on the world map are:
[0036] firstcolTemp=firstcol+indexC*(CCount-2);
[0037] endcolTemp=firstcol+indexC*(CCount-2)+CCount;
[0038] firstrowTemp=firstrow+indexR*( RCount-2);
[0039] endrowTemp=firstrow+indexR*( RCount-2)+ RCount;
[0040] If endrowTemp is greater than endrow, then endrowTemp = endrow, RCount = endrow - firstrowTemp; if endcolTemp is greater than endcol, then endcolTemp = endcol, CCount = endcol - firstcolTemp.
[0041] Preferably, step S4 calculates the drawing range based on the row and column numbers of the tiles corresponding to the boundary of each object to be drawn on the world map and the size of each tile, specifically including:
[0042] The drawing range is calculated using the following formula:
[0043] TileMinX = MinX+firstcolTemp*TileWidth;
[0044] TileMaxX = MinX+endcolTemp*TileWidth;
[0045] TileMinY = MaxY - firstrowTemp*TileHeight;
[0046] TileMaxY = MaxY - endrowTemp*TileHeight.
[0047] Secondly, the present invention provides a map drawing and tiling device based on GDAL, comprising:
[0048] The data acquisition module is configured to acquire vector layers and set slicing parameters;
[0049] The boundary determination module is configured to determine the coordinate range of the map to be drawn in the vector layer, calculate the size of each tile at the current tile level based on the tile parameters, and calculate the row and column numbers of the tiles corresponding to the boundary of the map to be drawn on the world map.
[0050] The partitioning module is configured to partition the tiles within the boundary of the map to be drawn to obtain at least one object to be drawn. In each object to be drawn, a row and / or a column of the edge tiles other than the boundary of the map to be drawn is set as a virtual row and / or a virtual column. The row and column numbers of the tiles corresponding to the boundary of the map to be drawn on the world map are calculated based on the row and column numbers of the tiles corresponding to the boundary of the map to be drawn on the world map.
[0051] The slicing module is configured to calculate the drawing range based on the row and column numbers of the tiles corresponding to the boundary of each object to be drawn on the world map and the size of each tile. It then slices each object within the drawing range according to the slicing parameters, discarding tiles in virtual rows and / or virtual columns of each object to be drawn during the slicing process to obtain slice data.
[0052] Thirdly, the present invention provides an electronic device including one or more processors; and a storage device for storing one or more programs, wherein when the one or more programs are executed by the one or more processors, the one or more processors implement the method as described in any implementation of the first aspect.
[0053] Fourthly, the present invention provides a computer-readable storage medium having a computer program stored thereon, which, when executed by a processor, implements the method as described in any of the implementations of the first aspect.
[0054] Compared with the prior art, the present invention has the following beneficial effects:
[0055] (1) The map drawing tiling method based on GDAL proposed in this invention first divides the map to be drawn into several objects to be drawn, and then draws all the tiles in the objects to be drawn at once, which can effectively shorten the drawing time.
[0056] (2) In the map drawing tiling method based on GDAL proposed in this invention, each object to be drawn contains the same number of rows and columns of tiles. In each object to be drawn, a row and / or a column of tiles on the edge other than the boundary of the map to be drawn is set as a virtual row and / or a virtual column. Two adjacent objects to be drawn overlap, and the overlapping area is the virtual row and / or virtual column corresponding to the overlapping edge of the two objects to be drawn that are set in the adjacent direction. The objects to be drawn are drawn and sliced. During the slicing process, the tiles in the virtual row and / or virtual column of each object to be drawn are discarded. This can avoid the situation where linear and area features are repeatedly labeled in adjacent slices, or the label of point features is only partially displayed in the slice in which it is located, but not in adjacent slices.
[0057] (3) The map drawing and tiling method based on GDAL proposed in this invention can reduce repetitive operations in the GDAL drawing process, shorten the drawing and tiling time, improve efficiency, and achieve rapid tiling. Attached Figure Description
[0058] To more clearly illustrate the technical solutions in the embodiments of the present invention, the accompanying drawings used in the description of the embodiments will be briefly introduced below. Obviously, the accompanying drawings described below are only some embodiments of the present invention. For those skilled in the art, other drawings can be obtained based on these drawings without creative effort.
[0059] Figure 1 A schematic flowchart illustrating a GDAL-based map tiling method according to an embodiment of this application;
[0060] Figure 2 A flowchart illustrating a GDAL-based map tiling method according to an embodiment of this application;
[0061] Figure 3 A schematic diagram of individually drawing tiles in the GDAL-based map drawing tiling method of an embodiment of this application;
[0062] Figure 4 This is a schematic diagram illustrating the simultaneous drawing of all tiles in the object to be drawn in the GDAL-based map drawing tiling method of this application according to an embodiment of the present application.
[0063] Figure 5A schematic diagram of the objects to be drawn in the map to be drawn in the GDAL-based map drawing tiling method according to an embodiment of this application;
[0064] Figure 6 A rendering of a map generated by the GDAL-based map tiling method according to an embodiment of this application;
[0065] Figure 7 This is a schematic diagram of a GDAL-based map drawing and tiling apparatus according to an embodiment of this application. Detailed Implementation
[0066] To make the objectives, technical solutions, and advantages of this invention clearer, the invention will be further described in detail below with reference to the accompanying drawings. Obviously, the described embodiments are merely some embodiments of this invention, and not all embodiments. Based on the embodiments of this invention, all other embodiments obtained by those skilled in the art without creative effort are within the scope of protection of this invention.
[0067] Figure 1 An embodiment of this application illustrates a GDAL-based map tiling method, comprising the following steps:
[0068] S1: Obtain the vector layer and set the slicing parameters.
[0069] In a specific embodiment, step S1 further includes setting the symbolization and annotation of the vector layer, and setting the visible scale of the annotation.
[0070] In specific embodiments, slicing parameters include tile boundaries, tile storage format, projection method, slicing level, and image size and type.
[0071] For details, please refer to Figure 2 In the vector data preparation stage, GIS software is used to load the vector layers to be displayed, and the symbolization and labeling of the vector layers are set. Specifically, the visible scale of the vector layer labels must be set to avoid dense overlap in the display. Then, the tiling parameters are input, and the vector layer is divided into tiles according to the tiling parameters.
[0072] S2, in the vector layer, determine the coordinate range of the map to be drawn, calculate the size of each tile at the current tile level according to the tile parameters, and calculate the row and column numbers of the tiles corresponding to the boundary of the map to be drawn on the world map.
[0073] In a specific embodiment, step S2 specifically includes:
[0074] In response to the determination that the projection method is latitude and longitude projection, a map is generated in Tianditu format. The coordinate range on the world map is MinX, MaxX, MinY, MaxY, and the current tile level is Level. The number of tiles in each row and each column, TileMatrixWidth and TileMatrixHeight, are calculated using the following formulas:
[0075] TileMatrixWidth = 2 Level ;
[0076] TileMatrixHeight = 2 Level - 1 ;
[0077] The width (TileWidth) and height (TileHeight) of each tile at the current tile level are calculated using the following formula:
[0078] TileWidth = (MaxX - MinX) / (2 Level );
[0079] TileHeight = (MaxY - MinY) / (2 Level – 1 );
[0080] Define the coordinate range of the map to be drawn as minX, maxX, minY, maxY. Calculate the row and column numbers of the tiles corresponding to the boundaries of the map on the world map as firstrow, endrow, firstcol, endcol using the following formula:
[0081] firstrow = ⌊|MaxY - maxY| / TileHeight⌋;
[0082] endrow = ⌊|MaxY - minY| / TileHeight⌋;
[0083] firstcol =⌊|minX - MinX| / TileWidth⌋;
[0084] endcol = ⌊|maxX - MinX| / TileWidth⌋.
[0085] Specifically, taking a world map as an example, the number of rows and columns of world map tiles is calculated based on the projection method and the current tile level. The width and height of each tile, as well as the row and column numbers of the tiles corresponding to the boundary of the map to be drawn on the world map, are also calculated. There are two methods for calculating the row and column numbers of tiles: one for supporting WMSC, and the other for supporting Tianditu, ArcGIS Discrete, Google Maps, and Google Earth. This embodiment uses longitude projection and Tianditu format as an example, where the number of tiles at each longitude level is 2 raised to the power of Level. The world map is divided according to the current tile level (Level) by 2 raised to the power of Level, and the width (TileWidth) and height (TileHeight) of each tile are calculated. Further, based on the coordinate range of the map to be drawn, the coordinate range of the world map, and the width (TileWidth) and height (TileHeight) of each tile, the row and column numbers of the tiles corresponding to the boundary of the map to be drawn on the world map are calculated as firstrow, endrow, firstcol, and endcol.
[0086] S3, divide the tiles within the boundary of the map to be drawn to obtain at least one object to be drawn. In each object to be drawn, a row and / or a column of the tiles on the edge other than the edge of the map to be drawn is set as a virtual row and / or a virtual column. Calculate the row and column numbers of the tiles corresponding to the boundary of each object to be drawn on the world map based on the row and column numbers of the tiles corresponding to the boundary of the map to be drawn on the world map.
[0087] In a specific embodiment, the object to be drawn contains RCount*CCount tiles, where RCount represents the number of rows of tiles in each object to be drawn, and CCount represents the number of columns of tiles in each object to be drawn. In response to the existence of at least two objects to be drawn, the two adjacent objects to be drawn overlap, and the overlapping area is the virtual row and / or virtual column corresponding to the overlapping edge of the two objects to be drawn that are arranged side by side in the adjacent direction.
[0088] In a specific embodiment, step S3 calculates the row and column numbers of the tiles corresponding to the boundary of each object to be drawn on the world map based on the row and column numbers of the tiles corresponding to the boundary of the map to be drawn. This specifically includes:
[0089] If we use indexR and indexC as the row and column numbers for the objects to be drawn, initially set to 0, and draw in a loop from row to column, then the row and column numbers of the tile corresponding to the boundary of each object on the world map are:
[0090] firstcolTemp=firstcol+indexC*(CCount-2);
[0091] endcolTemp=firstcol+indexC*(CCount-2)+CCount;
[0092] firstrowTemp=firstrow+indexR*( RCount-2);
[0093] endrowTemp=firstrow+indexR*( RCount-2)+ RCount;
[0094] If endrowTemp is greater than endrow, then endrowTemp = endrow, RCount = endrow - firstrowTemp; if endcolTemp is greater than endcol, then endcolTemp = endcol, CCount = endcol - firstcolTemp.
[0095] Specifically, existing technologies typically generate images by obtaining the range of each tile through row and column numbers, then drawing the corresponding information based on GDAL and generating an image. In this application's embodiment, a batch of tiles within a certain range is drawn at once to generate an image, and then each tile is extracted from the generated image. The image generated based on GDAL is stored in an image object. Due to the maximum pixel limit of the image object (32767x32767 pixels) and the memory limitation of the runtime environment, a maximum of RCount*CCount tiles are drawn at a time, where RCount and CCount can be adjusted according to the set tile size and pixel size. Drawing a batch of tiles at once has two advantages: firstly, because it is drawn at once using GDAL, the calculations related to initialization, symbolization, and annotation only need to be completed once, significantly reducing runtime compared to CCount*RCount calculations; secondly, drawing at once can solve the problem of annotations crossing boundaries. If the existing image generation method is used, for Figure 3 When drawing the right-hand tile separately, it is necessary to calculate whether the label (location A) in the left-hand tile will cross the boundary, and determine the location where the content crossing the boundary will be displayed. If the method proposed in the embodiments of this application is used to determine the object to be drawn, all RCount*CCount tiles are included in the object to be drawn, and further drawing and slicing are performed. The result is as follows. Figure 4As shown, this solves the problem of annotations crossing boundaries between upper and lower tiles. Therefore, using RCount*CCount tiles to form a single object to be drawn and drawing them simultaneously not only eliminates the need to consider the issue of annotations crossing boundaries but also improves the running speed. This is because adjacent objects to be drawn overlap, and their corresponding virtual rows and / or virtual columns are set side-by-side along their edges in adjacent directions.
[0096] During implementation, each drawing can proceed cyclically from row to column, using `indexR` and `indexC` as the drawing sequence numbers for the row and column of the object to be drawn, initially set to 0. The row and column numbers of the tiles corresponding to the boundaries of the map to be drawn on the world map, along with `RCount` and `CCount`, can be calculated to obtain the row and column numbers of the tiles corresponding to the boundaries of each object to be drawn on the world map. `RCount` and `CCount` do not necessarily need to be equal. Specifically, during actual generation, the maximum values of `RCount` and `CCount` can be adjusted according to the runtime environment and parameters (provided the saved image format and memory allow) to achieve optimal speed. If the number of rows and columns of the map range is less than `RCount` and `CCount`, it can be drawn all at once. A row and / or a column of tiles on the edges of the object to be drawn (excluding the edges of the map to be drawn) are drawn as part of the object itself, and tiles in virtual rows and / or virtual columns are also drawn, but these virtual rows and / or virtual columns must be discarded during tiling. From another perspective, each time the object to be drawn is obtained, it represents a large area of RCount * CCount. Then, each tile, excluding the boundary of the map to be drawn, is judged using a 3x3 grid. If the 3x3 grid centered on the tile falls within the area (RCount * CCount) of the object to be drawn, it is saved as a generated tile. Tiles on the boundary of the map to be drawn are generated directly. Therefore, it is possible to ensure that the outermost ring of tiles in the generated map can be judged and generated using a 3x3 grid centered on the tile.
[0097] S4. Calculate the drawing range based on the row and column numbers of the tiles corresponding to the boundary of each object to be drawn on the world map and the size of each tile. Slice each object within the drawing range according to the slicing parameters. During the slicing process, discard the tiles in the virtual rows and / or virtual columns of each object to be drawn to obtain the slice data.
[0098] In a specific embodiment, step S4 calculates the drawing range based on the row and column numbers of the tiles corresponding to the boundary of each object to be drawn on the world map and the size of each tile, specifically including:
[0099] The drawing range is calculated using the following formula:
[0100] TileMinX = MinX+firstcolTemp*TileWidth;
[0101] TileMaxX = MinX+endcolTemp*TileWidth;
[0102] TileMinY = MaxY - firstrowTemp*TileHeight;
[0103] TileMaxY = MaxY - endrowTemp*TileHeight.
[0104] Specifically, based on the coordinate range of the world map, the drawing range is calculated by combining the row and column numbers of the tiles corresponding to the boundaries of each object to be drawn on the world map, as well as the size of each tile. The objects to be drawn within this range are then drawn using GDAL. Labels are added before the drawing process, and the results are saved in an image object. During the drawing process, each object is drawn as a unit, but during tiling, tiles in virtual rows and / or virtual columns within each object must be discarded to avoid duplicate tiles.
[0105] To address the issue of tiles crossing boundaries, it's essential to ensure that the images of the surrounding nine-square grid for each generated tile are present in the current image object. For tiles located at the boundaries of each object to be drawn, such as those with row and column values of firstrow, endrow, firstcol, and endcol, a virtual row or column is added in the boundary direction before performing the nine-square grid check. Based on the set image size, the corresponding information is retrieved from the image object and saved as a separate tile image.
[0106] refer to Figure 5 For example: Draw the map within the range (1, 491) according to the size of each box, resulting in 6 objects to be drawn, with RCount and CCount both set to 6. After the 6 objects are drawn, the ranges of the generated image objects are (1, 191), (149, 339), (297, 487), (5, 195), (153, 343), and (301, 491).
[0107] The yellow areas represent overlapping portions. The ranges used to generate tiles for different image objects are as follows:
[0108] The range of tiles generated in the (1, 191) image object is (1, 153). During the slicing process, tiles on virtual columns 186-191 and virtual rows 6-191 are discarded.
[0109] The range of tiles generated in the image object (149, 339) is (186, 301). During the slicing process, tiles on the virtual columns 149-154 and 334-339 and the virtual rows 154-339 are discarded.
[0110] The range of tiles generated in the image object (297, 487) is (334, 486). During the slicing process, the tiles on the virtual columns 291-302 and the virtual rows 302-487 are discarded.
[0111] The range of tiles generated in the image object (5, 195) is (6, 158). During the slicing process, virtual rows 5-190 and virtual columns 190-195 are discarded.
[0112] The range of tiles generated in the image object (153, 343) is (191, 306). During the slicing process, the virtual columns 153-158 and 338-343 and the virtual row 153-338 are discarded.
[0113] The range of tiles generated in the image object (301, 491) is (339, 491). During the slicing process, virtual columns 301-306 and virtual rows 301-486 are discarded.
[0114] Although tile 188 was discarded during the slicing of the (1, 191) image object, it was retained in the (149, 339) image object.
[0115] Analyze the boundary tiles: For example, tile 1 has the boundary of the map to be drawn on its left and top, so add a row and column as virtual rows and columns to meet the requirements of the nine-square grid; the same applies to tiles 482, 10 and 491; the left side of tile 5 is the boundary, so add a virtual column on the left side to meet the requirements when judging; tile 6 is the same as tile 5, but its bottom is not the boundary, so it cannot meet the requirements in the (1, 191) image, but it can meet the requirements in the (5, 195) image; the same applies to tiles 486 and 487.
[0116] Specifically, during actual generation, the maximum values of RCount and CCount can be adjusted according to the operating environment and parameters (as long as the saved image format and memory allow) to achieve optimal speed.
[0117] by Figure 6Taking data as an example: locations G, C, and D, the corresponding nine-square grids containing their objects and labels are all drawn simultaneously by GDAL. Therefore, the relevant drawing parameters are the same, resulting in identical label positions, sizes, and other information. Although slicing is performed, it actually involves dividing the same image by range, avoiding boundary crossing issues. Furthermore, retrieving information from the image and saving it to a file only involves memory and I / O read / write operations, significantly reducing slicing time. The row and column numbers of the maximum drawing range determine whether all slicing is complete. If not, the row and column information for the new slice is recalculated, and the above process is repeated. Slicing is complete when all required slices have been generated.
[0118] To verify the efficiency of the GDAL-based map drawing tiling method proposed in the embodiments of this application, the following experiment was conducted. A level 17 tiling experiment was performed using OpenStreetMap map data on the QGIS platform. The experiment used Mercator projection, Tianditu format, and 256*256 pixel PNG images, and employed a single-threaded method. Tile generation was performed using both the commonly used single-tile generation method and the GDAL-based map drawing tiling method proposed in the embodiments of this application. After running both methods, 764,335 tile maps were generated, and the generation time is shown in Table 1. The tiles generated using the GDAL-based map drawing tiling method proposed in the embodiments of this application were verified to have resolved the cross-boundary labeling problem. Furthermore, compared to the single-tile generation method, it significantly reduces the generation time of tile data.
[0119] Table 1
[0120] Serial Number Single chip / time (seconds) This application / time (seconds) 1 660853 60256 2 681824 61532 3 675324 60125 4 680257 61879 5 681591 61944
[0121] Further reference Figure 7 As an implementation of the methods shown in the above figures, this application provides an embodiment of a map drawing tile device based on GDAL, which is similar to... Figure 1 Corresponding to the method embodiments shown, this device can be specifically applied to various electronic devices.
[0122] This application provides a GDAL-based map drawing and tiling device, including:
[0123] Data acquisition module 1 is configured to acquire vector layers and set slicing parameters;
[0124] Boundary determination module 2 is configured to determine the coordinate range of the map to be drawn in the vector layer, calculate the size of each tile at the current tile level according to the tile parameters, and calculate the row and column numbers of the tiles corresponding to the boundary of the map to be drawn on the world map.
[0125] The partitioning module 3 is configured to partition the tiles within the boundary of the map to be drawn to obtain at least one object to be drawn. In each object to be drawn, a row and / or a column of the tiles on the edge other than the edge of the map to be drawn is set as a virtual row and / or a virtual column. The row and column numbers of the tiles corresponding to the boundary of the map to be drawn on the world map are calculated based on the row and column numbers of the tiles corresponding to the boundary of the map to be drawn on the world map.
[0126] The slicing module 4 is configured to calculate the drawing range based on the row and column numbers of the tiles corresponding to the boundary of each object to be drawn on the world map and the size of each tile. It slices each drawing object within the drawing range according to the slicing parameters, discarding tiles in virtual rows or columns of each object to be drawn during the slicing process to obtain slice data.
[0127] It should be noted that the computer-readable medium described in this application can be a computer-readable signal medium, a computer-readable medium, or any combination thereof. A computer-readable medium can be, for example,—but not limited to—an electrical, magnetic, optical, electromagnetic, infrared, or semiconductor device, or any combination thereof. More specific examples of a computer-readable medium may include, but are not limited to: an electrical connection having one or more wires, a portable computer disk, a hard disk, random access memory (RAM), read-only memory (ROM), erasable programmable read-only memory (EPROM or flash memory), optical fiber, portable compact disk read-only memory (CD-ROM), optical storage device, magnetic storage device, or any suitable combination thereof. In this application, a computer-readable medium can be any tangible medium containing or storing a program that can be used by or in conjunction with an instruction execution device, apparatus, or device. In this application, a computer-readable signal medium can include a data signal propagated in baseband or as part of a carrier wave, carrying computer-readable program code. Such propagated data signals can take various forms, including but not limited to electromagnetic signals, optical signals, or any suitable combination thereof. Computer-readable signal media can also be any computer-readable medium other than a computer-readable medium, which can send, propagate, or transmit a program for use by or in connection with an instruction execution device, apparatus, or apparatus. The program code contained on the computer-readable medium can be transmitted using any suitable medium, including but not limited to: wireless, wire, optical fiber, RF, etc., or any suitable combination thereof.
[0128] Computer program code for performing the operations of this application can be written in one or more programming languages or a combination thereof, including object-oriented programming languages such as Java, Smalltalk, and C++, and conventional procedural programming languages such as the "C" language or similar programming languages. The program code can be executed entirely on the user's computer, partially on the user's computer, as a standalone software package, partially on the user's computer and partially on a remote computer, or entirely on a remote computer or server. In cases involving remote computers, the remote computer can be connected to the user's computer via any type of network—including a local area network (LAN) or a wide area network (WAN)—or it can be connected to an external computer (e.g., via the Internet using an Internet service provider).
[0129] The flowcharts and block diagrams in the accompanying drawings illustrate the architecture, functionality, and operation of possible implementations of apparatus, methods, and computer program products according to various embodiments of this application. In this regard, each block in a flowchart or block diagram may represent a module, segment, or portion of code containing one or more executable instructions for implementing a specified logical function. It should also be noted that in some alternative implementations, the functions indicated in the blocks may occur in a different order than those indicated in the drawings. For example, two consecutively indicated blocks may actually be executed substantially in parallel, and they may sometimes be executed in reverse order, depending on the functions involved. It should also be noted that each block in the block diagrams and / or flowcharts, and combinations of blocks in the block diagrams and / or flowcharts, can be implemented using dedicated hardware-based means to perform the specified function or operation, or using a combination of dedicated hardware and computer instructions.
[0130] The modules described in the embodiments of this application can be implemented in software or hardware. These modules can also be located within a processor.
[0131] In another aspect, this application also provides a computer-readable medium, which may be included in the electronic device described in the above embodiments; or it may exist alone and not assembled into the electronic device. The aforementioned computer-readable medium carries one or more programs. When the electronic device executes the aforementioned one or more programs, the electronic device causes the electronic device to: acquire a vector layer and set slicing parameters; determine the coordinate range of the map to be drawn in the vector layer, calculate the size of each tile at the current slicing level according to the slicing parameters, and calculate the row and column numbers of the tiles corresponding to the boundary of the map to be drawn on the world map; divide the tiles within the boundary of the map to be drawn to obtain at least one object to be drawn, setting one row and / or one column of the tiles on the edge of each object to be drawn (excluding the edge of the map to be drawn) as a virtual row and / or a virtual column, calculating the row and column numbers of the tiles corresponding to the boundary of each object to be drawn on the world map according to the row and column numbers of the tiles corresponding to the boundary of the map to be drawn on the world map; calculate the drawing range according to the row and column numbers of the tiles corresponding to the boundary of each object to be drawn on the world map and the size of each tile, slice each object within the drawing range according to the slicing parameters, discarding the tiles in the virtual rows and / or virtual columns of each object to be drawn during the slicing process, and obtaining slice data.
[0132] The above description is merely a preferred embodiment of this application and an explanation of the technical principles employed. Those skilled in the art should understand that the scope of the invention involved in this application is not limited to technical solutions formed by specific combinations of the above-described technical features, but should also cover other technical solutions formed by arbitrary combinations of the above-described technical features or their equivalents without departing from the above-described inventive concept. For example, technical solutions formed by substituting the above features with (but not limited to) technical features with similar functions disclosed in this application.
Claims
1. A map tiling method based on GDAL, characterized in that, Includes the following steps: S1: Obtain the vector layer and set the slicing parameters; S2, in the vector layer, determine the coordinate range of the map to be drawn, calculate the size of each tile at the current tile level according to the tile parameters, and calculate the row and column numbers of the tiles corresponding to the boundary of the map to be drawn on the world map, specifically including: In response to the determination that the projection method is latitude and longitude projection, a map is generated in Tianditu format, with the coordinate range on the world map being MinX, MaxX, MinY, and MaxY. The current tile level is Level, and the number of tiles in each row and column, TileMatrixWidth and TileMatrixHeight, are calculated using the following formulas: TileMatrixWidth = 2 Level ; TileMatrixHeight = 2 Level - 1 ; The width (TileWidth) and height (TileHeight) of each tile at the current tile level are calculated using the following formula: TileWidth = (MaxX - MinX) / (2 Level ); TileHeight = (MaxY - MinY) / (2 Level – 1 ); The coordinate range of the map to be drawn is determined as minX, maxX, minY, maxY. The row and column numbers of the tiles corresponding to the boundaries of the map to be drawn on the world map are calculated as firstrow, endrow, firstcol, endcol using the following formula: firstrow = ⌊|MaxY - maxY| / TileHeight⌋; endrow = ⌊|MaxY - minY| / TileHeight⌋; firstcol =⌊|minX - MinX| / TileWidth⌋; endcol = ⌊|maxX - MinX| / TileWidth⌋; S3, the tiles within the boundary of the map to be drawn are divided to obtain at least one object to be drawn. A row and / or a column of tiles on the edge of each object to be drawn (excluding the edge of the map to be drawn) are set as a virtual row and / or a virtual column. Each object to be drawn contains RCount*CCount tiles, where RCount represents the number of rows of tiles in each object to be drawn, and CCount represents the number of columns of tiles in each object to be drawn. In response to the existence of at least two objects to be drawn, where adjacent objects overlap and the overlapping area is the virtual row and / or virtual column corresponding to the overlapping edge of the two objects to be drawn arranged side-by-side in the adjacent direction, the row and column numbers of the tiles corresponding to the boundary of the map to be drawn on the world map are calculated based on the row and column numbers of the tiles corresponding to the boundary of the map to be drawn on the world map. Specifically, this includes: In the objects to be drawn, indexR and indexC are used as the row and column drawing numbers, respectively, initially 0. Drawing is performed cyclically from row to column. Then, the row and column numbers of the tiles corresponding to the boundary of each object on the world map are: firstcolTemp=firstcol+indexC*(CCount-2); endcolTemp=firstcol+indexC*(CCount-2)+CCount; firstrowTemp=firstrow+indexR*( RCount-2); endrowTemp=firstrow+indexR*( RCount-2)+ RCount; If endrowTemp is greater than endrow, then endrowTemp = endrow, RCount = endrow - firstrowTemp; if endcolTemp is greater than endcol, then endcolTemp = endcol, CCount = endcol - firstcolTemp. S4, calculate the drawing range based on the row and column numbers of the tiles corresponding to the boundary of each object to be drawn on the world map and the size of each tile; slice each object within the drawing range according to the slicing parameters; discard tiles in virtual rows and / or virtual columns of each object to be drawn during the slicing process to obtain slice data, specifically including: The drawing range is calculated using the following formula: TileMinX = MinX+firstcolTemp*TileWidth; TileMaxX = MinX+endcolTemp*TileWidth; TileMinY = MaxY - firstrowTemp*TileHeight; TileMaxY = MaxY - endrowTemp*TileHeight.
2. The map tiling method based on GDAL according to claim 1, characterized in that, Step S1 further includes setting the symbolization and annotation of the vector layer, and setting the visibility scale of the annotation.
3. The map tiling method based on GDAL according to claim 1, characterized in that, The slicing parameters include tile boundaries, tile storage format, projection method, slicing level, and image size and type.
4. A map drawing and tiling device based on GDAL, characterized in that, The GDAL-based map tiling method according to any one of claims 1-3 includes: The data acquisition module is configured to acquire vector layers and set slicing parameters; The boundary determination module is configured to determine the coordinate range of the map to be drawn in the vector layer, calculate the size of each tile at the current tile level according to the tile parameters, and calculate the row and column numbers of the tiles corresponding to the boundary of the map to be drawn on the world map. The partitioning module is configured to partition the tiles within the boundary of the map to be drawn to obtain at least one object to be drawn. In each object to be drawn, a row and / or a column of the tiles on the edge other than the edge of the map to be drawn is set as a virtual row and / or a virtual column. The row and column numbers of the tiles corresponding to the boundary of the map to be drawn on the world map are calculated based on the row and column numbers of the tiles corresponding to the boundary of the map to be drawn on the world map. The slicing module is configured to calculate the drawing range based on the row and column numbers of the tiles corresponding to the boundary of each object to be drawn on the world map and the size of each tile, slice each object within the drawing range according to the slicing parameters, and discard tiles in virtual rows and / or virtual columns of each object to be drawn during the slicing process to obtain slice data.
5. An electronic device, comprising: One or more processors; Storage device for storing one or more programs. When the one or more programs are executed by the one or more processors, the one or more processors implement the method as described in any one of claims 1-3.
6. A computer-readable storage medium having a computer program stored thereon, characterized in that, When the program is executed by the processor, it implements the method as described in any one of claims 1-3.
Citation Information
Patent Citations
Map drawing method based on tile map
CN111078814A
Distributed map slicing method and apparatus, storage medium, and server
WO2021136529A1
