OSGeo / libgeotiff

Official repository of the libgeotiff project
180 stars 69 forks source link

Encoded projection using GTIFSetFromProj4 are specified as USER-DEFINED #53

Closed kiliandys closed 2 years ago

kiliandys commented 3 years ago

I am willing to write down geotiff files.

For instance, i'd like to encode the projection info EPSG:25831.

In order to write down the projection in the geotiff, I am using GTIFSetFromProj4(gtif, proj4String).

In order to use this method, I first convert EPSG:25831 to it's proj4 equivalent via the method proj_as_proj_string (proj library)

This convert EPSG:25831 to +proj=utm +zone=32 +datum=WGS84 +units=m +no_defs +type=crs

The encoded information are the following;:

Geotiff_Information:
   Version: 1
   Key_Revision: 1.0
   Tagged_Information:
      ModelTiepointTag (2,3):
         0                 0                 0
         571239.5625       4845679           0
      ModelPixelScaleTag (1,3):
         2                 2                 0
      End_Of_Tags.
   Keyed_Information:
      GTModelTypeGeoKey (Short,1): ModelTypeProjected
      GeographicTypeGeoKey (Short,1): User-Defined
      GeogGeodeticDatumGeoKey (Short,1): User-Defined
      GeogEllipsoidGeoKey (Short,1): Ellipse_GRS_1980
      ProjectedCSTypeGeoKey (Short,1): User-Defined
      ProjectionGeoKey (Short,1): User-Defined
      ProjCoordTransGeoKey (Short,1): CT_TransverseMercator
      ProjLinearUnitsGeoKey (Short,1): Linear_Meter
      ProjNatOriginLongGeoKey (Double,1): 3
      ProjNatOriginLatGeoKey (Double,1): 0
      ProjFalseEastingGeoKey (Double,1): 500000
      ProjFalseNorthingGeoKey (Double,1): 0
      ProjScaleAtNatOriginGeoKey (Double,1): 0.9996
      End_Of_Keys.
   End_Of_Geotiff.

Unfortunately, in QGIS (my version is QGIS 3.6), the detected CRS is a "generated CRS" and not "EPSG:25831".

What I am doing wrong? Most of the time, our user will choose the projection from the EPSG database, so I always have the EPSG code available if needed.

I am using proj7 and libgeotiff 6.0.

kiliandys commented 3 years ago

Does anyone have any ideas? Or maybe I'm not using the right approach?

rouault commented 2 years ago

using PROJ.4 string is lossy. you'd need to set the ProjectedCSTypeGeoKey to 25831. Using GDAL might also simply by avoiding to deal directly with geotiff details

kiliandys commented 2 years ago

Thank you for this answer. I will try to modify ProjectedCSTypeGeoKey.

Unfortunately, we can not use GDAL directly :(

Our user can choose their output projection from a list of projection that we create from proj lib. For instance, they pick EPSG:2154.

Assuming that I have this EPSG:2154 code in hand, what is the best way to encode it in the geotiff file?