Dear list,

Below you will find a question from my intern Bram. Unfortunately I could not 
help him out either since I only use the gdal executables.
We would highly appreciate your help calling GDAL functions from within Python.

Kind regards,
Siebe Bosch


Hi devs,

This is my first time using the Gdal library directly in Python using the 
Anaconda Spyder shell. I want to write a program that automatically imports 
GRIB files from a public ftp server and use GDAL to perform some actions. I 
installed GDAL with the PIP installer. Python version 2.7.13, Anaconda 32-bit, 
GDAL 3.0.8.
First off it worked well; GDAL opened the file and could read its information 
(as in raster size and coordinates (not taking the automatically importing from 
the server into account)). I did noticed the difference in commands (for 
example, gdal_Translate turns into gdal.Translate(src_ds, DestName, **kwargs)):

Import gdal
From osgeo import osr
src_ds = gdal.Open('C:\Users\wijna_000\H11_V72_NED_SINGLE_LEVEL_00_000_GB')

raster_wkt = src_ds.GetProjection()
spatial_ref = osr.SpatialReference()
spatial_ref.ImportFromWkt(raster_wkt)
print spatial_ref.ExportToPrettyWkt()

From here I want to transform the GRIB file into ,preferably ASCII files, but 
tried .tif first since it’s the default. But when I run the gdal.Translate 
command and do the coordinate check again it still returns as data imported 
from a grib-file:

tif_ds = gdal.Translate("C:\Users\wijna_000\output.tif", src_ds)

raster_wkt2 = tif_ds.GetProjection()
spatial_ref2 = osr.SpatialReference()
spatial_ref2.ImportFromWkt(raster_wkt2)
print spatial_ref2.ExportToPrettyWkt()

Return:
GEOGCS["Coordinate System imported from GRIB file", 
DATUM["unknown",SPHEROID["Sphere",6367470,0]],PRIMEM["Greenwich",0],UNIT["degree",0.0174532925199433]]

Help on internet is rare since its within the Python environment. Can anyone 
point me towards a better direction?

Regards, Bram


--
_______________________________________________
gdal-dev mailing list
gdal-dev@lists.osgeo.org
https://lists.osgeo.org/mailman/listinfo/gdal-dev

Reply via email to