"Fossies" - the Fresh Open Source Software Archive

Member "libgeotiff-1.6.0/bin/makegeo.c" (15 Jun 2019, 2677 Bytes) of package /linux/privat/libgeotiff-1.6.0.tar.gz:


As a special service "Fossies" has tried to format the requested source page into HTML format using (guessed) C and C++ source code syntax highlighting (style: standard) with prefixed line numbers and code folding option. Alternatively you can here view or download the uninterpreted source code file. For more information about "makegeo.c" see the Fossies "Dox" file reference documentation and the latest Fossies "Diffs" side-by-side code changes report: 1.5.1_vs_1.6.0.

    1 /*
    2  * makegeo.c -- example client code for LIBGEO geographic
    3  *     TIFF tag support.
    4  *
    5  *  Author: Niles D. Ritter
    6  *
    7  * Revision History:
    8  *   31 October, 1995    Fixed reversed lat-long coordinates   NDR
    9  *
   10  */
   11 
   12 #include "geotiffio.h"
   13 #include "xtiffio.h"
   14 #include <stdlib.h>
   15 #include <string.h>
   16 
   17 void SetUpTIFFDirectory(TIFF *tif);
   18 void SetUpGeoKeys(GTIF *gtif);
   19 void WriteImage(TIFF *tif);
   20 
   21 #define WIDTH 20L
   22 #define HEIGHT 20L
   23 
   24 int main()
   25 {
   26     char *fname = "newgeo.tif";
   27     TIFF *tif;  /* TIFF-level descriptor */
   28     GTIF *gtif = NULL; /* GeoKey-level descriptor */
   29     
   30     tif=XTIFFOpen(fname,"w");
   31     if (!tif) goto failure;
   32     
   33     gtif = GTIFNew(tif);
   34     if (!gtif)
   35     {
   36         printf("failed in GTIFNew\n");
   37         goto failure;
   38     }
   39     
   40     SetUpTIFFDirectory(tif);
   41     SetUpGeoKeys(gtif);
   42     WriteImage(tif);
   43     
   44     GTIFWriteKeys(gtif);
   45     GTIFFree(gtif);
   46     XTIFFClose(tif);
   47     return 0;
   48     
   49 failure:
   50     printf("failure in makegeo\n");
   51     if (tif) TIFFClose(tif);
   52     if (gtif) GTIFFree(gtif);
   53     return -1;
   54 }
   55 
   56 
   57 void SetUpTIFFDirectory(TIFF *tif)
   58 {
   59     double tiepoints[6]={0,0,0,130.0,32.0,0.0};
   60     double pixscale[3]={1,1,0};
   61     
   62     TIFFSetField(tif,TIFFTAG_IMAGEWIDTH,    WIDTH);
   63     TIFFSetField(tif,TIFFTAG_IMAGELENGTH,   HEIGHT);
   64     TIFFSetField(tif,TIFFTAG_COMPRESSION,   COMPRESSION_NONE);
   65     TIFFSetField(tif,TIFFTAG_PHOTOMETRIC,   PHOTOMETRIC_MINISBLACK);
   66     TIFFSetField(tif,TIFFTAG_PLANARCONFIG,  PLANARCONFIG_CONTIG);
   67     TIFFSetField(tif,TIFFTAG_BITSPERSAMPLE, 8);
   68     TIFFSetField(tif,TIFFTAG_ROWSPERSTRIP,  20L);
   69     
   70     TIFFSetField(tif,TIFFTAG_GEOTIEPOINTS, 6,tiepoints);
   71     TIFFSetField(tif,TIFFTAG_GEOPIXELSCALE, 3,pixscale);
   72 }
   73 
   74 void SetUpGeoKeys(GTIF *gtif)
   75 {
   76     GTIFKeySet(gtif, GTModelTypeGeoKey, TYPE_SHORT, 1, ModelGeographic);
   77     GTIFKeySet(gtif, GTRasterTypeGeoKey, TYPE_SHORT, 1, RasterPixelIsArea);
   78     GTIFKeySet(gtif, GTCitationGeoKey, TYPE_ASCII, 0, "Just An Example");
   79     GTIFKeySet(gtif, GeographicTypeGeoKey, TYPE_SHORT,  1, KvUserDefined);
   80     GTIFKeySet(gtif, GeogCitationGeoKey, TYPE_ASCII, 0, "Everest Ellipsoid Used.");
   81     GTIFKeySet(gtif, GeogAngularUnitsGeoKey, TYPE_SHORT,  1, Angular_Degree);
   82     GTIFKeySet(gtif, GeogLinearUnitsGeoKey, TYPE_SHORT,  1, Linear_Meter);
   83     GTIFKeySet(gtif, GeogGeodeticDatumGeoKey, TYPE_SHORT,     1, KvUserDefined);
   84     GTIFKeySet(gtif, GeogEllipsoidGeoKey, TYPE_SHORT,     1, Ellipse_Everest_1830_1967_Definition);
   85     GTIFKeySet(gtif, GeogSemiMajorAxisGeoKey, TYPE_DOUBLE, 1, (double)6377298.556);
   86     GTIFKeySet(gtif, GeogInvFlatteningGeoKey, TYPE_DOUBLE, 1, (double)300.8017);
   87 }
   88 
   89 void WriteImage(TIFF *tif)
   90 {
   91     int i;
   92     char buffer[WIDTH];
   93     
   94     memset(buffer,0,(size_t)WIDTH);
   95     for (i=0;i<HEIGHT;i++)
   96         if (!TIFFWriteScanline(tif, buffer, i, 0))
   97             TIFFError("WriteImage","failure in WriteScanline\n");
   98 }
   99 
  100 
  101 
  102