Opened 16 years ago

Closed 16 years ago

#2546 closed defect (fixed)

SetProjection does not update Datum GeoTiff tags in a specific case

Reported by: vjetly Owned by: warmerdam
Priority: high Milestone: 1.5.3
Component: GDAL_Raster Version: 1.5.2
Severity: normal Keywords: GTiff libgeotiff setprojection
Cc:

Description

In place update of projection using SetProjection() fails to update Datum tags when trying to set the projection to any UTM zone with NAD83 datum in the attached image.

The image already has some 'LOCAL_CS' projection tags. When these tags are not present updating the projection works fine. Also setting the projection to geographic NAD83 works fine but not to UTM NAD83.

Attachments (1)

greene_sub.tif (252.8 KB ) - added by vjetly 16 years ago.
GeoTIFF on which SetProjection() works partially

Download all attachments as: .zip

Change History (5)

by vjetly, 16 years ago

Attachment: greene_sub.tif added

GeoTIFF on which SetProjection() works partially

comment:1 by warmerdam, 16 years ago

Status: newassigned

I have confirmed, testing with this script:

!/usr/bin/env python

import os
import sys
import ogr
import gdal
import gdalnumeric
import osr

os.system('cp safe.tif greene_sub.tif')

db = gdal.Open('greene_sub.tif',gdal.GA_Update)

srs = osr.SpatialReference()
srs.SetFromUserInput('EPSG:2241')
print srs.ExportToPrettyWkt()
db.SetProjection(srs.ExportToWkt())

db = None

The problem is that the input file has an explicit GCS item in the geotiff info:

   Keyed_Information:
      GTModelTypeGeoKey (Short,1): User-Defined
      GTRasterTypeGeoKey (Short,1): RasterPixelIsArea
      GTCitationGeoKey (Ascii,17): "METRE           "
      GeographicTypeGeoKey (Short,1): GCS_WGS_84
      GeogAngularUnitsGeoKey (Short,1): Angular_Degree
      ProjLinearUnitsGeoKey (Short,1): Linear_Meter
      End_Of_Keys.
   End_Of_Geotiff.

But the updated geotiff info does not wipe away unnecessary elements, though it does overwrite those it wishes to update.

   Keyed_Information:
      GTModelTypeGeoKey (Short,1): ModelTypeProjected
      GTRasterTypeGeoKey (Short,1): RasterPixelIsArea
      GTCitationGeoKey (Ascii,26): "NAD83 / Idaho East (ftUS)"
      GeographicTypeGeoKey (Short,1): GCS_WGS_84
      GeogCitationGeoKey (Ascii,6): "NAD83"
      GeogAngularUnitsGeoKey (Short,1): Angular_Degree
      ProjectedCSTypeGeoKey (Short,1): Unknown-2241
      ProjLinearUnitsGeoKey (Short,1): Linear_Foot_US_Survey
      End_Of_Keys.
   End_Of_Geotiff.

The solution, I imagine, is to add some way of actually clearing an existing geotiff info structure rather than just attempting to update it in place.

comment:2 by warmerdam, 16 years ago

Component: PythonBindingsGDAL_Raster
Keywords: GTiff libgeotiff added; python removed

comment:3 by warmerdam, 16 years ago

Milestone: 1.5.3

Unfortunately libgeotiff does not provide a mechanism to create an empty GTIF structure related to a file with existing geotiff info. Also, libtiff does not provide a mechanism to clear an existing tag in a GeoTIFF file.

So, I've taken the approach of reducing the geotiff tags to a minimum set when updating the file (r15293 in trunk). I have also written a test suite entry to verify this correction (r15292).

comment:4 by warmerdam, 16 years ago

Resolution: fixed
Status: assignedclosed

I have migrated the change into the 1.5 branch (r15294).

I believe this problem is now resolved.

Note: See TracTickets for help on using tickets.