[gdal-dev] Black borders after reprojection GDAL_WARP

Carl Godkin cgodkin at gmail.com
Thu Nov 18 05:10:11 PST 2021


 Hi Lorenzo,

I have faced this and there are two things to consider.

First, you can specify the georeferenced extents _and_ the SRS  of the
extents using something like this:

    gdalwarp -t_srs EPSG:3857 \
        -te_srs EPSG:4326 -te -109 32 -102 36 \
        input.tif output.tif

Note that I'm warping to one coordinate system but trimming based on
another one.  Is it possible that your black boundary is due to trimming in
the wrong coordinate system?  For instance, if your input map is projected
but the boundary of the map consists of parallels of latitude or
meridians of longitude, then you could use something like the above.  (You
can actually get even fancier by trimming with polygons too; see this
example for inspiration:
https://gis.stackexchange.com/questions/45053/gdalwarp-cutline-along-with-shapefile
.)

Second, recognize that the output will always be a rectangle in the output
SRS.  If the black border is due to "no data" areas outside the input map's
extent appearing in the output map, then you can use -dstalpha ("Create an
output alpha band to identify nodata (unset/transparent) pixels.") to mark
the output pixels that shouldn't be part of the map.  Basically your black
pixels become transparent in this case.

I hope that helps,
carl


On Wed, Nov 17, 2021 at 8:11 AM Lorenzo Di Giacomo <loridigia at gmail.com>
wrote:

> Hi all, i have a question, how is it possible to avoid black borders after
> reprojection with "gdal_warp" ?
> Basically i have an image that is little rotated, when i reprojected from
> 32632 to 4326 the resulting image has black borders more or less tight
> depending on the rotation.
> I saw i can change the colors of those no_data (using -dstnodata) but how
> can i do if i dont want it at all? Adding another band result in a size
> increase, that i don't want either.
>
> Thanks !!
> _______________________________________________
> gdal-dev mailing list
> gdal-dev at lists.osgeo.org
> https://lists.osgeo.org/mailman/listinfo/gdal-dev
>
-------------- next part --------------
An HTML attachment was scrubbed...
URL: <http://lists.osgeo.org/pipermail/gdal-dev/attachments/20211118/fddb1f5b/attachment.html>


More information about the gdal-dev mailing list