1 /*--------------------------------------------------------------------
2  *
3  *	Copyright (c) 1991-2021 by the GMT Team (https://www.generic-mapping-tools.org/team.html)
4  *	See LICENSE.TXT file for copying and redistribution conditions.
5  *
6  *	This program is free software; you can redistribute it and/or modify
7  *	it under the terms of the GNU Lesser General Public License as published by
8  *	the Free Software Foundation; version 3 or any later version.
9  *
10  *	This program is distributed in the hope that it will be useful,
11  *	but WITHOUT ANY WARRANTY; without even the implied warranty of
12  *	MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
13  *	GNU Lesser General Public License for more details.
14  *
15  *	Contact info: www.generic-mapping-tools.org
16  *--------------------------------------------------------------------*/
17 
18 /*!
19  * \file gmt_gdalread.h
20  * \brief Define structures to interface with gdalread|write
21  */
22 
23 #ifndef GMT_GDALREAD_H
24 #define GMT_GDALREAD_H
25 
26 #include <gdal.h>
27 #include <ogr_srs_api.h>
28 #include <cpl_string.h>
29 #include <cpl_conv.h>
30 
31 /*! Structure to control which options are transmitted to gmt_gdalwrite */
32 struct GMT_GDALWRITE_CTRL {
33 	char   *driver;            /* The GDAL diver name */
34 	char   *co_options;        /* The GDAL -co options */
35 	char   *type;              /* Data type */
36 	char   *command;           /* command line */
37 	char   *title;
38 	char   *remark;
39 	unsigned char   *alpha;    /* In case this is used to transmit an image that has a transparency layer */
40 	void   *data;              /* To store the grid/image array */
41 	char    layout[4];         /* A 3 letter code specifying the image memory layout plus a A|a if alpha data in array */
42 	int     orig_type;         /* Original grid data type. Typed as in to match the orig_datatype in GMT_GRID_HEADER */
43 	int     geog;
44 	int     n_columns, n_rows; /* Number of columns & rows of the region to be saved */
45 	int     nXSizeFull;        /* Total number of columns of the data array including padding */
46 	int     n_bands;
47 	int     pad[4];
48 	int     flipud;
49 	int     registration;      /* Registration type. 0 -> grid registration; 1 -> pixel reg */
50 	double	ULx, ULy;          /* x_min & y_max */
51 	double	x_inc, y_inc;      /* Grid/Image increments */
52 	double	nan_value;         /* unlike the nan_value in struct GMT_GRID_HEADER this one is of type double */
53 	struct  GW_C {             /* Color map */
54 		bool   active;
55 		int    n_colors;
56 		float *cpt;
57 	} C;
58 	struct  GW_P {             /* Proj4/WKT string */
59 		bool  active;
60 		char *ProjRefPROJ4;             /* To store a referencing system string in PROJ.4 format */
61 		char *ProjRefWKT;               /* To store a referencing system string in WKT format */
62 		int   ProjRefEPSG;              /* To store a referencing system EPSG code */
63 	} P;
64 	struct  GW_H {             /* To store the GDAL dataset handle */
65 		bool  active;
66 		GDALDatasetH *hSrcDS;
67 	} H;
68 };
69 
70 /*! Structure to control which options are transmitted to gmt_gdalread */
71 struct GMT_GDALREAD_IN_CTRL {
72 	struct GD_B {	/* Band selection */
73 		bool active;
74 		char *bands;
75 	} B;
76 	struct GD_I {	/* Interleaving by pixel (only for char data) */
77 		bool active;
78 	} I;
79 	struct GD_L {	/* Left-Right flip */
80 		bool active;
81 	} L;
82 	struct GD_M {	/* Metadata only */
83 		bool active;
84 	} M;
85 	struct GD_O {	/* Three chars code to specify the array layout in memory */
86 		/* first char T(op)|B(ot), second R(ow)|C(ol), third P(ix)|L(ine)|S(equencial) */
87 		char mem_layout[4];
88 	} O;
89 	struct GD_N {	/* For floats, replace this value by NaN */
90 		float nan_value;
91 	} N;
92 	struct GD_P {	/* Preview mode */
93 		bool active;
94 		char *jump;
95 	} P;
96 	struct GD_p {	/* Pad array in output */
97 		bool active;
98 		unsigned int pad[4];
99 	} p;
100 	struct GD_W {	/* Convert proj4 string into WKT */
101 		bool active;
102 	} W;
103 	struct GD_R {	/* Sub-region in referenced coords */
104 		bool active;
105 		bool periodic;
106 		char *region;
107 	} R;
108 	struct GD_Z {	/* Tell to store data in a complex array */
109 		bool active;
110 		int complex_mode; /* 1|2 if complex array is to hold real (1) and imaginary (2) parts (0 = read as real only) */
111 	} Z;
112 	struct GD_cp {	/* Send in a pointer with allocated chars */
113 		bool active;
114 		unsigned char *grd;
115 	} c_ptr;
116 	struct GD_fp {	/* Send in a pointer with allocated floats */
117 		bool active;
118 		gmt_grdfloat *grd;
119 	} f_ptr;
120 	struct GD_r {	/* Sub-region in row/column coords */
121 		bool active;
122 		char *region;
123 	} r;
124 	struct GD_reg {	/* Registration type. Used only when sending a sub-region request. Than we need to know this */
125 		double x_inc, y_inc;	/* Grid increments */
126 		int val;	/* 0 [default] means grid registration, 1 -> pixel registration */
127 	} registration;
128 	struct GD_hdr {	/* Some fields of the header structure */
129 		bool active;
130 		unsigned int mx, my;
131 		char side[1];		/* If array is going to pasted (grdpaste), tell in what side 'lrtb' */
132 		int offset;
133 	} mini_hdr;
134 	OGRCoordinateTransformationH hCT_fwd;		// TEMP TEMP TEMP. Only to quick try access GDAL coordinates transforms
135 	OGRCoordinateTransformationH hCT_inv;		// TEMP TEMP TEMP. Only to quick try access GDAL coordinates transforms
136 };
137 
138 /*! Structure to hold metadata info in a per bands basis read */
139 struct GDAL_BAND_FNAMES {
140 	char   *DataType;
141 	int     XSize;
142 	int     YSize;
143 	double  nodata;
144 	double  MinMax[2];
145 	double  ScaleOffset[2];
146 };
147 
148 /*! Structure with the output data transmitted by gmt_gdalread */
149 struct GMT_GDALREAD_OUT_CTRL {
150 	/* active is true if the option has been activated */
151 	struct UInt8 {			/* Declare byte pointer */
152 		bool active;
153 		unsigned char *data;
154 	} UInt8;
155 	struct UInt16 {			/* Declare short int pointers */
156 		bool active;
157 		unsigned short int *data;
158 	} UInt16;
159 	struct Int16 {			/* Declare unsigned short int pointers */
160 		bool active;
161 		short int *data;
162 	} Int16;
163 	struct UInt32 {			/* Declare unsigned int pointers */
164 		bool active;
165 		unsigned int *data;
166 	} UInt32;
167 	struct Int32 {			/* Declare int pointers */
168 		bool active;
169 		int *data;
170 	} Int32;
171 	struct Float {			/* Declare float pointers */
172 		bool active;
173 #ifdef DOUBLE_PRECISION_GRID
174 		double *data;
175 #else
176 		float *data;
177 #endif
178 	} Float;
179 	struct Double {			/* Declare double pointers */
180 		bool active;
181 		double *data;
182 	} Double;
183 
184 	double	hdr[9];
185 	double	GeoTransform[6];
186 	double	nodata;
187 	char	*ProjRefPROJ4;
188 	char	*ProjRefWKT;
189 	const char	*DriverShortName;
190 	const char	*DriverLongName;
191 	const char	*color_interp;
192 	int	*ColorMap;
193 	int ProjRefEPSG;
194 	int nIndexedColors; /* Number of colors in a paletted image */
195 	int	RasterXsize;
196 	int	RasterYsize;
197 	int	RasterCount;    /* Total number of bands in file */
198 	int	nActualBands;   /* Number of bands that were actually sent back */
199 	struct Corners {
200 		double LL[2], UL[2], UR[2], LR[2];
201 	} Corners;
202 	struct GEOGCorners {
203 		double LL[2], UL[2], UR[2], LR[2];
204 	} GEOGCorners;
205 
206 	struct GDAL_BAND_FNAMES *band_field_names;
207 };
208 
209 struct OGR_FEATURES {
210 	int     n_rows, n_cols, n_layers;	/* n_rows, n_column, n_layers of the struct array */
211 	int     n_filled;   /* Number of actually filled elements in the matrix */
212 	int     is3D;       /* True when geometries have a z component */
213 	unsigned int np;    /* Number of data points in this feature */
214 	int     att_number; /* Feature's number of attributes */
215 	int     n_islands;	/* Number of islands of a polygon (0 for non-polygon geometries) */
216 	char   *name, *wkt, *proj4;
217 	char   *type;	    /* Geometry type. E.g. Point, Polygon or LineString */
218 	char  **att_names;	/* Names of the attributes of a Feature */
219 	char  **att_values;	/* Values of the attributes of a Feature as strings */
220 	int    *att_types;
221 	int    *islands;	/* Indexes of start&end of main polygon plus its interior rings (i.e. n_islands+1) */
222 	double  BoundingBox[6];
223 	double *BBgeom;     /* Not currently assigned (would be the BoundingBox of each individual geometry) */
224 	double *x, *y, *z;
225 };
226 
227 struct GMT_GDALLIBRARIFIED_CTRL {
228 	char *fname_in;			/* Input file name */
229 	char *fname_out;		/* Output file name */
230 	char *opts;				/* A string with GDAL options in GDAL syntax */
231 	char *dem_method;		/* The method name for gdaldem */
232 	char *dem_cpt;			/* A CPT name to use in gdaldem color-relief method */
233 	struct GD_GL_M {		/* If true, write grid with GMT */
234 		bool write_gdal, read_gdal;
235 	} M;
236 };
237 
238 struct OGRREAD_CTRL {
239 	int    info;            /* If != 0 gmt_ogrread will return only Info (Will it?) */
240 	int    layer;           /* If >= 0 will return only data from that layer. Use negative to return all layers */
241 	char  *name;            /* Vector file name */
242 	double region[6];       /* For when a sub-region is required */
243 };
244 
245 #endif  /* GMT_GDALREAD_H */
246