I've been developing my QGIS plugin for few weeks now. It's going to be pretty similar to well known GDAL Georeferencer plugin, but including few more helpful features. So far my code has been working pretty fine, but I met a serious problem and I can't manage to solve it.
I'd love to know how to obtain the dx/dy/residual errors for GCPs after gdalwarp excuting?
I mean the errors that GDAL georeferencer shows in last 3 columns of GCP table. They did it somehow in C++, but I can't figure out how.
What I do is simply:
1
gdal_translate -of GTiff [GCPs] [source.tif] [temp.tif]
2
gdalwarp -r near -order 1 -co COMPRESS=NONE [temp.tif] [final.tif]
Then I type gdalinfo [temp.tif]
so I can see GCP list in answer, but it is the file before georeference. Unfortunatlly, gdalinfo [final.tif]
gives is no info about GCPs.
However if I use VRT format instead of GeoTIff for gdal_translate
and gralwarp
outputs there is a little bit more information. I think it could be a step beyond.
In [final.vrt]
GCPs are listed, but without errors (dx/dy/rms). There are also lines called <DstGeoTransform>
and <DstInvGeoTransform
>. I think they may have something in common with errors I want to get.
Does anybody know how to deal with it?
The perfect solution for me would be to get a formula to calculate new coordinates for GCPs using the transformation from gdalwarp
. Then i'd simply compare computed coordinates and those which user received clicking in map canvas.
Unfortunately, gdalwarp works with rasters, not with pure points.
Have you got any ideas to solve my problem?
I've already searched through the stackexchange. The subect have already been raised, but not solved. How to preserve GCP's after gdalwarp
I attach a part of example final.vrt below
<VRTDataset rasterXSize="547" rasterYSize="732" subClass="VRTWarpedDataset">
<GeoTransform> 2.2187573162167482e+006, 3.0844837064488870e+000, 0.0000000000000000e+000, 6.4578332124060132e+006, 0.0000000000000000e+000,-3.0844837064488870e+000</GeoTransform>
<VRTRasterBand dataType="Byte" band="1" subClass="VRTWarpedRasterBand">
<ColorInterp>Palette</ColorInterp>
...
</VRTRasterBand>
<VRTRasterBand dataType="Byte" band="2" subClass="VRTWarpedRasterBand">
<ColorInterp>Alpha</ColorInterp>
</VRTRasterBand>
<BlockXSize>512</BlockXSize>
<BlockYSize>128</BlockYSize>
<GDALWarpOptions>
<WarpMemoryLimit>6.71089e+007</WarpMemoryLimit>
<ResampleAlg>NearestNeighbour</ResampleAlg>
<WorkingDataType>Byte</WorkingDataType>
<Option name="INIT_DEST">0</Option>
<SourceDataset relativeToVRT="0">G:Python/Python/okno_QGIS/smieci/mapa_krakowa 1.vrt</SourceDataset>
<Transformer>
<ApproxTransformer>
<MaxError>0.125</MaxError>
<BaseTransformer>
<GenImgProjTransformer>
<SrcGCPTransformer>
<GCPTransformer>
<Order>2</Order>
<Reversed>0</Reversed>
<GCPList>
<GCP Id="" Pixel="158.0590" Line="178.4810" X="2.219220000000E+006" Y="6.457240000000E+006" />
<GCP Id="" Pixel="374.7860" Line="297.1410" X="2.219910000000E+006" Y="6.456890000000E+006" />
<GCP Id="" Pixel="177.6730" Line="347.1550" X="2.219290000000E+006" Y="6.456710000000E+006" />
<GCP Id="" Pixel="79.6064" Line="301.0640" X="2.219010000000E+006" Y="6.456850000000E+006" />
<GCP Id="" Pixel="232.5900" Line="468.2670" X="2.219490000000E+006" Y="6.456350000000E+006" />
<GCP Id="" Pixel="63.4254" Line="426.0980" X="2.218950000000E+006" Y="6.456450000000E+006" />
<GCP Id="" Pixel="323.7910" Line="535.4420" X="2.219770000000E+006" Y="6.456150000000E+006" />
<GCP Id="" Pixel="191.8920" Line="616.8370" X="2.219360000000E+006" Y="6.455880000000E+006" />
<GCP Id="" Pixel="218.8600" Line="162.3000" X="2.219430000000E+006" Y="6.457290000000E+006" />
<GCP Id="" Pixel="303.1980" Line="201.5260" X="2.219690000000E+006" Y="6.457170000000E+006" />
<GCP Id="" Pixel="282.1130" Line="140.7250" X="2.219620000000E+006" Y="6.457360000000E+006" />
<GCP Id="" Pixel="107.0650" Line="102.4790" X="2.219080000000E+006" Y="6.457460000000E+006" />
<GCP Id="" Pixel="264.4610" Line="67.6657" X="2.219560000000E+006" Y="6.457600000000E+006" />
<GCP Id="" Pixel="400.2830" Line="117.1890" X="2.219990000000E+006" Y="6.457460000000E+006" />
<GCP Id="" Pixel="415.9740" Line="209.3720" X="2.220050000000E+006" Y="6.457160000000E+006" />
</GCPList>
</GCPTransformer>
</SrcGCPTransformer>
<DstGeoTransform>2218757.3162167482,3.084483706448887,0,6457833.2124060132,0,-3.084483706448887</DstGeoTransform>
<DstInvGeoTransform>-719328.59025252087,0.32420336599906463,0,2093651.2645225821,0,-0.32420336599906463</DstInvGeoTransform>
</GenImgProjTransformer>
</BaseTransformer>
</ApproxTransformer>
</Transformer>
<BandList>
<BandMapping src="1" dst="1" />
</BandList>
<DstAlphaBand>2</DstAlphaBand>
</GDALWarpOptions>
</VRTDataset>