1. Introduction
When the author realizes the visualization of grid data, I encountered a problem. Calculating the geographical transformation information error at the level of the graphic data pyramid level caused a small error when visualization. Geographical transformation information refers to the starting point and resolution of the geographical coordinate of grid data. In another article"The starting point of the coordinates read by GDAL is in the upper left corner of the pixel or the pixel center? "It discusses the problem of half pixels in the starting point of the grid data set coordinates. But how does the pyramid hierarchy of the grid data set deal with this problem?
2. Details
2.1 Continuous or discrete
from"The starting point of the coordinates read by GDAL is in the upper left corner of the pixel or the pixel center? "This article continues to extend a question: Is the grid data continuous or discrete? From the perspective of GIS, grid data is the expression of real world geographical entities, and it should definitely be continuous. But the problem is that there is no such perfect carrier that can express continuous physical objects, and most of them will be discretely into grids. For example, the data carrier of images and screens, they are essentially grid. If you magnify them, you can see the magnifying grid. GIS's grid data is expressed through these discrete data vectors. Can you say that grid data must be continuous? So the author has a conclusion:
GIS's grid data is continuous in macro, and it is discrete in the micro。
In fact, this conclusion that some readers may not be able to accept it, because everyone has their own inherent cognition, and forcibly accept the cognition of others to shatter their own three views. For example, my former colleague is disapproved of my theory. There will always be a question: If the grid data is discretely into an integer, where is the pixel with a horizontal coordinates of 0.6? In fact, I don't think it is possible to understand this. A discrete pixel grid does correspond to a length of the real geographical entity, but a pixel grid is already the smallest expression entity, so you can only use the value of the position of the center of the pixel grid. Express the value of the entire pixel grid. The pixels with a horizontal coordinate 0.6 do not exist in the data carrier, but the data expressed does exist objectively. It must be processed by this value. The most adjacent, dual -linearity, and three convolutional algorithms are available.
2.2 Starting point position issues
In the author's opinion, whether the grid data is continuous or discretely, in fact, the position problem of geographical coordinates in the grid data is actually associated. The geographical transformation information stored inside the TIF data specifies the starting point of the geographical coordinates in the upper corner of the pixel, which is the continuity of the grid data; the TIF external data TFW stipulates the starting point of the geographical coordinate at the pixel center point, which focuses on the discrete type of grid data. Essence So when does the upper left corner of the pixel use the pixel center point as the starting point? The author's opinion is that for GIS grid data only:
When calculating the space calculation, the upper point of the pixel should start; when the image processing is processed, the pixel center point should start。
For example, the author has a grid data here, and the query information is as follows through GDALINFO:
Driver: GTiff/GeoTIFF
Files:
Size is 19312, 22531
Origin = (1967768.351536701666191,570294.132588228210807)
Pixel Size = (0.250000000000000,-0.250000000000000)
Metadata:
AREA_OR_POINT=Area
Image Structure Metadata:
COMPRESSION=LZW
INTERLEAVE=PIXEL
Corner Coordinates:
Upper Left ( 1967768.352, 570294.133)
Lower Left ( 1967768.352, 564661.383)
Upper Right ( 1972596.352, 570294.133)
Lower Right ( 1972596.352, 564661.383)
Center ( 1970182.352, 567477.758)
Band 1 Block=19312x32 Type=Byte, ColorInterp=Red
Min=0.000 Max=255.000
Minimum=0.000, Maximum=255.000, Mean=110.556, StdDev=57.195
Overviews: 9656x11266, 4828x5633, 2414x2817, 1207x1409, 604x705, 302x353, 151x177
Metadata:
STATISTICS_MAXIMUM=255
STATISTICS_MEAN=110.55552426626
STATISTICS_MINIMUM=0
STATISTICS_STDDEV=57.19535628196
STATISTICS_VALID_PERCENT=100
Band 2 ...
Band 3 ...
The calculations of the four -to -four -to -range (upper left, LOWER Left, Upper Right, and LOWER RIGHT) are calculated based on the upper point of the pixel left (Origin). Interested readers can check it. However, if you need to visualize this grid data, you usually need to pass the grid value to the IMAGE object value of the GUI canvas, and align the grid pixels. Value, at this time, it is best to calculate with pixel centers as a starting point.
2.3 Pyramid hierarchical image
Finally return to the problem of the calculation of geographical transformation information at the pyramid level. When visualization, the pixel center is used as the starting point for the calculation of space coordinates, and the appropriate pixel value is reinstated. But first of all, the four -to -range range of any pyramid image cannot be changed. For the above example, the width height of the original image is 19312 × 22531, and the first layer of pyramid image is 9656 × 11266.
The starting point position will not change, Origin = (1967768.351536701666191,570294.13258228210807).
The resolution needs to be re -calculated, in the X direction, (19312 * 0.25)/ 9656 = 0.5; in the Y direction, (22531 * 0.25)/ 11266 = 0.49997780933783064. That is, pixel size = (0.500000000000000, -0.4999780933783064).
At this time, a slightly weird phenomenon occurs, that is, the resolution of the X direction of the X direction on the original raster image is 0.25, but there are already tiny differences in the first -level pyramid hierarchical image. In fact, the reason for this phenomenon is not surprising, because the height of the pyramid level is usually decreased at multiple of 2, but the height of the original grid is not even. In this case, priority should be given to the consistency of the four to range of the geographical coordinates.
Next, calculate the pixel center as the starting point, geographical transformation information:
The resolution will not change, it is also pixel size = (0.5000000000000000000, -0.49997780933783064).
The starting point position needs to be offset half pixels, move to the pixel center, Origin = (1967768.601536701666191,570293.8825932354189168))
It must be noted that in the case of pixel center as the starting point, the starting point coordinates of each pyramid hierarchical image will change because the resolution of each pyramid level is different.
3. Other
Through the above methods, you can calculate the geographical transformation information of any pyramid hierarchical image. Not only the pyramid -level image, the author is"Summary of GDAL on Reading and Writing Images"This article introduces when GDAL reads raster data, you can read it again and read, as shown below:
// Apply for buf
size_t imgbufnum = (size_t) bufwidth * bufheight * bandnum * depth;
size_t imgbufoffset = (size_t) bufwidth * (bufheight-) * bandnum * depth;
Gbyte *imgbuf = new gbyte [imgbufnum];
// Read
img->RasterIO(GF_Read, 0, 0, imgWidth, imgHeight, imgBuf + imgBufOffset, bufWidth, bufHeight,
Gdt_byte, bandnum, nullptr, bandnum*depth, -bufwidth*bandnum*depth, depth);
// Write
dst->RasterIO(GF_Write, 0, 0, bufWidth, bufHeight, imgBuf + imgBufOffset, bufWidth, bufHeight,
Gdt_byte, bandnum, nullptr, bandnum*depth, -bufwidth*bandnum*depth, depth);
//release
delete [] imgbuf;
imgbuf = nullptr;
The wide heights, IMGHEIGHT, and Buffer blocks, and BUFWIDth, and Bufheight are inconsistent, and GDAL will automatically processes this process by re -sampling. We know the geographical transformation information of the image block, but the geographical transformation information of the buffer block needs to be calculated by itself. The principle is the same. It is necessary to give priority to ensure that the four to the BUFFER block is consistent with the four to the four to the image block. First calculate the resolution, and calculate the specific starting point position at the distance of the half pixel.