[Geotiff] Re: consultation

Frank Warmerdam warmerdam at pobox.com
Thu Jul 12 09:26:18 EDT 2007


gis.xznu wrote:
>  
>  
>  
> Hello, I would like to know that how to use the libgeotiff library and 
> how to achieve geotiff format reading and writing operations in visual 
> basic(vc++) platform , I hope you can give me some help or make the 
> project examples, thank you,

Xznu,

Are you already familiar with using libtiff?

The libgeotiff/bin/listgeo.c program shows a partial example
of using libgeotiff, which I abbreviate here:

     /*
      * Open the file, read the GeoTIFF information, and print to stdout.
      */

     tif=XTIFFOpen(fname,"r");
     if (!tif) goto failure;
	
     gtif = GTIFNew(tif);
     if (!gtif)
     {
         fprintf(stderr,"failed in GTIFNew\n");
         goto failure;
     }

     if( tfw_flag )
     {
         WriteTFWFile( gtif, fname );

         goto Success;
     }
	
     /* dump the GeoTIFF metadata to std out */

     GTIFPrint(gtif,0,0);
     GTIFFree(gtif);
     XTIFFClose(tif);

In this case the Geotiff definition is just printed to the
screen using GTIFPrint().  If you want to pull out detailed
definitions you can do so one of two ways.

One is to call GTIFGetDefn() (see listgeo.c) and then pull
values of interest out of the resulting structure.  The
structure looks like this:

typedef struct {
     /** From GTModelTypeGeoKey tag.  Can have the values ModelTypeGeographic
         or ModelTypeProjected. */
     short	Model;

     /** From ProjectedCSTypeGeoKey tag.  For example PCS_NAD27_UTM_zone_3N.*/
     short	PCS;

     /** From GeographicTypeGeoKey tag.  For example GCS_WGS_84 or
         GCS_Voirol_1875_Paris.  Includes datum and prime meridian value. */
     short	GCS;	

     /** From ProjLinearUnitsGeoKey.  For example Linear_Meter. */
     short	UOMLength;

     /** One UOMLength = UOMLengthInMeters meters. */
     double	UOMLengthInMeters;

     /** The angular units of the GCS. */
     short       UOMAngle;

     /** One UOMAngle = UOMLengthInDegrees degrees. */
     double      UOMAngleInDegrees;

     /** Datum from GeogGeodeticDatumGeoKey tag. For example Datum_WGS84 */
     short	Datum;

     /** Prime meridian from GeogPrimeMeridianGeoKey.  For example PM_Greenwich
         or PM_Paris. */
     short	PM;

     /** Decimal degrees of longitude between this prime meridian and
         Greenwich.  Prime meridians to the west of Greenwich are negative. */
     double	PMLongToGreenwich;

     /** Ellipsoid identifier from GeogELlipsoidGeoKey.  For example
         Ellipse_Clarke_1866. */
     short	Ellipsoid;

     /** The length of the semi major ellipse axis in meters. */
     double	SemiMajor;

     /** The length of the semi minor ellipse axis in meters. */
     double	SemiMinor;

     /** Projection id from ProjectionGeoKey.  For example Proj_UTM_11S. */
     short	ProjCode;

     /** EPSG identifier for underlying projection method.  From the EPSG
         TRF_METHOD table.  */
     short	Projection;

     /** GeoTIFF identifier for underlying projection method.  While some of
       these values have corresponding vlaues in EPSG (Projection field),
       others do not.  For example CT_TransverseMercator. */
     short	CTProjection;

     /** Number of projection parameters in ProjParm and ProjParmId. */
     int		nParms;

     /** Projection parameter value.  The identify of this parameter
         is established from the corresponding entry in ProjParmId.  The
         value will be measured in meters, or decimal degrees if it is a
         linear or angular measure. */
     double	ProjParm[MAX_GTIF_PROJPARMS];

     /** Projection parameter identifier.  For example ProjFalseEastingGeoKey.
         The value will be 0 for unused table entries. */
     int		ProjParmId[MAX_GTIF_PROJPARMS]; /* geokey identifier,
                                                    eg. ProjFalseEastingGeoKey*/

     /** Special zone map system code (MapSys_UTM_South, MapSys_UTM_North,
         MapSys_State_Plane or KvUserDefined if none apply. */
     int		MapSys;

     /** UTM, or State Plane Zone number, zero if not known. */
     int		Zone;

} GTIFDefn;

The other is to call GTIFKeyGet() on individual geokeys.

The API documentation is available at:

   http://geotiff.maptools.org/api/index.html

A fairly complex example of using libgeotiff (mixed with lots
of other stuff) is available at:

   http://trac.osgeo.org/gdal/browser/trunk/gdal/frmts/gtiff/gt_wkt_srs.cpp

Lastly, the geotiff at lists.maptools.org mailing list is the
appropriate place to ask questions about geotiff and libgeotiff.
I'd encourage you to subscribe.  Details on the geotiff web page
of course.

   http://geotiff.maptools.org/

Good luck,
-- 
---------------------------------------+--------------------------------------
I set the clouds in motion - turn up   | Frank Warmerdam, warmerdam at pobox.com
light and sound - activate the windows | http://pobox.com/~warmerdam
and watch the world go round - Rush    | President OSGeo, http://osgeo.org



More information about the Geotiff mailing list