<div dir="ltr">Hello GDAL Dev community!<div><br></div><div>First time question asker here, and it doesn't seem like this specific task has been asked about before.</div><div><br></div><div>Problem: I have a bunch of KML superoverlays which I am tasked with converting them all to geotiff. I am running into an issue with the rotation values not being 0.0, which results in improperly georeferenced rasters. I've attempted a few different solutions, which I'll outline below.</div><div><br></div><div>Here is a sample KML bounding box (exact coords omitted for anonymity):</div><div><br></div><div><?xml version="1.0" encoding="UTF-8"?><br><kml xmlns="<a href="http://www.opengis.net/kml/2.2">http://www.opengis.net/kml/2.2</a>" xmlns:gx="<a href="http://www.google.com/kml/ext/2.2">http://www.google.com/kml/ext/2.2</a>" xmlns:kml="<a href="http://www.opengis.net/kml/2.2">http://www.opengis.net/kml/2.2</a>" xmlns:atom="<a href="http://www.w3.org/2005/Atom">http://www.w3.org/2005/Atom</a>"><br></div><div><GroundOverlay><br>     <name>KML Name</name><br>     <Icon><br>          <href>image_path.jpg</href><br>          <viewBoundScale>0.75</viewBoundScale><br>     </Icon><br>     <LatLonBox><br>          <north>40.5</north><br>          <south>40.4</south><br>          <east>-105.2</east><br>          <west>-105.1</west><br>          <rotation>58.0</rotation><br>     </LatLonBox><br></GroundOverlay><br></div><div><br></div><div>The code snippet below is my current iteration, the only inputs are IN_KML_PATH, OUT_TIFF_NAME, and then the ROTATION value in degrees read directly from the KML LatLonBox.</div><div><br></div><div>Here it is:</div><div><br></div><div>'''</div><div>#Dependencies</div><div>import gdal</div><div>from affine import Affine</div><div><br></div><div>#Driver for writing geotiff</div><div>tiff_driver = gdal.GetDriverByName('GTiff')</div><div><br></div><div>#Setting up data source, getting GeoTransform and other relevant info</div><div>in_ds = gdal.OpenEx(IN_KML_PATH)</div><div>in_geotransform = in_ds.GetGeoTransform()</div><div>in_projection = in_ds.GetProjection()</div><div>primary_band = in_ds.GetRasterBand(1)</div><div><br></div><div>#Creating an affine geotransform and rotating it 58.0 degrees anticlockwise (KML specs)</div><div>#This is obviously where I'm going wrong, but don't quite know what I'm missing!</div><div>af_geotransform = Affine.from_gdal(*in_geotransform)</div><div>af_geotransform *= Affine.rotation(-58.0)</div><div><br></div><div>#Creating out tiff </div><div>out_ds = tiff_driver.Create(OUT_TIFF_NAME, </div><div>     primary_band.XSize, </div><div>     primary_band.YSize, </div><div>     in_ds.RasterCount, </div><div>     primary_band.DataType)</div><div><br></div><div>#Setting projection and new geotransform</div><div>out_ds.SetProjection(in_projection)</div><div>out_ds.SetGeoTransform(af_geotransform.to_gdal())</div><div><br></div><div><br></div><div>#Writing in bands to the output image</div><div>for i in range(1, in_ds.RasterCount + 1):</div><div>     in_band = in_ds.GetRasterBand(i)</div><div>     in_data = in_band.ReadAsArray()</div><div>     out_band = out_ds.GetRasterBand(i)</div><div>     out_band.WriteArray(in_data)</div><div><br></div><div>#Fin</div><div>out_ds.FlushCache()</div><div>del out_ds</div><div>'''</div><div><br></div><div>I've tried a few different methods for rotating the in_geotransform, including:directly changing the 'rotation' values from default 0.0 to the rotation value in the KML. This does not result in anything resembling what I need. I assume I'm missing a translation step in the affine transformation, but haven't gotten too far there. </div><div><br></div><div>I know this was a lengthy question, I tried to be as detailed as possible about what I've attempted so far. I don't think there is anything going wrong per say, just reaching out to the community to see if I could get any direction here! </div><div><br></div><div><br></div><div>Cheers,</div><div><br></div><div>Chris Moulton</div><div><a href="mailto:cmoultonatx@gmail.com">cmoultonatx@gmail.com</a></div></div>