Re: Writing ESRI sidecar files

Sean Gillies


On Fri, Jun 28, 2019 at 10:00 AM James David Smith <james.david.smith@...> wrote:
Thanks again Sean, and Evan too. It seems I just need to get the right
combination of options.

The options that you have shown Even are they implemented?
They don't seem to go in the Env like the other options?

Correct, those dataset creation options need to be passed into

One way to do that is to add to your metadata dict below

  metadata["profile"] = "GeoTIFF"

Any extra keyword argument passed to is collected into a kwargs dict (see and items of that dict are turned into GDAL dataset creation options (by uppercasing the keyword argument names and converting their values appropriately).

My code at the moment as follows. It create the .tif and .ovr file .
If anyone can improve it, and help me get the aux.xml file too I'd be
very grateful. I need the ovr and aux.xml files to be created
independently as it's what the client needs.
import rasterio

with"meri50year.tif") as file:
    data               =
    metadata           = file.profile
    metadata['nodata'] = 255
    data[data == 1 ]   = 4
    data[data == 15 ]  = 255

outfile = 'meri50_processed.tif'

with rasterio.Env(GDAL_PAM_ENABLED=True, ESRI_XML_PAM=True, TIFF_USE_OVR=True):
    with, 'w', **metadata) as new_temp_file:
        new_temp_file.write(data, 1)
        overviews = [2,4,8,16]
        new_temp_file.build_overviews(overviews, Resampling.nearest)

On Fri, 28 Jun 2019 at 16:09, Even Rouault <even.rouault@...> wrote:
> On vendredi 28 juin 2019 08:26:35 CEST Sean Gillies wrote:
> > If you are creating a GeoTIFF it is possible that no XML file will be
> > written. As Even Rouault explains in
> >, the PAM
> > file is only created if needed.
> Indeed. You can play with the GTIFF specific PROFILE creation option
> (see
> PROFILE=BASELINE: .aux.xml only created if presence of georeferencing and/or
> user metadata
> PROFILE=GEOTIFF: .aux.xml only created if there's user metadata
> PROFILE=GDALGeoTIFF: .aux.xml only created if user metadata doesn't fit in
> TIFF tag
> Even
> --
> Spatialys - Geospatial professional services

Sean Gillies

Join to automatically receive all group messages.