No geoKeys generated when writing a geotiff


devsantiago
 

Hello,
I'm sorry if this is question is an easy one, I'm a beginner with rasterio. I have a python script that reads in a dataset, calculates an overlay layer and then outputs the calculated layer. This part works as expected. I then need to take this output geotiff and read it in for display inside a web application. Inside my web application, I need to extract data such as the geotiff's coordinate system , resolution and origin. Currently, I have some other geotiffs that were not generated using rasterio  and I'm able to fetch the needed information by extracting the geoKeys with npm's geotiff package : https://www.npmjs.com/package/geotiff. However, when reading my geotifffs generated with rasterio, no geoKeys are found. Below you can find my code used to open the existing dataset and the open and create options I'm using. I'm wondering if there is something that I'm missing to be able to correctly generate these geoKeys. Any help will be greatly appreciated!

 

def layers(directory, gis_data, maptype, mapname):
    h = gis_data.height
    w = gis_data.width
    c = gis_data.crs
    t = gis_data.transform
    output_folder = directory + 'output'
    
    if not os.path.exists(output_folder):
        os.makedirs(output_folder)
    
    mapname = rio.open(
        output_folder + '/' + mapname + '.tiff',
        'w',
        driver = 'GTiff',
        height = h,
        width = w,
        count = 1,
        dtype = np.uint8,
        crs = c,
        transform = t,
profile='GeoTIFF',
geotiff_keys_flavour='STANDARD',
georef_sources='INTERNAL', ) mapname.write(maptype, 1) mapname.close()


Sean Gillies
 

Hi,

On Tue, Jul 6, 2021 at 10:23 AM devsantiago <santiago@...> wrote:

Hello,
I'm sorry if this is question is an easy one, I'm a beginner with rasterio. I have a python script that reads in a dataset, calculates an overlay layer and then outputs the calculated layer. This part works as expected. I then need to take this output geotiff and read it in for display inside a web application. Inside my web application, I need to extract data such as the geotiff's coordinate system , resolution and origin. Currently, I have some other geotiffs that were not generated using rasterio  and I'm able to fetch the needed information by extracting the geoKeys with npm's geotiff package : https://www.npmjs.com/package/geotiff. However, when reading my geotifffs generated with rasterio, no geoKeys are found. Below you can find my code used to open the existing dataset and the open and create options I'm using. I'm wondering if there is something that I'm missing to be able to correctly generate these geoKeys. Any help will be greatly appreciated!

 

def layers(directory, gis_data, maptype, mapname):
    h = gis_data.height
    w = gis_data.width
    c = gis_data.crs
    t = gis_data.transform
    output_folder = directory + 'output'
    
    if not os.path.exists(output_folder):
        os.makedirs(output_folder)
    
    mapname = rio.open(
        output_folder + '/' + mapname + '.tiff',
        'w',
        driver = 'GTiff',
        height = h,
        width = w,
        count = 1,
        dtype = np.uint8,
        crs = c,
        transform = t,
profile='GeoTIFF',
geotiff_keys_flavour='STANDARD',
georef_sources='INTERNAL', ) mapname.write(maptype, 1) mapname.close()

Can you try with 

    geotiff_keys_flavor='STANDARD'

and see what happens? According to https://gdal.org/drivers/raster/gtiff.html#creation-options there is no "u" in the option name.

--
Sean Gillies


devsantiago
 

Hi Sean, 

Thanks for your quick answer and for noting this, i had indeed a typo. However, this did not solve my problem. Am I missing something else ? There is not much info in the documentation and I feel like I included everything needed.


Sean Gillies
 

Hi,

Right, the typo wouldn't make a difference since "STANDARD" is already the GDAL GeoTIFF default.

At https://github.com/geotiffjs/geotiff.js I see "Rudimentary extraction of geospatial metadata". Perhaps the package isn't complete in this area? I didn't immediately see tests of reading geotiff keys.

On Thu, Jul 8, 2021 at 10:34 AM devsantiago <santiago@...> wrote:

Hi Sean, 

Thanks for your quick answer and for noting this, i had indeed a typo. However, this did not solve my problem. Am I missing something else ? There is not much info in the documentation and I feel like I included everything needed.

._,_._,

--
Sean Gillies


devsantiago
 

Could be, but i doubt it. The other geotiffs I'm able to successfully read (geoKeys) and display inside the web application (using npm's geotiff package) are generated using professional GIS software. Further question, in my full script, there are other places (not shown in sample code) where a dataset is open with rasterio and some information is read to calculate the overlay. Could it be that the geotiffs that i'm using to generate my output image don't have any information encoded, which would explain why nothing is passed to my output image? Also, is there some sample code somewhere using rasterio to generate a geotiff (and its geoKeys) that I could look at ?


Sean Gillies
 

Hi,

On Mon, Jul 12, 2021 at 7:36 AM devsantiago <santiago@...> wrote:
Could be, but i doubt it. The other geotiffs I'm able to successfully read (geoKeys) and display inside the web application (using npm's geotiff package) are generated using professional GIS software. Further question, in my full script, there are other places (not shown in sample code) where a dataset is open with rasterio and some information is read to calculate the overlay. Could it be that the geotiffs that i'm using to generate my output image don't have any information encoded, which would explain why nothing is passed to my output image? Also, is there some sample code somewhere using rasterio to generate a geotiff (and its geoKeys) that I could look at ?
,_._,_

I'm stumped. Rasterio doesn't have any native understanding of GeoTIFF geokeys. To define a dataset's georeferencing, we call GDALSetGeoTransform and GDALSetProjection and GDAL's GeoTIFF driver and libgeotiff take care of the details. We haven't had a report of rasterio (and GDAL) writing a non-conforming GeoTIFF in a long time. The tutorial at https://rasterio.readthedocs.io/en/latest/quickstart.html#opening-a-dataset-in-writing-mode produces a GeoTIFF that can be used with GDAL and QGIS. Can you tell me what rasterio version you are using and what its provenance is? PyPI? Anaconda? Something else?

--
Sean Gillies


devsantiago
 

Hi,

We are currently using rasterio version 1.1.8 and it was installed following this procedure : https://rasterio.readthedocs.io/en/latest/installation.html#installing-with-anaconda