matafokka/geotiff-geokeys-to-proj4

Error in data in `ProjectionGeoKey.js`

Closed this issue · 6 comments

​My geotiff file has the following (somewhat mysterious) geoKeys:

GTCitationGeoKey: "UTM Zone 32, Northern Hemisphere"
​GTModelTypeGeoKey: 1
​GTRasterTypeGeoKey: 1
GeogAngularUnitsGeoKey: 9102
​GeogCitationGeoKey: "GCS Name = GRS 1980(IUGG, 1980)|Datum = unknown|Ellipsoid = GRS80|Primem = Greenwich|"
​GeogEllipsoidGeoKey: 32767
​GeogGeodeticDatumGeoKey: 32767
​GeogInvFlatteningGeoKey: 298.257222101
​GeogPrimeMeridianLongGeoKey: 0
​GeogSemiMajorAxisGeoKey: 6378137
​GeogTOWGS84GeoKey: [ 0, 0, 0 ]
​GeographicTypeGeoKey: 32767
​ProjLinearUnitsGeoKey: 9001
​ProjectedCSTypeGeoKey: 32767
​ProjectionGeoKey: 16032

which convertGeoKeys2proj4 converts to this string:

+proj=tmerc +lat_0=0 +lon_0=0.1570796326794895 +k_0=0.9996 +x_0=500000 +y_0=0 +a=6378137 +b=6356752.314140356 +towgs84=0,0,0, +no_defs 

This is not quite right - the lon_0 value should be 9, as listgeo lists the tiff file as follows:

eotiff_Information:
   Version: 1
   Key_Revision: 1.0
   Tagged_Information:
      ModelTiepointTag (2,3):
         0                 0                 0                
         554006.599009888  6301417.47768047  0                
      ModelPixelScaleTag (1,3):
         0.356706451650175 0.356706451650175 0                
      End_Of_Tags.
   Keyed_Information:
      GTModelTypeGeoKey (Short,1): ModelTypeProjected
      GTRasterTypeGeoKey (Short,1): RasterPixelIsArea
      GTCitationGeoKey (Ascii,33): "UTM Zone 32, Northern Hemisphere"
      GeographicTypeGeoKey (Short,1): User-Defined
      GeogCitationGeoKey (Ascii,86): "GCS Name = GRS 1980(IUGG, 1980)|Datum = unknown|Ellipsoid = GRS80|Primem = Greenwich|"
      GeogGeodeticDatumGeoKey (Short,1): User-Defined
      GeogAngularUnitsGeoKey (Short,1): Angular_Degree
      GeogEllipsoidGeoKey (Short,1): User-Defined
      GeogSemiMajorAxisGeoKey (Double,1): 6378137          
      GeogInvFlatteningGeoKey (Double,1): 298.257222101    
      GeogPrimeMeridianLongGeoKey (Double,1): 0                
      GeogTOWGS84GeoKey (Double,3): 0                0                0                
      ProjectedCSTypeGeoKey (Short,1): User-Defined
      ProjectionGeoKey (Short,1): Proj_UTM_zone_32N
      ProjLinearUnitsGeoKey (Short,1): Linear_Meter
      End_Of_Keys.
   End_Of_Geotiff.

Projection = 16032 (UTM zone 32N)
Projection Method: CT_TransverseMercator
   ProjNatOriginLatGeoKey: 0.000000 (  0d 0' 0.00"N)
   ProjNatOriginLongGeoKey: 9.000000 (  9d 0' 0.00"E)
   ProjScaleAtNatOriginGeoKey: 0.999600
   ProjFalseEastingGeoKey: 500000.000000 m
   ProjFalseNorthingGeoKey: 0.000000 m
TOWGS84: 0,0,0
Projection Linear Units: 9001/metre (1.000000m)

The problem seems to be in data preparation, because the string for 16032 in ProjectionGeoKey.js has the wrong value. On http://epsg.io/16032.gml, the latitude is 9. The problem seems simply a mixup between degrees and radians: 0.1570796326794895 is 9 degrees in radians.

Hello again, thanks for the report, I really appreciate the effort!

I've got a lot going on lately, so it'll take some time for me to look into this issue, sorry :)

Looks like it's fixed. It passes my tests with geokeys from this issue, but I'm a bit unsure if I've covered everything while refactoring.

If you have a larger dataset, may I ask you to extract geokeys and whatever Proj4 strings GDAL outputs, and send it to me?

The library now returns this proj4 string for my geokeys:

+proj=tmerc +lat_0=0 +lon_0=8.999999999999991 +k_0=0.9996 +x_0=500000 +y_0=0 +a=6378137 +b=6356752.314140356 +towgs84=0,0,0, +no_defs

It turns out that openlayers cannot correctly parse this. The problem is the +towgs84=0,0,0, part. If I change it to +towgs84=0,0,0 (that is, remove the final comma), then it works correctly.

Also, somehow when preparing the data you are changing the 9 degrees in the specification into 8.999999999999991 degrees. It would be nicer if you could round to 12 digits or something like that, so that the degrees would exactly match the specification.

Thanks, fixed it! Also good point regarding the numbers, done the rounding at the end of string processing to not mess up everything.

An updated version should already be in npm :)

Thanks, I can confirm that now it works!

Thanks, been a pleasure working with you!