[0045] The technical solutions in the embodiments of the present invention will be clearly and completely described below with reference to 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. The components of the embodiments of the invention generally described and illustrated in the drawings herein may be arranged and designed in a variety of different configurations.
[0046] Thus, the following detailed description of the embodiments of the invention provided in the accompanying drawings are not intended to limit the scope of the invention as claimed, but are merely representative of selected embodiments of the invention. Based on the embodiments of the present invention, all other embodiments obtained by those skilled in the art without creative work fall within the protection scope of the present invention.
[0047]It should be noted that relational terms such as the terms "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 relationship between these entities or operations. any such actual relationship or sequence exists. Moreover, the terms "comprising", "comprising" or any other variation thereof are intended to encompass non-exclusive inclusion such that a process, method, article or device comprising a list of elements includes not only those elements, but also includes not explicitly listed or other elements inherent to such a process, method, article or apparatus. Without further limitation, an element qualified by the phrase "comprising a..." does not preclude the presence of additional identical elements in a process, method, article or apparatus that includes the element.
[0048] At present, raster terrain data is usually stored in the GeoTiff file format. Although it can store high-precision terrain data well, it has the disadvantage of a very large file size, which will cause very large amounts of data storage and data network transmission. problem.
[0049] In view of this, the embodiments of the present invention propose a terrain data conversion method, device, electronic device, and storage medium, which can convert raster terrain data into data in a picture format with millimeter-level precision, and utilize the lossless compression technology possessed by the picture format. , compresses the raster terrain data losslessly, thereby effectively reducing the file size of the raster terrain data, reducing the data storage cost, and improving the data transmission efficiency.
[0050] Hereinafter, the terrain data conversion method provided by the embodiment of the present invention will be described in detail.
[0051] Please refer to figure 1 , which is a schematic flowchart of a terrain data conversion method provided by an embodiment of the present invention. It should be noted that the terrain data conversion method of the embodiment of the present invention does not figure 1 And the following specific order is limited, it should be understood that in other embodiments, the order of some steps in the terrain data conversion method of the embodiment of the present invention may be exchanged with each other according to actual needs, or some of the steps may also be omitted or deleted. The following will figure 1 The specific process shown is described in detail.
[0052] Step S101, read the elevation value in the grid terrain data.
[0053] In this embodiment, the grid terrain data may be DSM data or DEM data, which records the terrain fluctuations of the mapping area, and the elevation value can be read from the DSM data or DEM data.
[0054] Step S102, converting the elevation value into a pseudo-elevation value; the pseudo-elevation value is a positive integer whose unit is millimeter.
[0055] In this embodiment, the elevation value is usually in meters. In order to realize the conversion of raster terrain data with higher precision, after reading the elevation value, it can be converted into a pseudo-integer whose unit is millimeters. Elevation values for easy data conversion with millimeter accuracy.
[0056] In step S103, the pseudo-elevation value is converted into values of three bands of red, green and blue according to a preset corresponding relationship.
[0057] In this embodiment, according to the preset correspondence, the pseudo-elevation value can be converted into three numerical values, which are respectively recorded in the three bands of RGB (red, green and blue), thereby obtaining the values of the three bands of red, green and blue. It can be understood that the values of the three bands of red, green and blue include the value of the red band, the value of the green band and the value of the blue band.
[0058] Step S104: Save the raster terrain data as data in a picture format according to the values of the three bands of red, green and blue.
[0059] In this embodiment, the picture format may include PNG, Webp and other formats. In both PNG and Webp formats, there are three RGB bands for recording the color information of the picture, so the pseudo-elevation value is converted into three red, green and blue. After setting the value of the band, the raster terrain data can be saved in PNG or Webp format according to the values of the three bands of red, green and blue. Since common image formats such as PNG and Webp have lossless compression technology, saving raster terrain data as data in image format can realize lossless compression of raster terrain data. For example, 100Mb GeoTiff data can be compressed to less than 30Mb, which effectively reduces the file size of raster terrain data, reduces data storage costs and increases data transmission efficiency.
[0060] It can be seen that the terrain data conversion method provided by the embodiment of the present invention converts the elevation value into a pseudo-elevation value whose unit is millimeter and is a positive integer by reading the elevation value in the grid terrain data, and converts the pseudo-elevation value according to the preset value. The corresponding relationship is converted into the values of the three bands of red, green and blue, and then the raster terrain data is saved as data in the image format according to the values of the three bands of red, green and blue. In this way, the raster terrain data can be converted into image format data with millimeter-level precision, and the raster terrain data can be compressed losslessly by using the lossless compression technology of the image format, thereby effectively reducing the file size of the raster terrain data. , reduce data storage costs and improve data transmission efficiency.
[0061] In practical applications, considering that the current common earth elevation value range is plus or minus 10,000 meters, and the unit is converted into millimeters, the elevation value range is plus or minus 10 million millimeters, and 20 million positive integers are needed to represent all elevations value.
[0062] In image formats such as PNG and Webp, there are three RGB bands used to record the color information of the image, and the data type of the value of the RGB band is usually uint8, which can record positive integer values in the range of 0 to 255 at most, so in the In the three bands of RGB, the range of values that can be recorded in each band is a positive integer from 0 to 255, with a total of 256 values. Multiply the values in the three bands to obtain a positive integer. The value range of the positive integer is It is 0~(256*256*256=16777216), about 16 million positive integer values. That is, the three bands of RGB can express 16 million positive integers.
[0063] Therefore, if the elevation value range of plus or minus 10,000 meters is taken, in millimeters, 20 million values are needed to record, and the three RGB bands cannot meet the requirements. Based on this, this embodiment removes some elevation value ranges that will not be used, so that all values in the modified elevation value range can be expressed by three RGB bands.
[0064] Based on this, the above step S102 may include: adding the elevation value in meters and a preset value and multiplying by 1000, and rounding the multiplied value according to the set first rounding rule to obtain the unit is a positive integer pseudo-elevation value in millimeters.
[0065] In this embodiment, the preset value may be determined according to the modified range of elevation values.
[0066] For example, the range of elevation values from -6000m to -10000m, which is rarely used, can be culled. The highest land elevation on Earth is Mount Everest 8844.43 meters, and the lowest land elevation is the Dead Sea - 428 meters. Then change the record range of the altitude value from -10000m to 10000m, modify it to the range of -6000m to 10000m, and convert it into millimeters from -6 million millimeters to 10 million millimeters, a total of 16 million positive integer values, through the aforementioned The analysis shows that the three RGB bands can express 16 million positive integers, so the modified range of elevation values meets the requirements of using the three RGB bands to record.
[0067] In this embodiment, the first rounding rule can be set according to actual needs, for example, rounding (rounding off the digits after the decimal point) can be used to round off. When the modified elevation value ranges from -6000m to 10000m, to make the converted pseudo-elevation value a positive integer with the unit of millimeter, you can set the preset value to 6000, and then convert the elevation value H into a pseudo-elevation When the elevation value is h, first use the formula hm=(H+6000)*1000 to calculate the hm, and then round off the hm to obtain the pseudo-elevation value h. At this time, the pseudo-elevation value h is a positive integer in millimeters.
[0068] It can be seen that, in the terrain data conversion method provided by the embodiment of the present invention, in order to enable the three RGB bands to express all elevation values with an accuracy of millimeters, some elevation value ranges that will not be used are removed, and based on the modified elevation value range Determine the preset value for pseudo-elevation value conversion. After reading the elevation value, add the elevation value in meters to a preset value and multiply by 1000, and the multiplied value is set according to the setting. By rounding the first rounding rule of , the pseudo-elevation value with a unit of millimeter and a positive integer can be obtained, so as to realize data conversion with millimeter-level precision.
[0069] In one embodiment, the preset correspondence includes a first correspondence, a second correspondence, and a third correspondence, and based on the first correspondence, the second correspondence and the third correspondence, the corresponding relationships can be calculated respectively. Values in the red band, values in the green band, and values in the blue band. like figure 2 As shown, the above step S103 may include the following sub-steps:
[0070] Sub-step S1031, substitute the pseudo-elevation value into the first corresponding relationship for calculation, and round the first result obtained by the calculation according to the set second rounding rule to obtain the value of the red band.
[0071] In this embodiment, the first correspondence records the correspondence between the first result and the pseudo-elevation value, and the second rounding rule may also be set according to actual needs, for example, rounding down may be adopted. After the pseudo-elevation value is determined, the first result can be calculated based on the first correspondence, and the value of the red band can be obtained by rounding down the first result.
[0072] Sub-step S1032: Substitute the pseudo-elevation value and the value of the red band into the second corresponding relationship for calculation, and round the calculated second result according to the second rounding rule to obtain the value of the green band.
[0073] In this embodiment, the second correspondence records the correspondence between the second result and the pseudo-elevation value and the value of the red band. After the pseudo-elevation value and the value of the red band are determined, a second result can be calculated based on the second correspondence, and the second result can be rounded down to obtain the value of the green band.
[0074] Sub-step S1033: Substitute the pseudo-elevation value, the value of the red band and the value of the green band into the third corresponding relationship for calculation to obtain the value of the blue band.
[0075] In this embodiment, the third correspondence records the correspondence between the value of the blue band and the pseudo-elevation value, the value of the red band, and the value of the green band. After the pseudo-elevation value, the value of the red band, and the value of the green band are determined, based on the third correspondence, the value of the blue band can be calculated.
[0076] It can be seen that the terrain data conversion method provided by the embodiment of the present invention can simply and quickly convert the pseudo-elevation value to red by presetting three correspondences (ie, the first correspondence, the second correspondence and the third correspondence). The values of the three bands of green and blue are used to record the color information of the picture through the values of the three bands of red, green and blue.
[0077] In an embodiment, the expression of the first correspondence is: R1=h/256/256, where h represents the pseudo-elevation value, and R1 represents the first result. The expression of the second correspondence is: G1=(h-(R*256*256))/256, where G1 represents the second result, R represents the value of the red band, and R is set by R1 according to the second The rounding rule is rounded to get. The expression of the third correspondence is: B=h-(R*256*256)-(G*256), where B represents the value of the blue band, G represents the value of the green band, and G is set by G1 according to the setting According to the specified second rounding rule, it is obtained by rounding up.
[0078]According to the range of elevation values defined in this embodiment, the maximum value of the elevation value H is 10000 and the minimum value is -6000, then the maximum value of the pseudo-elevation value h is 16 million and the minimum value is 0, so the value range of R is From 0 to 244, it can be proved that the storage range of the three RGB bands can satisfy all elevation values with an accuracy of millimeters.
[0079] Optionally, since image formats such as PNG and Webp can achieve lossless compression, the conversion and storage of all data will not destroy the elevation value information. Inversely convert data in image format to raster terrain data in GeoTiff format. Based on this, please refer to image 3 , the terrain data conversion method provided by the embodiment of the present invention may further include:
[0080] Step S301 , according to a preset conversion relationship, convert the values of the three bands of red, green and blue in the data in the picture format into elevation values, so as to inversely convert the data in the picture format into raster terrain data.
[0081] For example, according to the expression B=h-(R*256*256)-(G*256) of the aforementioned third correspondence and the conversion process of the elevation value and the pseudo-elevation value, the elevation value and the three bands of red, green and blue can be set The conversion relationship of the value is: H=((R*256*256)+(G*256)+B)*0.001-6000. That is to say, the value R of the red band, the value G of the green band, and the value B of the blue band in the data in the picture format are substituted into the conversion relationship, and the elevation value H can be obtained, realizing the inverse of the data in the picture format. Convert to raster terrain data.
[0082] It can be seen that in the terrain data conversion method provided by the embodiment of the present invention, by reading out the elevation value in the grid terrain data, and then converting the elevation value, three values of the uint8 type are obtained, which are respectively recorded in the three bands of RGB , to convert raster terrain data into PNG, Webp and other image formats. Lossless compression of raster terrain data can be achieved by using the lossless compression technology of general image formats such as PNG or Webp, so the conversion and preservation of all data will not destroy the elevation value information, thus ensuring the use of the numerical inverse of the three RGB bands. Convert to the corresponding elevation value to get raster terrain data. like Figure 4 As shown, it is a schematic diagram of the mutual conversion between the elevation value and the values of the three RGB bands.
[0083] In order to execute the corresponding steps in the above embodiments and various possible manners, an implementation manner of a terrain data conversion apparatus is given below. see Figure 5 , is a functional module diagram of the terrain data conversion apparatus 500 provided by the embodiment of the present invention. It should be noted that the basic principles and technical effects of the terrain data conversion device 500 provided in this embodiment are the same as those in the above-mentioned embodiments. For the sake of brief description, for the parts not mentioned in this embodiment, reference may be made to the above-mentioned implementation. corresponding content in the example. The terrain data conversion device 500 includes a data reading module 510 , a first conversion module 520 , a second conversion module 530 and a data storage module 540 .
[0084] The data reading module 510 is used for reading the elevation value in the raster terrain data.
[0085] It can be understood that the data reading module 510 can perform the above step S101.
[0086] The first conversion module 520 is configured to convert the elevation value into a pseudo-elevation value; the pseudo-elevation value is a positive integer whose unit is millimeter.
[0087] It can be understood that the first conversion module 520 can perform the above step S102.
[0088] The second conversion module 530 is configured to convert the pseudo-elevation value into the value of three bands of red, green and blue according to a preset corresponding relationship.
[0089] It can be understood that the second conversion module 530 can perform the above-mentioned step S103.
[0090] The data saving module 540 is configured to save the raster terrain data as data in a picture format according to the values of the three bands of red, green and blue.
[0091] It can be understood that the data saving module 540 can execute the above-mentioned step S104.
[0092] Optionally, the first conversion module 520 can be specifically configured to add the elevation value in meters and a preset value, and then multiply by 1000, and take the multiplied value according to the set first rounding rule. integer to get a pseudo-elevation value in millimeters and a positive integer.
[0093] Optionally, the preset corresponding relationship includes a first corresponding relationship, a second corresponding relationship and a third corresponding relationship; the second conversion module 530 can be specifically configured to substitute the pseudo-elevation value into the first corresponding relationship for calculation, and calculate the calculated value. The first result is rounded according to the set second rounding rule to obtain the value of the red band; the pseudo-elevation value and the value of the red band are substituted into the second corresponding relationship for calculation, and the calculated second result is calculated according to the second The rounding rule is used to round up to obtain the value of the green band; the pseudo-elevation value, the value of the red band and the value of the green band are substituted into the third corresponding relationship for calculation, and the value of the blue band is obtained.
[0094] It can be understood that the second conversion module 530 may execute the above sub-steps S1031 to S1033.
[0095] Optionally, the expression of the first correspondence is: R1=h/256/256, where h represents the pseudo-elevation value, and R1 represents the first result. The expression of the second correspondence is: G1=(h-(R*256*256))/256, where G1 represents the second result, R represents the value of the red band, and R is determined by R1 according to the set The two rounding rules are rounded to get. The expression of the third correspondence is: B=h-(R*256*256)-(G*256), wherein B represents the value of the blue band, G represents the value of the green band, and G is determined by G1 according to The set second rounding rule is rounded to obtain.
[0096] Optionally, see Image 6 , the terrain data conversion device 500 provided by the embodiment of the present invention may further include a third conversion module 550, and the third conversion module 550 may be configured to convert the red, green, and blue three bands in the data of the picture format according to a preset conversion relationship. The values of , are converted to elevation values, thereby inversely converting data in image format to raster terrain data.
[0097] It can be understood that the third conversion module 550 can perform the above step S301.
[0098] It can be seen that the terrain data conversion device provided by the embodiment of the present invention reads the elevation value in the grid terrain data through the data reading module, and the first conversion module converts the elevation value into a pseudo-elevation value; the pseudo-elevation value is in millimeters A positive integer, the second conversion module converts the pseudo-elevation value into the values of the three bands of red, green and blue according to the preset corresponding relationship, and the data saving module saves the raster terrain data as a picture format according to the values of the three bands of red, green and blue. data. In this way, the raster terrain data can be converted into image format data with millimeter-level precision, and the raster terrain data can be compressed losslessly by using the lossless compression technology of the image format, thereby effectively reducing the file size of the raster terrain data. , reduce data storage costs and improve data transmission efficiency.
[0099] Please refer to Figure 7 , is a schematic block diagram of an electronic device 700 provided in an embodiment of the present invention. The electronic device 700 includes a memory 710 , a processor 720 and a communication module 730 . The elements of the memory 710 , the processor 720 and the communication module 730 are directly or indirectly electrically connected to each other to realize data transmission or interaction. For example, these elements may be electrically connected to each other through one or more communication buses or signal lines.
[0100] The memory 710 is used for storing programs or data. The memory 710 can be, but is not limited to, random access memory (Random Access Memory, RAM), read only memory (Read Only Memory, ROM), programmable read only memory (Programmable Read-Only Memory, PROM), erasable Read-only memory (ErasableProgrammable Read-Only Memory, EPROM), Electrically Erasable Programmable Read-Only Memory (Electric ErasableProgrammable Read-Only Memory, EEPROM), etc.
[0101] The processor 720 is used to read/write data or programs stored in the memory 710, and perform corresponding functions. For example, when the computer program stored in the memory 710 is executed by the processor 720, the terrain data conversion methods disclosed in the above embodiments can be implemented.
[0102] The communication module 730 is used to establish a communication connection between the electronic device 700 and other communication terminals through the network, and to send and receive data through the network.
[0103] It should be understood that, Figure 7 The shown structure is only a schematic diagram of the structure of the electronic device 700, and the electronic device 700 may further include Figure 7 more or fewer components shown in, or have the same Figure 7 different configurations shown. Figure 7 The components shown in can be implemented in hardware, software, or a combination thereof.
[0104] Embodiments of the present invention further provide a computer-readable storage medium on which a computer program is stored, and when the computer program is executed by the processor 720, implements the terrain data conversion methods disclosed in the foregoing embodiments.
[0105] In the several embodiments provided in this application, it should be understood that the disclosed apparatus and method may also be implemented in other manners. The apparatus embodiments described above are merely illustrative, for example, the flowcharts and block diagrams in the accompanying drawings illustrate the architecture, functionality and possible implementations of apparatuses, methods and computer program products according to various embodiments of the present invention. operate. In this regard, each block in the flowchart or block diagrams may represent a module, segment, or portion of code that contains one or more functions for implementing the specified logical function(s) executable instructions. It should also be noted that, in some alternative implementations, the functions noted in the block may occur out of the order noted in the figures. For example, two blocks in succession may, in fact, be executed substantially concurrently, or the blocks may sometimes be executed in the reverse order, depending upon the functionality involved. It is also noted that each block of the block diagrams and/or flowchart illustrations, and combinations of blocks in the block diagrams and/or flowchart illustrations, can be implemented in dedicated hardware-based systems that perform the specified functions or actions , or can be implemented in a combination of dedicated hardware and computer instructions.
[0106] In addition, each functional module in each embodiment of the present invention may be integrated together to form an independent part, or each module may exist alone, or two or more modules may be integrated to form an independent part.
[0107] If the functions are implemented in the form of software function modules and sold or used as independent products, they may be stored in a computer-readable storage medium. Based on such understanding, the technical solution of the present invention can be embodied in the form of a software product in essence, or the part that contributes to the prior art or the part of the technical solution. The computer software product is stored in a storage medium, including Several instructions are used to cause a computer device (which may be a personal computer, a server, or a network device, etc.) to execute all or part of the steps of the methods described in the various embodiments of the present invention. The aforementioned storage medium includes: U disk, removable hard disk, Read-Only Memory (ROM, Read-Only Memory), Random Access Memory (RAM, Random Access Memory), magnetic disk or optical disk and other media that can store program codes .
[0108] The above descriptions are only preferred embodiments of the present invention, and are not intended to limit the present invention. For those skilled in the art, the present invention may have various modifications and changes. Any modification, equivalent replacement, improvement, etc. made within the spirit and principle of the present invention shall be included within the protection scope of the present invention.