Topics

Using Python rasterio package to read gif file and world file, re-project to another picture

gd.zhu@...
 

Hello,

I want to re-project a radar image (https://radar.weather.gov/Conus/RadarImg/latest_radaronly.gif) which is in NAD83/EPSG4326 to WGS84/Pseudo-Mercator/EPSG3857. There is a world file associated with this gif (https://radar.weather.gov/Conus/RadarImg/latest_radaronly.gfw). I was wondering how can I do this projection using Python rasterio package, and how to extract the coordinates bounds from the new re-projected picture?

I'm very new to GIS. I know world file contains georeferencing information, but I stucked at the first step and don't know how to read gif file along with the world file... 

Thanks a lot for your time and help! 

Best regards, 
Guodong

Sean Gillies
 

Hi Guodong,

If you save the .gif and the .gfw file to the same directory, so that they are siblings, rasterio will find the .gfw automatically when the .gif file is opened. This behavior is inherited from the GDAL library that rasterio uses and is a common GIS paradigm. Many GIS file formats are actually multi-file formats. One file, usually the image file, is the primary file and it may have auxiliary or "sidecar" files that carry additional information. A world file is one such auxiliary file.

Because rasterio's programs don't handle colormapped images well, I suggest that you use the GDAL programs instead. Like this:

gdal_translate -of GTiff -a_srs EPSG:4326 latest_radaronly.gif latest_radaronly.tif
gdalwarp -r near -t_srs EPSG:3857 latest_radaronly.tif warped.tif

Rasterio's rio-info program will show you the bounds

$ rio info warped.tif
{"bounds": [-14207635.496435506, 2470074.029222458, -7406084.60511778, 6518566.074162895], "colorinterp": ["palette"], "count": 1, "crs": "EPSG:3857", "descriptions": [null], "driver": "GTiff", "dtype": "uint8", "height": 1922, "indexes": [1], "interleave": "band", "lnglat": [-97.07967556953324, 37.395081418108624], "mask_flags": [["nodata"]], "nodata": 0.0, "res": [2106.3954448181253, 2106.3954448181253], "shape": [1922, 3229], "tiled": false, "transform": [2106.3954448181253, 0.0, -14207635.496435506, 0.0, -2106.3954448181253, 6518566.074162895, 0.0, 0.0, 1.0], "units": [null], "width": 3229}

The rio-bounds program will give you the bounds as GeoJSON

$ rio bounds warped.tif
{"bbox": [-127.62936117647057, 21.654332979481737, -66.5299899625959, 50.41561201989618], "geometry": {"coordinates": [[[-127.62936117647057, 21.654332979481737], [-66.5299899625959, 21.654332979481737], [-66.5299899625959, 50.41561201989618], [-127.62936117647057, 50.41561201989618], [-127.62936117647057, 21.654332979481737]]], "type": "Polygon"}, "properties": {"filename": "warped.tif", "id": "0", "title": "warped.tif"}, "type": "Feature"}


On Thu, Mar 5, 2020 at 6:29 AM <gd.zhu@...> wrote:

Hello,

I want to re-project a radar image (https://radar.weather.gov/Conus/RadarImg/latest_radaronly.gif) which is in NAD83/EPSG4326 to WGS84/Pseudo-Mercator/EPSG3857. There is a world file associated with this gif (https://radar.weather.gov/Conus/RadarImg/latest_radaronly.gfw). I was wondering how can I do this projection using Python rasterio package, and how to extract the coordinates bounds from the new re-projected picture?

I'm very new to GIS. I know world file contains georeferencing information, but I stucked at the first step and don't know how to read gif file along with the world file... 

Thanks a lot for your time and help! 

Best regards, 
Guodong



--
Sean Gillies