Disclosure of Invention
In view of the above, an object of the present invention is to provide a method and an apparatus for converting topographic data, an electronic device, and a storage medium, so as to solve the problems of the prior art that the amount of topographic data files is large, which further results in high storage cost and low transmission efficiency of data.
In order to achieve the above purpose, the embodiment of the present invention adopts the following technical solutions:
in a first aspect, the present invention provides a method for transforming terrain data, the method comprising:
reading an elevation value in the grid terrain data;
converting the elevation value into a pseudo elevation value; the pseudo elevation value is a positive integer with the unit of millimeter;
converting the pseudo elevation value into numerical values of red, green and blue wave bands according to a preset corresponding relation;
and storing the raster terrain data into data in a picture format according to the numerical values of the red, green and blue wave bands.
In an alternative embodiment, the converting the elevation values into pseudo elevation values includes:
and adding the elevation value in the unit of meter with a preset value, multiplying by 1000, and rounding the multiplied value according to a set first rounding rule to obtain a pseudo elevation value which is in the unit of millimeter and is a positive integer.
In an optional embodiment, the preset corresponding relationship includes a first corresponding relationship, a second corresponding relationship, and a third corresponding relationship;
the converting the pseudo elevation value into the numerical values of red, green and blue three wave bands according to the preset corresponding relation comprises the following steps:
substituting the pseudo elevation value into the first corresponding relation for calculation, and rounding a first result obtained by calculation according to a set second rounding rule to obtain a numerical value of a red waveband;
substituting the pseudo elevation value and the numerical value of the red waveband into the second corresponding relation for calculation, and rounding a second result obtained by calculation according to a second rounding rule to obtain a numerical value of a green waveband;
and substituting the pseudo elevation value, the numerical value of the red waveband and the numerical value of the green waveband into the third corresponding relation for calculation to obtain the numerical value of the blue waveband.
In an alternative embodiment, the expression of the first corresponding relationship is: r1 ═ h/256/256, where h represents the pseudo-elevation value and R1 represents the first result;
the expression of the second correspondence relationship is: g1 ═ h- (R256 × 256))/256, where G1 represents the second result, R represents the value of the red band, and R is rounded by R1 according to a second set rounding rule;
the expression of the third correspondence relationship is: b ═ h- (R × 256) - (G × 256), where B denotes the value of the blue band, G denotes the value of the green band, and G is rounded by G1 according to a second set rounding rule.
In an alternative embodiment, the method further comprises:
and converting numerical values of red, green and blue wave bands in the data in the picture format into elevation values according to a preset conversion relation, so that the data in the picture format is inversely converted into the raster terrain data.
In a second aspect, the present invention provides a terrain data conversion apparatus, the apparatus comprising:
the data reading module is used for reading an elevation value in the grid terrain data;
the first conversion module is used for converting the elevation value into a pseudo elevation value; the pseudo elevation value is a positive integer with the unit of millimeter;
the second conversion module is used for converting the pseudo elevation value into numerical values of red, green and blue wave bands according to a preset corresponding relation;
and the data storage module is used for storing the raster terrain data into data in a picture format according to the numerical values of the red, green and blue wave bands.
In an optional embodiment, the first conversion module is configured to add the elevation value in units of meters to a preset value, then multiply by 1000, and round a value obtained by the multiplication according to a set first rounding rule to obtain a pseudo elevation value in units of millimeters and positive integers.
In an optional embodiment, the preset corresponding relationship includes a first corresponding relationship, a second corresponding relationship, and a third corresponding relationship;
the second conversion module is used for substituting the pseudo elevation value into the first corresponding relation to calculate, and rounding a first result obtained by calculation according to a set second rounding rule to obtain a numerical value of a red waveband; substituting the pseudo elevation value and the numerical value of the red waveband into the second corresponding relation for calculation, and rounding a second result obtained by calculation according to a second rounding rule to obtain a numerical value of a green waveband; and substituting the pseudo elevation value, the numerical value of the red waveband and the numerical value of the green waveband into the third corresponding relation for calculation to obtain the numerical value of the blue waveband.
In a third aspect, the invention provides an electronic device comprising a processor, a memory and a computer program stored on the memory and executable on the processor, the computer program, when executed by the processor, implementing the steps of the terrain data conversion method according to any of the preceding embodiments.
In a fourth aspect, the invention provides a computer-readable storage medium, on which a computer program is stored, which computer program, when being executed by a processor, realizes the steps of the terrain data conversion method according to any one of the preceding embodiments.
According to the terrain data conversion method, the device, the electronic equipment and the storage medium provided by the embodiment of the invention, the elevation value is converted into the pseudo elevation value with the unit of millimeter and a positive integer by reading the elevation value in the raster terrain data, the pseudo elevation value is converted into the numerical values of red, green and blue wave bands according to the preset corresponding relation, and then the raster terrain data is stored as the data in the picture format according to the numerical values of the red, green and blue wave bands. Like this, realized converting grid topographic data to the data of picture format with the precision of millimeter level, utilized the lossless compression technique that the picture format has, can carry out lossless compression to grid topographic data to effectively reduce the file size of grid topographic data, reduce the storage cost of data, promoted the transmission efficiency of data.
In order to make the aforementioned and other objects, features and advantages of the present invention comprehensible, preferred embodiments accompanied with figures are described in detail below.
Detailed Description
The technical solutions in the embodiments of the present invention will be clearly and completely described below with reference to the drawings in the embodiments of the present invention, and it is obvious that the described embodiments are only a part of the embodiments of the present invention, and not all of the embodiments. The components of embodiments of the present invention generally described and illustrated in the figures herein may be arranged and designed in a wide variety of different configurations.
Thus, the following detailed description of the embodiments of the present invention, presented in the figures, is not intended to limit the scope of the invention, as claimed, but is merely representative of selected embodiments of the invention. All other embodiments, which can be derived by a person skilled in the art from the embodiments of the present invention without making any creative effort, shall fall within the protection scope of the present invention.
It is noted that relational terms such as "first" and "second," and the like, may be used solely to distinguish one entity or action from another entity or action without necessarily requiring or implying any actual such relationship or order between such entities or actions. Also, the terms "comprises," "comprising," or any other variation thereof, are intended to cover a non-exclusive inclusion, such that a process, method, article, or apparatus that comprises a list of elements does not include only those elements but may include other elements not expressly listed or inherent to such process, method, article, or apparatus. Without further limitation, an element defined by the phrase "comprising an … …" does not exclude the presence of other identical elements in a process, method, article, or apparatus that comprises the element.
At present, raster terrain data is usually stored in a GeoTiff file format, and high-precision terrain data can be well stored, but the defect of huge file amount exists, and great problems are generated in data storage and data network transmission.
In view of this, embodiments of the present invention provide a topographic data conversion method, an apparatus, an electronic device, and a storage medium, which are capable of converting raster topographic data into data in a picture format with millimeter-scale accuracy, and performing lossless compression on the raster topographic data by using a lossless compression technique in the picture format, so as to effectively reduce the file size of the raster topographic data, reduce the storage cost of the data, and improve the transmission efficiency of the data.
Next, a detailed description will be given of a method for converting topographic data according to an embodiment of the present invention.
Fig. 1 is a schematic flow chart of a method for converting topographic data according to an embodiment of the present invention. It should be noted that the method for converting terrain data according to the embodiment of the present invention is not limited by fig. 1 and the following specific sequence, and it should be understood that, in other embodiments, the sequence of some steps in the method for converting terrain data according to the embodiment of the present invention may be interchanged according to actual needs, or some steps may be omitted or deleted. The specific process shown in FIG. 1 will be described in detail below.
And step S101, reading the elevation value in the grid terrain data.
In this embodiment, the raster terrain data may be DSM data or DEM data, which records the topography of the surveying area, from which elevation values may be read.
Step S102, converting elevation values into pseudo elevation values; the pseudo elevation values are positive integers in millimeters.
In this embodiment, the elevation value is usually in meters, and in order to realize the conversion of the grid terrain data with higher precision, after the elevation value is read, the elevation value can be converted into a pseudo elevation value which is in millimeters and is a positive integer, so that the data conversion can be realized with the precision of millimeter.
And step S103, converting the pseudo elevation value into the numerical values of red, green and blue wave bands according to a preset corresponding relation.
In this embodiment, the pseudo-elevation value may be converted into three values according to a preset corresponding relationship, and the three values are respectively recorded in three bands of RGB (red, green, and blue), so as to obtain the values of the three bands of red, green, and blue. It is understood that the values of the three red, green and blue bands include the values of the red band, the values of the green band and the values of the blue band.
And step S104, storing the raster terrain data into data in a picture format according to the numerical values of the red, green and blue wave bands.
In this embodiment, the picture formats may include PNG, Webp, and the like, and in both the PNG and Webp formats, three RGB bands may exist for recording the color information of the picture, so that after the pseudo-elevation value is converted into the values of the three red, green, and blue bands, the raster terrain data may be stored as the data in the PNG or Webp format according to the values of the three red, green, and blue bands. Because the common picture formats such as PNG, Webp and the like have lossless compression technology, the raster terrain data is stored as the data in the picture format, and lossless compression of the raster terrain data can be realized. For example, 100Mb of GeoTiff data can be compressed to be below 30Mb, the file size of raster terrain data is effectively reduced, the storage cost of the data is reduced, and the data transmission efficiency is increased.
As can be seen, in the method for converting terrain data provided in the embodiment of the present invention, by reading the elevation value in the raster terrain data, the elevation value is converted into a pseudo elevation value with a unit of millimeter and a positive integer, the pseudo elevation value is converted into values of three red, green and blue bands according to a preset corresponding relationship, and then the raster terrain data is stored as data in a picture format according to the values of the three red, green and blue bands. Like this, realized converting grid topographic data to the data of picture format with the precision of millimeter level, utilized the lossless compression technique that the picture format has, can carry out lossless compression to grid topographic data to effectively reduce the file size of grid topographic data, reduce the storage cost of data, promoted the transmission efficiency of data.
In practical application, considering that the current general earth altitude elevation value range is plus or minus 10000 meters, converting a unit into millimeters, the elevation value range is plus or minus 1000 ten thousand millimeters, and all elevation values can be represented by 2000 ten thousand positive integers.
In the picture formats such as PNG and Webp, three RGB bands exist for recording color information of the picture, and the data type of the numerical values of the RGB bands is usually uint8, and at most, positive integer numerical values in the range of 0 to 255 can be recorded, so that in the three RGB bands, the recordable numerical values of each band range from 0 to 255 for 256 numerical values, and the numerical values in the three bands are multiplied to obtain a positive integer, where the range of the positive integer is from 0 to (256 × 16777216), and about 1600 ten thousand positive integer numerical values. Namely, the three bands of RGB can express 1600 ten thousand positive integers.
Therefore, if the elevation range of plus or minus 10000 meters is adopted, 2000 ten thousand values are needed to record in millimeter unit, and the three RGB wave bands can not meet the requirement. Therefore, the embodiment eliminates part of unused elevation value ranges, so that the numerical values in the modified elevation value ranges can be expressed through three RGB wave bands.
Based on this, the step S102 may include: and adding the elevation value in the unit of meter with a preset value, multiplying by 1000, and rounding the value obtained by the multiplication according to a set first rounding rule to obtain a pseudo elevation value which is in the unit of millimeter and is a positive integer.
In this embodiment, the preset value may be determined according to the modified elevation value range.
For example, the range of high values of-6000 meters to-10000 meters, which is hardly used, can be excluded. The highest altitude of the land of the earth is 8844.43 m of Jolmoumare, and the lowest altitude of the land of the earth is 428 m of dead sea. The elevation value recording range of the elevation value is modified from-10000 meters to 10000 meters, the elevation value recording range is modified into a range from-6000 meters to 10000 meters, the elevation value recording range is converted into millimeters, the elevation value recording range is from-600 ten thousand millimeters to 1000 ten thousand millimeters, and 1600 ten thousand positive integer values are obtained.
In the present embodiment, the first rounding rule may be set according to actual requirements, for example, rounding (rounding numbers after decimal points) may be adopted. When the modified height value range is from-6000 m to 10000 m and the pseudo-height value obtained by conversion is a positive integer in mm, the preset value can be set to 6000, when the height value H is converted into the pseudo-height value H, firstly, a formula hm ═ H +6000 × 1000 is used for calculating to obtain hm, then, the formula hm is rounded up to obtain the pseudo-height value H, and the pseudo-height value H is a positive integer in mm.
It can be seen that, in the method for converting terrain data provided in the embodiment of the present invention, in order to enable three RGB bands to express all height values with a precision of millimeter level, part of the height value ranges that are not used are eliminated, and a preset value for pseudo-height value conversion is determined based on the modified height value ranges, after reading out the height values, the height values in units of meters are added to a preset value and multiplied by 1000, and the multiplied values are rounded according to a set first rounding rule, so that pseudo-height values in units of millimeters and positive integers can be obtained, thereby realizing data conversion with a precision of millimeter level.
In an embodiment, the preset corresponding relationship includes a first corresponding relationship, a second corresponding relationship, and a third corresponding relationship, and based on the first corresponding relationship, the second corresponding relationship, and the third corresponding relationship, the value of the red band, the value of the green band, and the value of the blue band may be calculated respectively. As shown in fig. 2, the step S103 may include the following sub-steps:
and a substep S1031, substituting the pseudo elevation value into the first corresponding relation for calculation, and rounding the calculated first result according to a set second rounding rule to obtain a numerical value of a red waveband.
In this embodiment, the first corresponding relationship records the corresponding relationship 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, a first result can be calculated based on the first corresponding relation, and the first result is rounded downwards, so that the numerical value of the red waveband can be obtained.
And a substep S1032 of substituting the pseudo elevation value and the value of the red wave band into a second corresponding relation for calculation, and rounding a second result obtained by calculation according to a second rounding rule to obtain the value of the green wave band.
In this embodiment, the second corresponding relationship records the corresponding relationship between the second result and the pseudo-elevation value and the red waveband value. And when the pseudo elevation value and the red waveband value are determined, calculating a second result based on the second corresponding relation, and rounding the second result downwards to obtain the green waveband value.
And a substep S1033 of substituting the pseudo elevation value, the value of the red waveband and the value of the green waveband into a third corresponding relation for calculation to obtain the value of the blue waveband.
In this embodiment, the third correspondence records the correspondence between the numerical value of the blue wavelength band and the pseudo-elevation value, the numerical value of the red wavelength band, and the numerical value of the green wavelength band. And after the pseudo elevation value, the numerical value of the red waveband and the numerical value of the green waveband are determined, calculating to obtain the numerical value of the blue waveband based on the third corresponding relation.
Therefore, the method for converting terrain data provided by the embodiment of the invention can simply and quickly convert the pseudo-elevation value into the numerical values of the red, green and blue three wave bands by presetting the three corresponding relations (namely the first corresponding relation, the second corresponding relation and the third corresponding relation), and record the color information of the picture by the numerical values of the red, green and blue three wave bands.
In one embodiment, the expression of the first correspondence relationship is: r1 ═ h/256/256, where h denotes the pseudo-elevation value and R1 denotes the first result. The expression of the second correspondence relationship is: g1 ═ h- (R256 × 256))/256, where G1 indicates the second result, R indicates the value of the red band, and R is rounded by R1 according to the second set rounding rule. The expression of the third correspondence relationship is: b ═ h- (R × 256) - (G × 256), where B denotes the value of the blue band, G denotes the value of the green band, and G is rounded by G1 according to a second set rounding rule.
According to the elevation value range defined in this embodiment, the maximum value of the elevation value H is 10000, the minimum value is-6000, the maximum value of the pseudo elevation value H is 1600 ten thousand, and the minimum value is 0, so that the value range of R is 0-244, which proves that the storage ranges of three RGB bands can satisfy all the elevation values with the accuracy of millimeter level.
Optionally, since the picture formats such as PNG and Webp can implement lossless compression, conversion and storage of all data do not destroy the elevation value information, and after the raster terrain data is converted into the picture format data and stored, the picture format data can be reversely converted into the raster terrain data in the GeoTiff format. Based on this, referring to fig. 3, the method for converting terrain data according to the embodiment of the present invention may further include:
step S301, converting the numerical values of red, green and blue wave bands in the data in the picture format into elevation values according to a preset conversion relation, thereby inversely converting the data in the picture format into raster terrain data.
For example, according to the expression B- (R × 256) - (G × 256) of the third correspondence and the conversion process of the elevation value and the pseudo elevation value, the conversion relationship between the elevation value and the values of the red, green, and blue three bands may be set as follows: h ═ ((R × 256) + (G × 256) + B) × 0.001-6000. That is, 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 of the picture format are substituted into the conversion relationship, so that the elevation value H can be obtained, and the data of the picture format is inversely converted into the raster terrain data.
Therefore, according to the terrain data conversion method provided by the embodiment of the invention, the elevation value in the grid terrain data is read out, then the elevation value is converted to obtain 3 uint8 type numerical values, and the numerical values are respectively recorded in three RGB wave bands, so that the grid terrain data is converted into data in picture formats such as PNG (portable navigation group), Webp (Webp) and the like. Because the lossless compression technology of common picture formats such as PNG or Webp is utilized, the lossless compression of the raster terrain data can be realized, so that the conversion and the storage of all data can not damage the elevation value information, and the inverse conversion of numerical values of three wave bands of RGB into corresponding elevation values is ensured to obtain the raster terrain data. Fig. 4 is a schematic diagram illustrating the interconversion between the elevation value and the RGB three-band value.
In order to perform the corresponding steps in the above embodiments and various possible manners, an implementation manner of the topographic data conversion device is given below. Referring to fig. 5, a functional block diagram of a terrain data conversion apparatus 500 according to an embodiment of the invention is shown. It should be noted that the basic principle and the technical effects of the topographic data conversion device 500 provided in the present embodiment are the same as those of the above embodiments, and for the sake of brief description, no part of the present embodiment is mentioned, and corresponding contents in the above embodiments may be referred to. The topographic 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.
The data reading module 510 is configured to read an elevation value in the grid terrain data.
It is understood that the data reading module 510 can perform the above step S101.
The first conversion module 520 is configured to convert the elevation values into pseudo elevation values; the pseudo elevation values are positive integers in millimeters.
It is understood that the first conversion module 520 may perform the step S102.
The second conversion module 530 is configured to convert the pseudo-elevation value into values of three bands, red, green and blue, according to a preset corresponding relationship.
It is understood that the second conversion module 530 can perform the step S103.
The data storage module 540 is configured to store the raster terrain data as data in a picture format according to the values of the red, green and blue bands.
It is understood that the data saving module 540 may perform the step S104.
Optionally, the first conversion module 520 may be specifically configured to add the elevation value in units of meters to a preset value, then multiply by 1000, and round the value obtained by the multiplication according to a set first rounding rule to obtain a pseudo elevation value in units of millimeters and positive integers.
Optionally, the preset corresponding relationship includes a first corresponding relationship, a second corresponding relationship and a third corresponding relationship; the second conversion module 530 may be specifically configured to substitute the pseudo elevation value into the first corresponding relationship to perform calculation, and perform rounding on a first result obtained by the calculation according to a set second rounding rule to obtain a value of a red band; substituting the pseudo elevation value and the numerical value of the red waveband into a second corresponding relation for calculation, and rounding a second result obtained by calculation according to a second rounding rule to obtain a numerical value of the green waveband; and substituting the pseudo elevation value, the numerical value of the red waveband and the numerical value of the green waveband into a third corresponding relation for calculation to obtain the numerical value of the blue waveband.
It is to be understood that the second conversion module 530 can perform the sub-steps S1031 to S1033 described above.
Optionally, the expression of the first corresponding relationship is: r1 ═ h/256/256, where h denotes the pseudo-elevation value and R1 denotes the first result. The expression of the second correspondence relationship is: g1 ═ h- (R256 × 256))/256, where G1 indicates the second result, R indicates the value of the red band, and R is rounded by R1 according to the second set rounding rule. The expression of the third correspondence relationship is: b ═ h- (R × 256) - (G × 256), where B denotes the value of the blue band, G denotes the value of the green band, and G is rounded by G1 according to a second set rounding rule.
Optionally, referring to fig. 6, the terrain data conversion apparatus 500 according to the embodiment of the present invention may further include a third conversion module 550, where the third conversion module 550 may be configured to convert the values of the red, green, and blue bands in the data in the picture format into altitude values according to a preset conversion relationship, so as to inversely convert the data in the picture format into the raster terrain data.
It is understood that the third converting module 550 can perform the step S301.
Therefore, in the topographic data conversion device provided by the embodiment of the invention, the elevation value in the grid topographic data is read through the data reading module, and the elevation value is converted into the pseudo elevation value through the first conversion module; the unit of the pseudo elevation value is a positive integer of millimeter, the second conversion module converts the pseudo elevation value into numerical values of red, green and blue wave bands according to a preset corresponding relation, and the data storage module stores the raster terrain data into data in a picture format according to the numerical values of the red, green and blue wave bands. Like this, realized converting grid topographic data to the data of picture format with the precision of millimeter level, utilized the lossless compression technique that the picture format has, can carry out lossless compression to grid topographic data to effectively reduce the file size of grid topographic data, reduce the storage cost of data, promoted the transmission efficiency of data.
Fig. 7 is a block diagram of an electronic device 700 according to an embodiment of the invention. Electronic device 700 includes memory 710, processor 720, and communication module 730. The elements of the memory 710, processor 720 and communication module 730 are electrically connected to each other, directly or indirectly, to enable the transfer or interaction of data. For example, the components may be electrically connected to each other via one or more communication buses or signal lines.
The memory 710 is used for storing programs or data. The Memory 710 may be, but is not limited to, a Random Access Memory (RAM), a Read Only Memory (ROM), a Programmable Read-Only Memory (PROM), an Erasable Read-Only Memory (EPROM), an electrically Erasable Read-Only Memory (EEPROM), and the like.
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 method disclosed in the above embodiments may be implemented.
The communication module 730 is used for establishing a communication connection between the electronic device 700 and another communication terminal through a network, and for transceiving data through the network.
It should be understood that the configuration shown in fig. 7 is merely a schematic diagram of the configuration of the electronic device 700, and that the electronic device 700 may include more or fewer components than shown in fig. 7, or have a different configuration than shown in fig. 7. The components shown in fig. 7 may be implemented in hardware, software, or a combination thereof.
An embodiment of the present invention further provides a computer-readable storage medium, on which a computer program is stored, and the computer program, when executed by the processor 720, implements the method for converting terrain data disclosed in the above embodiments.
In the embodiments provided in the present application, it should be understood that the disclosed apparatus and method can be implemented in other ways. The apparatus embodiments described above are merely illustrative, and for example, the flowchart and block diagrams in the figures illustrate the architecture, functionality, and operation of possible implementations of apparatus, methods and computer program products according to various embodiments of the present invention. In this regard, each block in the flowchart or block diagrams may represent a module, segment, or portion of code, which comprises one or more executable instructions for implementing the specified logical function(s). 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 shown 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 will also be noted that each block of the block diagrams and/or flowchart illustration, and combinations of blocks in the block diagrams and/or flowchart illustration, can be implemented by special purpose hardware-based systems which perform the specified functions or acts, or combinations of special purpose hardware and computer instructions.
In addition, the functional modules in the embodiments of the present invention may be integrated together to form an independent part, or each module may exist separately, or two or more modules may be integrated to form an independent part.
The functions, if implemented in the form of software functional modules and sold or used as a stand-alone product, may be stored in a computer readable storage medium. Based on such understanding, the technical solution of the present invention may be embodied in the form of a software product, which is stored in a storage medium and includes instructions for causing a computer device (which may be a personal computer, a server, or a network device) to execute all or part of the steps of the method according to the embodiments of the present invention. And the aforementioned storage medium includes: a U-disk, a removable hard disk, a Read-Only Memory (ROM), a Random Access Memory (RAM), a magnetic disk or an optical disk, and other various media capable of storing program codes.
The above description is only a preferred embodiment of the present invention and is not intended to limit the present invention, and various modifications and changes may be made by those skilled in the art. Any modification, equivalent replacement, or improvement made within the spirit and principle of the present invention should be included in the protection scope of the present invention.