A storage and reading method for classified raster data
By storing the partitioned raster data in blocks and classification information, and recording cell distribution with distributed flag bit data, the problem of excessive storage space of large-scale partitioned raster data is solved, and the effect of saving storage costs and improving transmission efficiency is achieved.
Patent Information
- Application Number
- CN202210617689.7
- Authority / Receiving Office
- CN · China
- Patent Type
- Patents(China)
- Current Assignee / Owner
- Filing Date
- 2022-06-01
- Publication Date
- 2025-03-11
- Estimated Expiration
- 2042-06-01
AI Technical Summary
When storing and processing large-scale subtyped raster data, the prior art faces problems such as excessive storage space usage, high equipment costs and low network transmission efficiency.
By blocking the original classification raster data with the unit statistical area as the minimum granularity, multiple statistical blocks are formed, and each statistical block is classified and stored row by row, column by row, and classification information is used to record the distribution of cells, reducing storage space requirements.
It effectively reduces the amount of data storage, saves storage equipment costs, improves network transmission efficiency, and ensures data accuracy and flexible accuracy control.
Smart Images

Figure CN115049873B_ABST
Abstract
Description
Technical Field
[0001] The present invention relates to the field of raster data processing, and in particular to a storage and reading method for classified raster data. Background Art
[0002] The raster data model divides the geographic space into a pixel array consisting of several rows and columns. The smallest unit is called a pixel. The position of each pixel is determined by the row and column number, and the value of the pixel is used to record a certain type of geographic attribute value at this position. Raster data with integer pixel values are usually used to store various so-called discrete data or classified data. This data set describes a class of objects whose geographic attribute values at the location of the raster pixel are integers. For example, in the land use type raster data, each pixel stores an integer, which represents the land use category of the geographic space corresponding to the pixel, such as integer 1 represents cultivated land, integer 2 represents forest land, integer 3 represents grassland, and so on.
[0003] Assume that a certain type of raster data is composed of K rows and L columns of raster pixels, and the value corresponding to each raster pixel is a one-byte unsigned integer value. For example, each raster pixel of the above land use type raster data stores the integer value of the land use classification. According to the common practice of the current raster data model, each raster pixel is stored with 1 byte, which requires K×L bytes. When the coverage area of the type of raster data is large and the accuracy is high, the number of rows and columns of the raster is large, K×L, and the required storage space is very large, which is a great challenge to the system's storage device cost and network transmission efficiency. Summary of the invention
[0004] The technical problem to be solved by the present invention is to provide a storage and reading method for classified raster data, which can effectively reduce the amount of data storage, save storage device costs, and improve network transmission efficiency.
[0005] The technical solution of the present invention to solve the above technical problems is as follows:
[0006] A storage method for classified raster data stores original classified raster data Data consisting of K rows and L columns of m types of pixels, including the following steps:
[0007] S1. Re-dividing the rows and columns of the original raster data Data composed of K rows and L columns of pixels with the unit statistical area as the minimum granularity to obtain a rows and b columns of statistical blocks;
[0008] When K / s1 is an integer, a=K / s1;
[0009] When K / s1 is not an integer, a=[K / s1]+1;
[0010] When L / s2 is an integer, b = L / s2;
[0011] When L / s2 is not an integer, b=[L / s2]+1;
[0012] Among them, the unit statistical area is a grid data matrix with s1 rows and s2 columns, and s1 and s2 are constants;
[0013] S2. For a row and b column statistical blocks, count the classification information of each statistical block row by row and column by column, and store the classification information in the data file Xdata, wherein the classification information includes the total number of pixels of each classification in the statistical block, and the distribution flag data of all pixels whose total number of each classification is greater than 0 in the statistical block; record the storage space size of the statistical block classification information, and store it in the data file Xdata;
[0014] S3. Storing metadata information of the original classified raster data Data, and storing the metadata information in a data file meta.
[0015] Furthermore, the distribution flag data determines the distribution of a certain type of pixel in the statistical block with the unit distribution area as the minimum granularity. The distribution flag data of each category occupies w1*w2 bits of storage space, corresponding to the w1*w2 sub-areas divided in the statistical block. If there are pixels of this category in a sub-area, the distribution flag value corresponding to the sub-area is set to 1, otherwise the distribution flag value corresponding to the sub-area is set to 0, wherein w1=s1 / t1, w2=s2 / t2, t1 is the row of the unit distribution area, and t2 is the column of the unit distribution area.
[0016] Furthermore, if the statistical block contains s1*s2 pixels, the unit distribution areas t1 and t2 take values greater than 1 and satisfy s1 / t1 and s2 / t2 are integers; if the statistical block contains less than s1*s2 pixels, the unit distribution areas t1 and t2 take values of 1.
[0017] Furthermore, the total number of pixels of each classification in the statistical block is stored in the following steps: the bit size required for storing the classification information of the current statistical block is recorded with the value Ts, and the selected storage data type is determined according to the number of pixels in the unit statistical area, wherein the Ts value is initially 0;
[0018] When s1*s2<256, a 1-byte unsigned integer type is used to store the total number of pixels in each classification, which requires a total of m bytes. When writing to the data file Xdata, m 1-byte unsigned integers are written continuously. At this time, the Ts value increases by 8*m;
[0019] When 256<=s1*s2<65536, a 2-byte unsigned integer type is used to store the total number of pixels in each classification, requiring a total of 2m bytes. When writing to the data file Xdata, m 2-byte unsigned integers are written continuously, and the Ts value increases by 16*m at this time;
[0020] When s1*s2>=65536, a 4-byte unsigned integer type is used to store the total number of pixels in each category, requiring a total of 4m bytes. When writing to the data file Xdata, m 4-byte unsigned integers are written continuously. At this time, the Ts value increases by 32*m.
[0021] Furthermore, the statistical block contains s1*s2 pixels, and the distribution flag data storage process of a certain type of pixels whose total number of classifications is greater than 0 is:
[0022] If the value of a certain type of pixel is equal to 0, it means that there is no pixel of this classification in the statistical block, then skip this value and continue to judge the next value;
[0023] If the value of a certain type of pixel is greater than 0, the distribution flag data of all pixels of this classification in the statistical block with the unit distribution area as the minimum granularity is stored;
[0024] If there are q (1<=q<=m) classified distribution flag data that need to be stored in the statistical block, a total of w1*w2*q bits of storage space are required. These w1*w2*q bits of distribution flag data are written to the data file Xdata, and the value of Ts increases by w1*w2*q.
[0025] Furthermore, if the statistical block contains less than s1*s2 pixels, if there are y pixels, the distribution flag data storage process of a certain type of pixels whose total number of each classification is greater than 0 is:
[0026] If there are q categories of distribution flag data that need to be stored in the statistical block, a total of q*y bits of storage space are required; the q*y bits of distribution flag data are written into the data file Xdata, and the value of Ts increases by q*y, where 1<=q<=m.
[0027] Furthermore, the total storage space size value required to store the classification information of all statistical blocks in each row is recorded and written into the data file rowSize.
[0028] Furthermore, the metadata information includes the number of rows K and columns L of the original classified raster data Data, the total number of pixel categories m, the pixel values corresponding to each category of pixels, the values of unit statistical areas s1 and s2, and the values of unit distribution areas t1 and t2.
[0029] A method for reading classified raster data, reading raster data stored according to a raster data storage method, if the raster unit data D(r, c) of the pixel value of the rth row and cth column of the original classified raster data Data is to be read, wherein 1<=r<=K, 1<=c<=L, the method comprises the following steps:
[0030] S1. Read the data file meta, obtain the metadata information of the original classified raster data Data, and calculate that there are a rows and b columns of statistical blocks in the data file Xdata;
[0031] S2. Calculate the statistical block number where the pixel in the rth row and cth column belongs. If the number of rows and columns of the statistical block to which it belongs is v and z, then:
[0032] When r / s1 is an integer, v=r / s1;
[0033] When r / s1 is not an integer, v=[r / s1]+1;
[0034] When c / s2 is an integer, z = c / s2;
[0035] When c / s2 is not an integer, z=[c / s2]+1;
[0036] S3. Read the data file rowSize to obtain the total storage space size value of the classification information of all statistical blocks in each column of each row;
[0037] When v=1, the classification information of the first column of the first row of the statistics block starts at bit 0 of the data file Xdata, and the reading point position offset=0;
[0038] When v>1, the classification information of the first column of the vth row of the statistics block starts at e in the data file Xdata. (v-1) bit position, at this time the reading point position offset = e (v-1) ;
[0039] The data file Xdata] is read from the read point position offset, and the classification information of the statistical block is parsed.
[0040] Furthermore, S3 also includes:
[0041] S31. Read the total number of pixels of each category in the classification information:
[0042] When s1*s2<256, read 1-byte unsigned integer data one by one, a total of m times, and get integer values n1, n2, ..., n m ;
[0043] When 256<=s1*s2<65536, read 2-byte unsigned integer data one by one, a total of m times, and get integer values n1, n2, ..., n m ;
[0044] When s1*s2>=65536, read 4-byte unsigned integer data one by one, a total of m times, and get integer values n1, n2, ..., n m ;
[0045] S32. Read the distribution flag data of each category in the classification information:
[0046] S321. For the obtained m integer values n1, n2, ..., n m , judge whether it is greater than 0 one by one;
[0047] If i If it is equal to 0, it means that there is no pixel of this classification in the statistical block, then skip this value and continue to judge the next value; if n i If it is greater than 0, the distribution flag data of the category i in the statistical block is read, where the value range of category i is 1<=i<=m;
[0048] S322. Determine m integer values n1, n2, ..., n m Is the sum F equal to s1*s2?
[0049] If F = s1*s2, then the statistical block contains s1*s2 pixels, and the distribution flag data of each classification occupies w1*w2 bits. Continue to read w1*w2 bits of data in the data file Xdata, that is, w1*w2 sub-areas, and obtain a bit array B[][] with w1 rows and w2 columns;
[0050] If the pixel in the cth column is in the statistical block, calculate the sub-region row number gr and column number hc of the pixel in the statistical block; accumulate all sub-regions with B[][]=1 to obtain the sub-regions and their number st of pixel distribution of category i; calculate the probability value P of each pixel in the sub-region belonging to each category bi , take the category j with the maximum probability value as the category of each pixel in the sub-region, and return the pixel value pj corresponding to the pixel category j in the rth row and cth column requested to be read, and the reading is completed, where P bi =n i / (st*t1*t2)*100%,1<=j<=m,n i is the total number of pixels of category i; otherwise, continue parsing and processing the classification information of the statistical block in the next column;
[0051] If F < s1 * s2, the number of pixels contained in the statistical block is less than s1 * s2. The distribution flag bit data of each classification is calculated to occupy rr * cc bit positions. Then, continue to read rr * cc bit positions of data from the data file Xdata to obtain rr * cc sub-regions, that is, obtain a two-dimensional array B[][] of rr rows and cc columns of bit positions. If the pixel in the c-th column is in this statistical block, calculate the row number gg and column number hh of the requested pixel in this statistical block, and determine whether the requested pixel in this statistical block is a pixel of classification i. If B[gg][hh] = 1, the requested pixel belongs to classification i, and return the value p of the pixel i , the reading ends, where rr = (K - [K / s1] * s1), cc = (L - [L / s2] * s2), 1 <= gg <= rr; 1 <= hh <= cc; otherwise, continue to parse and process the classification information of the statistical block in the next column.
[0052] Compared with the prior art, the present invention has the following technical effects:
[0053] Taking the unit statistical area as the smallest granularity, the original classified grid data Data is divided into blocks to obtain a series of statistical blocks, and the classification information of each statistical block is stored in order; the classification information includes the total number of pixels of each classification in the statistical block and the distribution flag bit data of all pixels with the total number of each classification greater than 0 in this statistical block; to improve the efficiency of subsequently reading the classification information of the statistical block with any row and column numbers from the data file, record the total storage space size value required to store the classification information of all statistical blocks in each row; store the metadata information of the original classified grid data Data into the data file; this method can ensure the accuracy of the total number of pixels of each classification in each statistical block, and using the distribution flag bit data in the statistical block can record the distribution of pixels of each classification with less storage space, having a high data compression rate and flexible data precision control, and being applicable to various common classified grid data. BRIEF DESCRIPTION OF THE DRAWINGS
[0054] Figure 1 It is a flowchart of a storage method for a classified grid data of the present invention.
[0055] Figure 2 It is a flowchart of a reading method for a classified grid data of the present invention. DETAILED DESCRIPTION OF THE INVENTION
[0056] The principles and features of the present invention are described below with reference to the accompanying drawings. The examples given are only for explaining the present invention and are not intended to limit the scope of the present invention.
[0057] To reduce the data storage volume, save the cost of storage devices, and improve the network transmission efficiency, a storage and reading method for classified grid data is proposed.
[0058] Reference Figure 1 , a storage method for classified raster data, storing the original classified raster data Data composed of K rows and L columns of pixels, there are m non-repeating integer values corresponding to all pixels, that is, the pixels of the original classified raster data Data have m different attribute categories, assuming that the integer value of the first type of pixel is p1, the integer value of the second type of pixel is p2, ..., the integer value of the mth type of pixel is pm; for the convenience of description, the row and column numbers of the pixels and blocks of the original classified raster data Data are counted from 1. In this document, the symbol [x] represents the maximum integer not greater than x.
[0059] The storage method of classified raster data specifically includes the following steps:
[0060] S1. Re-divide the rows and columns of the original classified raster data Data:
[0061] The rows and columns of the original raster data Data composed of K rows and L columns of pixels are re-divided with the unit statistical area as the minimum granularity to obtain a rows and b columns of statistical blocks;
[0062] When K / s1 is an integer, a=K / s1;
[0063] When K / s1 is not an integer, a=[K / s1]+1;
[0064] When L / s2 is an integer, b = L / s2;
[0065] When L / s2 is not an integer, b=[L / s2]+1;
[0066] The unit statistical area is a grid data matrix with s1 rows and s2 columns, and s1 and s2 are constants.
[0067] The number of pixel rows s1 and columns s2 in the unit statistical area can be unequal or equal. If s1=s2=s, the unit statistical area is composed of s rows and s columns of pixels. The original classified raster data Data is divided from top to bottom and from left to right with the unit statistical area as the minimum granularity to obtain a rows and b columns of statistical blocks.
[0068] When K / s is an integer, a=K / s;
[0069] When K / s is not an integer, a=[K / s]+1, then there are s rows of pixels in the statistical blocks from the first row to the a-1th row, and there are (K-[K / s]*s) rows of pixels in the statistical block of the ath row;
[0070] When L / s is an integer, b = L / s;
[0071] When L / s is not an integer, b=[L / s]+1, then there are s columns of pixels in the statistical blocks from the first column to the b-1th column, and there are (L-[L / s]*s) columns of pixels in the statistical block of the bth column;
[0072] That is to say, when the original classified raster data Data cannot be completely divided by the unit statistical area, the actual number of pixels in the statistical block of the rightmost column or the bottom row is not equal to s*s.
[0073] That is, the number of pixels in the statistical block includes two cases: the statistical block contains s1*s2 pixels and the statistical block contains less than s1*s2 pixels.
[0074] S2. Storage of statistical block classification information and storage space size of statistical block classification information:
[0075] For a rows and b columns of statistical blocks, the classification information of each statistical block is counted row by row and column by column, and the classification information is stored in the data file Xdata. The classification information includes the total number of pixels of each classification in the statistical block, and the distribution flag data of all pixels whose total number of each classification is greater than 0 in the statistical block; the size of the storage space for the classification information of the statistical block is recorded and stored in the data file Xdata.
[0076] The classification information includes the total number of pixels in each classification in the statistical block. The total number of pixels in each classification in the statistical block in the classification information is stored in the data file Xdata, and the bit size required for storing the classification information of the current statistical block is recorded with the value Ts. The selected storage data type is determined according to the number of pixels in the unit statistical area, where the Ts value is initially 0.
[0077] Assume that the classification information of the statistical block in the jth row and qth column is stored, where 1<=j<=a, 1<=q<=b, and all pixel values of the statistical block are traversed in order. It is found that there are n1 pixels of the first category (integer value is p1); there are n2 pixels of the second category (integer value is p2); ...; there are n pixels of the mth category (integer value is p m ) Total n m The total number of pixels of each category in the statistical block is stored in order, that is, these m values, which are n1, n2, ..., n m ; When storing these m values, the selected data type needs to be determined based on the number of pixels in the unit statistical area.
[0078] For example, when the unit statistical area s1=s2=s=12, the total number of pixels in the unit statistical area is 144, and the maximum value of these m values does not exceed 144. At this time, the data type selected when storing these m values can be a 1-byte unsigned integer (the maximum value can be 255); when the unit statistical area s1=s2=s=20, the total number of pixels in the unit statistical area is 400, and the maximum value of these m values does not exceed 400. At this time, the data type selected when storing these m values can be a 2-byte unsigned integer (the maximum value can be 65535); in most applications, the unit statistical area s value is less than 256.
[0079] Therefore, when s1*s2<256, a 1-byte unsigned integer type is used to store the total number of pixels in each category, which requires a total of m bytes. When writing to the data file Xdata, m 1-byte unsigned integers are written continuously. At this time, the Ts value increases by 8*m.
[0080] When 256<=s1*s2<65536, a 2-byte unsigned integer type is used to store the total number of pixels in each category, requiring a total of 2m bytes. When writing to the data file Xdata, m 2-byte unsigned integers are written continuously, and the Ts value increases by 16*m.
[0081] When s1*s2>=65536, a 4-byte unsigned integer type is used to store the total number of pixels in each category, requiring a total of 4m bytes. When writing to the data file Xdata, m 4-byte unsigned integers are written continuously. At this time, the Ts value increases by 32*m.
[0082] The classification information also includes the distribution flag data of all pixels whose total number of each classification is greater than 0 in the statistical block, and the distribution flag data of all pixels whose total number of each classification is greater than 0 in the statistical block is stored in the data file Xdata. The distribution flag data determines the distribution of a certain type of pixels in the statistical block with the unit distribution area as the minimum granularity. The distribution flag data of each classification occupies w1*w2 bits of storage space, corresponding to the w1*w2 sub-areas divided in the statistical block. If there are pixels of this classification in a sub-area, the distribution flag value corresponding to the sub-area is set to 1, otherwise the distribution flag value corresponding to the sub-area is set to 0, where w1=s1 / t1, w2=s2 / t2, t1 is the row of the unit distribution area, and t2 is the column of the unit distribution area.
[0083] The size of the unit distribution area is determined according to the total number of pixels in the statistical block. The first type of statistical block is a statistical block containing s1*s2 pixels, and the unit distribution area t1 and t2 values are greater than 1 and satisfy s1 / t1, s2 / t2 are integers; the second type of statistical block is a statistical block containing less than s1*s2 pixels, and the unit distribution area t1 and t2 values are 1.
[0084] When the distribution flag data of a certain type of pixels whose total classification number is greater than 0 is stored in the data file Xdata, it is divided into two cases: the statistical block contains s1*s2 pixels, and the statistical block contains less than s1*s2 pixels.
[0085] For the first type of statistical block containing s1*s2 pixels, the distribution flag data storage process of a certain type of pixels whose total number in each classification is greater than 0: if the value of a certain type of pixel is equal to 0, it means that there is no pixel of this classification in the statistical block, then skip this value and continue to judge the next value; if the value of a certain type of pixel is greater than 0, it is necessary to store the distribution flag data of all pixels of this classification in the statistical block with the unit distribution area as the minimum granularity; if there are q (1<=q<=m) classifications of distribution flag data that need to be stored in the statistical block, a total of w1*w2*q bits of storage space are required, and these w1*w2*q bits of distribution flag data are written to the data file Xdata, and the value of Ts increases by w1*w2*q.
[0086] For the second type of statistical blocks containing less than s1*s2 pixels, if there are y pixels, the distribution flag data storage process of a certain type of pixels whose total number in each category is greater than 0: if there are q (1<=q<=m) categories of distribution flag data that need to be stored in the statistical block, a total of q*y bits of storage space are required; write these q*y bits of distribution flag data into the data file Xdata, and the value of Ts increases by q*y.
[0087] The storage space Ts value used for storing classification information for each statistical block may not be the same. After storing the classification information data of all statistical blocks in the data file Xdata in the order of the above steps, if the classification information is read and parsed from the first row and first column of each statistical block, the efficiency is low; if the data starting point position of the first column of each row of statistical blocks is known, the classification information of any statistical block can be quickly read, and it is only necessary to parse the statistical blocks from the first column of the row to a certain column of statistical blocks one by one. Therefore, in order to improve the efficiency of reading the classification information of statistical blocks of any row and column number from the data file in the future, it is necessary to record the total storage space size value required to store the classification information of all statistical blocks in each row.
[0088] Specifically, in the processing of S2, the cumulative value sumTs of the classification information storage space size of each column statistical block in each row is recorded, and sumTs is in bits, and is written into the data file rowSize. For a row and b columns of statistical blocks in step S1, a integer values e1, e2, ..., e3 can be accumulated by processing each row according to step S2. a , where e1 means that the total classification information storage space of the statistical blocks of all columns in the first row is e1 bits, e a The total classification information storage space of the statistical block of all columns in the last row is e a bits, and convert these integer values e1, e2, ..., e a Write to the data file rowSize.
[0089] S3. Store metadata information of the original classified raster data Data.
[0090] The metadata information includes the number of rows K and columns L of the original classified raster data Data, the total number of pixel classifications m, the pixel values corresponding to each type of pixel, the values of unit statistical areas s1 and s2, and the values of unit distribution areas t1 and t2. The metadata information is stored in the data file meta.
[0091] Reference Figure 2 Based on the above-mentioned storage method of classified raster data, the present invention also provides a method for reading classified raster data. Specific reading process:
[0092] To read the grid cell data D(r, c) of the pixel value of the rth row and cth column of the original classified grid data Data, where 1<=r<=K, 1<=c<=L, the following steps are included:
[0093] Step 1. Read the data file meta, obtain the metadata information of the original classified raster data Data, and obtain the number of rows K and columns L of the original classified raster data Data, the total number of pixel classifications m, the values of the unit statistical areas s1 and s2, the values of the unit distribution areas t1 and t2, and the pixel values corresponding to each type of pixel, such as the pixel value p1 of the first type, the pixel value p2 of the second type, ... the pixel value p of the mth type. m ; It is calculated that there are a rows and b columns of statistical blocks in the data file Xdata.
[0094] Step 2. Calculate the statistical block number where the pixel in the rth row and the cth column is located. Assume that the statistical block where the requested pixel is located has a row number of v and a column number of z.
[0095] When r / s1 is an integer, v=r / s1;
[0096] When r / s1 is not an integer, v=[r / s1]+1;
[0097] When c / s2 is an integer, z = c / s2;
[0098] When c / s2 is not an integer, z=[c / s2]+1.
[0099] Step 3. Read the data file rowSize and obtain the total storage space size value of the classification information of all statistical blocks in each column of each row, that is, obtain a integer values e1, e2, ..., e a , where e1 means that the total classification information storage space of the statistical blocks of all columns in the first row is e1 bits, e a The total classification information storage space of the statistical block of all columns in the last row is e a bits.
[0100] When v=1, the classification information of the first column of the first row of the statistics block starts at bit 0 of the data file Xdata, and the reading point position offset=0;
[0101] When v>1, the classification information of the first column of the vth row of the statistics block starts at e in the data file Xdata. (v-1) bit position, at this time the reading point position offset = e (v-1) ;
[0102] Read the statistics block at row v and column 1 in the data file Xdata from the read point position offset, and parse the classification information of the statistics block. Specifically,
[0103] Step 31. Read the total number of pixels of each category in the classification information.
[0104] When s1*s2<256, read 1-byte unsigned integer data one by one, a total of m times, and get integer values n1, n2, ..., n m ;
[0105] When 256<=s1*s2<65536, read 2-byte unsigned integer data one by one, a total of m times, and get integer values n1, n2, ..., n m ;
[0106] When s1*s2>=65536, read 4-byte unsigned integer data one by one, a total of m times, and get integer values n1, n2, ..., n m .
[0107] Specifically, when s1=s2=s, and when s<16, 1-byte unsigned integer type data is read one by one, and a total of m times are read to obtain integer values n1, n2, ..., n m ; When 16<=s<256, read 2-byte unsigned integer data one by one, a total of m times, and get integer values n1, n2, ..., n m ; When s>=256, read 4-byte unsigned integer data one by one, a total of m times, and get integer values n1, n2, ..., n m ;
[0108] Step 32: Read the distribution flag data of each category in the classification information.
[0109] For the m integer values n1, n2, ..., n obtained in the previous step m , determine whether it is greater than 0 one by one.
[0110] If n i If it is equal to 0, it means that there is no pixel of this classification in the statistical block, then skip this value and continue to judge the next value; if n i If it is greater than 0, it is necessary to read the distribution flag data of the category i in the statistical block; the value range of category i is 1<=i<=m.
[0111] Determine m integer values n1, n2, ..., n m Is the sum F equal to s1*s2?
[0112] In the first case, F=s1*s2, then the statistical block contains s1*s2 pixels, and the distribution flag data of each category occupies w1*w2 bits. Continue to read w1*w2 bits of data in the data file Xdata to obtain a bit array B[][] with w1 rows and w2 columns; determine whether the pixel in the cth column is in the statistical block.
[0113] It is worth explaining that: the two-dimensional array B[][] indicates whether the pixel of category i is distributed in a certain sub-area by dividing the statistical block into w1 rows and w2 columns of sub-areas with the minimum granularity of unit distribution area t1*t2 pixels; if B[g][h]=0, it means that there is no pixel of category i in the sub-area of g-th row and h-th column, 1<=g<=w1, 1<=h<=w2; if B[g][h]=1, it means that the sub-area of g-th row and h-th column contains pixels of category i.
[0114] If the pixel in the c-th column is within the statistical block: Calculate the sub-region row number gr and column number hc of this pixel within the statistical block, and accumulate all sub-regions where B[][] = 1. Suppose st sub-regions are obtained, which indicates that the pixels of classification i are distributed in st sub-regions, and the total number of pixels of classification i is n i ; Determine if B[gr][hc] = 1 for the sub-region row number gr and column number hc. Since each sub-region contains t1 * t2 pixels, the probability P that each pixel in the sub-region belongs to the i-th classification can be obtained bi = n i / (st * t1 * t2) * 100%; If B[gr][hc] = 0, this sub-region has no pixels of classification i, and the probability P bi = 0. According to this method, read the distribution flag bit data with a classification total greater than 0 one by one, and the probability value P that each pixel in the sub-region (row number gr and column number hc) belongs to each classification can be calculated b1 、P b2 、..、P bm , take the maximum probability value P bj (1 <= j <= m) of classification j as the classification of each pixel in this sub-region, that is, the value of the pixel in the r-th row and c-th column requested to be read is pj. From step 1, the integer value corresponding to each type of pixel can be known, and the reading is completed. It can be seen that the classification results of the t1 * t2 pixels in the sub-region are the same, with the sub-region as the calculation unit, and each bit in the stored distribution flag bit data corresponds to a sub-region.
[0115] If the pixel in the c-th column is not within the statistical block, it means that the pixel requested to be read is in the subsequent column of this statistical block, and continue to parse and process the classification information of the next column's statistical block.
[0116] In the second case, F < s1 * s2, which means that the number of pixels contained in this statistical block is less than s1 * s2. Then it is divided into the following situations:
[0117] This statistical block is the last row in the a * b statistical blocks. The number of pixel rows contained in this statistical block is rr = (K - [K / s1] * s1) rows of pixels, otherwise rr = s1;
[0118] This statistical block is the last column in the a * b statistical blocks. The number of pixel columns contained in this statistical block is cc = (L - [L / s2] * s2) rows of pixels, otherwise cc = s2.
[0119] At this time, the distribution flag bit data of each classification should occupy rr * cc bits. Therefore, continue to read rr * cc bits of data from the data file Xdata.
[0120] Assume that we get a bit two-dimensional array B[][] with rr rows and cc columns, and determine whether the pixel in the cth column is in the statistical block. At this time, there are two cases: the pixel in the cth column is in the statistical block and the pixel in the cth column is not in the statistical block.
[0121] If the pixel in the cth column is in the statistical block: calculate the pixel row number gg and pixel column number hh of the requested pixel in the statistical block, where 1<=gg<=rr, 1<=hh<=cc; to determine whether the requested pixel in the statistical block is a pixel of category i, it is only necessary to determine whether B[gg][hh] is equal to 1. If B[gg][hh]=1, the pixel requested to be read is of category i, and the value of the returned pixel is pi, and the reading is completed. It can be seen that among the m classification distribution flag data B[][], there must be one and only one classification distribution flag data B[gg][hh]=1.
[0122] If the pixel in the cth column is not in the statistical block, it means that the pixel requested to be read is in the subsequent column of the statistical block, and the classification information of the statistical block in the next column is continuously parsed and processed.
[0123] The present invention divides the original classified raster data Data into blocks with the unit statistical area as the minimum granularity, obtains a series of statistical blocks, and stores the classification information of each statistical block in order; the classification information includes the total number of pixels of each classification in the statistical block, and the distribution flag data of all pixels whose total number of each classification is greater than 0 in the statistical block; in order to improve the efficiency of reading the classification information of the statistical block with any row and column number from the data file in the future, the total storage space size value required for storing the classification information of all statistical blocks in each row is recorded; and the metadata information of the original classified raster data Data is stored in the data file. The method can ensure the accuracy of the total number of pixels of each classification in each statistical block, and the distribution flag data in the statistical block can be used to record the distribution of pixels of each classification with less storage space, and has a high data compression rate and flexible data accuracy control, and is suitable for various common classified raster data.
[0124] The value of the unit statistical area mainly depends on the number of categories m of the classified raster data; for the pixels in the statistical block, if the more classification types it contains, the larger the amount of distribution flag data of each classification pixel that needs to be stored, that is, the larger the storage space required for the classification information of the statistical block, that is, the data compression rate will be reduced; if the fewer classification types it contains, the smaller the storage space required for the classification information, and the data compression rate will be significantly improved; therefore, when the value of the number of categories m is small, the value of the unit statistical area is larger; when the value of the number of categories m is large, the value of the unit statistical area is smaller.
[0125] For example, when m=5, the value of the unit statistical area is s1=s2=15 (or a larger value). At this time, there are 225 pixels in the statistical block. Even if the distribution flag data storage space required for all classified pixels is only 125 bits at most (t1=t2=t=3), the classification information of the statistical block requires 165 bits of storage space. Compared with the 225 bytes required by the traditional storage method, this method saves 90% of the storage space.
[0126] For example, when m=15, the value of the unit statistical area can be s1=s2=9 (or a smaller value). At this time, there are 81 pixels in the statistical block. A smaller area is more likely to contain a smaller number of classified pixels, so the classification information requires less storage space. Assuming that 8 types of classified pixels are included, the required distribution flag data storage space is 8*9 bits (t1=t2=3), and the statistical block classification information requires 192 bits of storage space. Compared with the 81 bytes required by the traditional storage method, this method saves 70% of the storage space.
[0127] It can be seen from this that when the value of the unit statistical area is given, the fewer the types of classified pixels in the unit statistical area, the higher the data compression rate, which is also very consistent with the classified raster data in actual project applications; in local geographic areas, there are often only one or a few types of geographic elements. For example, in an area of 10*10 square meters (each pixel corresponds to 1 meter in length and width), there is usually only one type of grassland or two types of grassland and forestland. Generally, there are rarely more than a dozen land use types in an area of 100 square meters. Therefore, this method is applicable to most classified raster data storage.
[0128] The value of the unit distribution area mainly depends on the accuracy requirements of the pixel value data of the classified raster data at the application layer. Although the total number of pixels of each classification in the statistical block classification information stored in this method is accurate, the classified distribution flag data is stored with the unit distribution area as the minimum granularity. Therefore, when obtaining the value of the pixel in the rth row and cth column of a certain original classified raster data Data (assuming that the pixel is not in the second type of statistical block), what is actually parsed is the pixel classification probability of a sub-area (containing t1*t2 pixels) in a certain statistical block, which may have errors with the true classification value, resulting in data accuracy problems. It can be seen from the storage process that when the value of the unit distribution area is larger, the error is larger, but the corresponding distribution flag data volume is smaller. When the value is smaller, the error is smaller, but the corresponding distribution flag data volume is larger. In particular, when t1=t2=t=1 (used in the second type of statistical block), there is no pixel classification value error but the corresponding distribution flag data volume is the largest.
[0129] Therefore, for application systems that focus on performing classified statistical analysis of regions, when the accuracy requirements for a specific pixel value are not high, in order to obtain greater compression efficiency, the value of the unit distribution area can be set larger (such as t1=t2=t=5 or larger); when there are certain requirements for the data accuracy of a single pixel value, the value of the unit distribution area t can be set smaller (such as t1=t2=t=3 or smaller), thereby sacrificing a certain data compression rate in exchange for higher data accuracy.
[0130] Taking the national soil erosion degree classification raster data as an example, there are four pixel classifications, namely "no data value", "mild", "moderate" and "intense". At a resolution of 30 meters, the usual storage method consists of 134724 rows and 161360 columns of raster pixel data, using 1-byte unsigned integer value storage, and the total storage space required is about 20.24GB.
[0131] In this method, since the number of classifications m = 4 is small, the unit statistical area is s1 = s2 = 15. In addition, the user focuses on the statistical analysis of the erosion degree classification, and the accuracy requirement for a specific pixel value is not high. The unit distribution area is set to t1 = t2 = t = 5, and a = 8982, b = 10758 statistical blocks are obtained. According to statistics, about 88% of these statistical blocks contain only one type of pixels, about 11% contain two types of pixels, and the rest are about 1%; the classification information of each statistical block containing one type of pixels needs to be stored The storage space is 41 bits, and the classification information of each statistical block containing Class II pixels requires a storage space of 50 bits; the storage space required for all statistical blocks is about 483MB; the total storage space required to store the classification information of all statistical blocks in each row of a=8982 rows requires a total storage space of 8*a bytes, about 70KB, and the metadata information storage space of the original classified raster data Data can be ignored. The total storage space is about 2.3% of the original data storage size. It can be seen that this method greatly saves storage space.
[0132] The storage and reading method of the classified raster data of the present invention has the following advantages: ensuring the accuracy of the total number of classified pixels in the basic unit (statistical block) of statistical analysis of the classified raster data; having a high data compression rate; flexible data accuracy control; and having a very wide range of applicability and a high value of promotion and use.
[0133] The above description is only a preferred embodiment of the present invention and is not intended to limit the present invention. Any modifications, equivalent substitutions, improvements, etc. made within the spirit and principle of the present invention should be included in the protection scope of the present invention.
Claims
1. A storage method for classified raster data, characterized in that: Storing the original classified raster data Data consisting of K rows and L columns of m types of pixels includes the following steps: S1. Re-dividing the rows and columns of the original raster data Data composed of K rows and L columns of pixels with the unit statistical area as the minimum granularity to obtain a rows and b columns of statistical blocks; When K / s1 is an integer, a=K / s1; When K / s1 is not an integer, a=[K / s1]+1; When L / s2 is an integer, b = L / s2; When L / s2 is not an integer, b=[L / s2]+1; Among them, the unit statistical area is a grid data matrix with s1 rows and s2 columns; S2. For a row and b column statistical blocks, count the classification information of each statistical block row by row and column by column, and store the classification information in the data file Xdata, wherein the classification information includes the total number of pixels of each classification in the statistical block, and the distribution flag data of all pixels whose total number of each classification is greater than 0 in the statistical block; record the storage space size of the statistical block classification information, and store it in the data file Xdata; S3. Storing metadata information of the original classified raster data Data, and storing the metadata information in a data file meta; The distribution flag data determines the distribution of a certain type of pixel in the statistical block with the unit distribution area as the minimum granularity. The distribution flag data of each category occupies w1*w2 bits of storage space, corresponding to the w1*w2 sub-areas divided in the statistical block; if there is a pixel of this category in a sub-area, the distribution flag value corresponding to the sub-area is set to 1, otherwise the distribution flag value corresponding to the sub-area is set to 0, wherein w1=s1 / t1, w2=s2 / t2, t1 is the row of the unit distribution area, and t2 is the column of the unit distribution area.
2. A storage method for classified raster data according to claim 1, characterized in that: If the statistical block contains s1*s2 pixels, the unit distribution area t1 and t2 values are greater than 1 and satisfy s1 / t1, s2 / t2 are integers; if the statistical block contains less than s1*s2 pixels, the unit distribution area t1 and t2 values are 1.
3. A storage method for classified raster data according to claim 2, characterized in that: The storage process of the total number of pixels of each classification in the statistical block includes: recording the bit size required for storing the classification information of the current statistical block with a value Ts, and the selected storage data type is determined according to the number of pixels in the unit statistical area, wherein the Ts value is initially 0; When s1*s2<256, a 1-byte unsigned integer type is used to store the total number of pixels in each classification, which requires a total of m bytes. When writing to the data file Xdata, m 1-byte unsigned integers are written continuously. At this time, the Ts value increases by 8*m; When 256<=s1*s2<65536, a 2-byte unsigned integer type is used to store the total number of pixels in each classification, requiring a total of 2m bytes. When writing to the data file Xdata, m 2-byte unsigned integers are written continuously, and the Ts value increases by 16*m at this time; When s1*s2>=65536, a 4-byte unsigned integer type is used to store the total number of pixels in each category, requiring a total of 4m bytes. When writing to the data file Xdata, m 4-byte unsigned integers are written continuously. At this time, the Ts value increases by 32*m.
4. The storage method of classified raster data according to claim 3, characterized in that: If the statistical block contains s1*s2 pixels, the distribution flag data storage process of each type of pixels whose total number of classifications is greater than 0 includes: If the value of a certain type of pixel is equal to 0, it means that there is no pixel of this classification in the statistical block, then skip this value and continue to judge the next value; If the value of a certain type of pixel is greater than 0, the distribution flag data of all pixels of this category in the statistical block with the unit distribution area as the minimum granularity is stored; if there are q categories of distribution flag data that need to be stored in the statistical block, a total of w1*w2*q bits of storage space are required. These w1*w2*q bits of distribution flag data are written to the data file Xdata, and the value of Ts increases by w1*w2*q, where 1<=q<=m.
5. The storage method of classified raster data according to claim 3, characterized in that: If the statistical block contains less than s1*s2 pixels, if there are y pixels, the distribution flag data storage process of a certain type of pixels whose total number of each classification is greater than 0 includes: If there are q categories of distribution flag data that need to be stored in the statistical block, a total of q*y bits of storage space are required; the q*y bits of distribution flag data are written into the data file Xdata, and the value of Ts increases by q*y, where 1<=q<=m.
6. A storage method for classified raster data according to claim 4 or 5, characterized in that: Record the total storage space size required to store the classification information of all statistical blocks in each row and write it to the data file rowSize.
7. The storage method of classified raster data according to claim 2, characterized in that: The metadata information includes the number of rows K and columns L of the original classified raster data Data; the total number of pixel categories m; the pixel values corresponding to each category of pixels, the pixel value pm of the mth category; the values of unit statistical areas s1 and s2; and the values of unit distribution areas t1 and t2.
8. A method for reading classified raster data, used for reading raster data stored according to a method for storing classified raster data according to any one of claims 6 to 7, characterized in that: To read the grid cell data D(r, c) of the pixel value of the rth row and cth column of the original classified grid data Data, where 1<=r<=K, 1<=c<=L, the following steps are included: S1. Read the data file meta, obtain the metadata information of the original classified raster data Data, and calculate that there are a rows and b columns of statistical blocks in the data file Xdata; S2. Calculate the statistical block number where the pixel in the rth row and cth column belongs. If the number of rows and columns of the statistical block to which it belongs is v and z, then: When r / s1 is an integer, v=r / s1; When r / s1 is not an integer, v=[r / s1]+1; When c / s2 is an integer, z = c / s2; When c / s2 is not an integer, z=[c / s2]+1; S3. Read the data file rowSize to obtain the total storage space size value of the classification information of all statistical blocks in each column of each row; When v=1, the classification information of the first column of the first row of the statistics block starts at bit 0 of the data file Xdata, and the reading point position offset=0; When v>1, the classification information of the first column of the vth row of the statistics block starts at e in the data file Xdata. (v-1) bit position, at this time the reading point position offset = e (v-1) ; The data file Xdata is read from the read point position offset, and the classification information of the statistical block is parsed.
9. The method for reading classified raster data according to claim 8, characterized in that: The classification information of the parsing statistics block includes the following steps: S31. Read the total number of pixels of each category in the classification information: When s1*s2<256, read 1-byte unsigned integer data one by one, a total of m times, and get integer values n1, n2, ..., n m ; When 256<=s1*s2<65536, read 2-byte unsigned integer data one by one, a total of m times, and get integer values n1, n2, ..., n m ; When s1*s2>=65536, read 4-byte unsigned integer data one by one, a total of m times, and get integer values n1, n2, ..., n m ; S32. Read the distribution flag data of each category in the classification information; S321. For the obtained m integer values n1, n2, ..., n m , judge whether it is greater than 0 one by one; If i If it is equal to 0, it means that there is no pixel of this classification in the statistical block, then skip this value and continue to judge the next value; if n i If it is greater than 0, the distribution flag data of the category i in the statistical block is read, where the value range of category i is 1<=i<=m; S322. Determine m integer values n1, n2, ..., n m Is the sum F equal to s1*s2? If F = s1*s2, then the statistical block contains s1*s2 pixels, and the distribution flag data of each classification occupies w1*w2 bits. Continue to read w1*w2 bits of data in the data file Xdata, that is, w1*w2 sub-areas, and obtain a bit array B[][] with w1 rows and w2 columns; If the pixel in the cth column is in the statistical block, calculate the sub-region row number gr and column number hc of the pixel in the statistical block; accumulate all sub-regions with B[][]=1 to obtain the sub-regions and their number st of pixel distribution of category i; calculate the probability value P of each pixel in the sub-region belonging to each category bi , take the category j with the maximum probability value as the category of each pixel in the sub-region, and return the pixel value pj corresponding to the pixel category j in the rth row and cth column requested to be read, and the reading is completed, where P bi =n i / (st*t1*t2)*100%,1<=j<=m,n i is the total number of pixels of category i; otherwise, continue parsing and processing the classification information of the statistical block in the next column; If F < s1 * s2, the number of pixels contained in the statistical block is less than s1 * s2. The distribution flag bit data for each classification is calculated to occupy rr * cc bit positions. Continue to read rr * cc bit positions of data from the data file Xdata to obtain rr * cc sub-regions, that is, obtain a two-dimensional array B[][] of rr rows and cc columns of bit positions. If the pixel in the c-th column is in the statistical block, calculate the pixel row number gg and pixel column number hh of this pixel in the statistical block, and determine whether this pixel in the statistical block is a pixel of classification i. If B[gg][hh] = 1, the pixel to be read belongs to classification i, and return the value p of the pixel i , the reading ends, where rr = (K - [K / s1] * s1), cc = (L - [L / s2] * s2), 1 <= gg <= rr; 1 <= hh <= cc; otherwise, continue to parse and process the classification information of the statistical block in the next column.
Citation Information
Patent Citations
Method and device for writing-in and reading remote-sensing image data
CN102902491A
Storage method and reading method for mass tile data
CN103412962A