1 /******************************************************************************
2  * $Id: gdal_alg.h 27850 2014-10-12 16:58:09Z rouault $
3  *
4  * Project:  GDAL Image Processing Algorithms
5  * Purpose:  Prototypes, and definitions for various GDAL based algorithms.
6  * Author:   Frank Warmerdam, warmerdam@pobox.com
7  *
8  ******************************************************************************
9  * Copyright (c) 2001, Frank Warmerdam
10  * Copyright (c) 2008-2012, Even Rouault <even dot rouault at mines-paris dot org>
11  *
12  * Permission is hereby granted, free of charge, to any person obtaining a
13  * copy of this software and associated documentation files (the "Software"),
14  * to deal in the Software without restriction, including without limitation
15  * the rights to use, copy, modify, merge, publish, distribute, sublicense,
16  * and/or sell copies of the Software, and to permit persons to whom the
17  * Software is furnished to do so, subject to the following conditions:
18  *
19  * The above copyright notice and this permission notice shall be included
20  * in all copies or substantial portions of the Software.
21  *
22  * THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS
23  * OR IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
24  * FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL
25  * THE AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER
26  * LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING
27  * FROM, OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER
28  * DEALINGS IN THE SOFTWARE.
29  ****************************************************************************/
30 
31 #ifndef GDAL_ALG_H_INCLUDED
32 #define GDAL_ALG_H_INCLUDED
33 
34 /**
35  * \file gdal_alg.h
36  *
37  * Public (C callable) GDAL algorithm entry points, and definitions.
38  */
39 
40 #ifndef DOXYGEN_SKIP
41 #include "gdal.h"
42 #include "cpl_minixml.h"
43 #include "ogr_api.h"
44 #endif
45 
46 CPL_C_START
47 
48 int CPL_DLL CPL_STDCALL GDALComputeMedianCutPCT( GDALRasterBandH hRed,
49                              GDALRasterBandH hGreen,
50                              GDALRasterBandH hBlue,
51                              int (*pfnIncludePixel)(int,int,void*),
52                              int nColors,
53                              GDALColorTableH hColorTable,
54                              GDALProgressFunc pfnProgress,
55                              void * pProgressArg );
56 
57 int CPL_DLL CPL_STDCALL GDALDitherRGB2PCT( GDALRasterBandH hRed,
58                        GDALRasterBandH hGreen,
59                        GDALRasterBandH hBlue,
60                        GDALRasterBandH hTarget,
61                        GDALColorTableH hColorTable,
62                        GDALProgressFunc pfnProgress,
63                        void * pProgressArg );
64 
65 int CPL_DLL CPL_STDCALL GDALChecksumImage( GDALRasterBandH hBand,
66                                int nXOff, int nYOff, int nXSize, int nYSize );
67 
68 CPLErr CPL_DLL CPL_STDCALL
69 GDALComputeProximity( GDALRasterBandH hSrcBand,
70                       GDALRasterBandH hProximityBand,
71                       char **papszOptions,
72                       GDALProgressFunc pfnProgress,
73                       void * pProgressArg );
74 
75 CPLErr CPL_DLL CPL_STDCALL
76 GDALFillNodata( GDALRasterBandH hTargetBand,
77                 GDALRasterBandH hMaskBand,
78                 double dfMaxSearchDist,
79                 int bDeprecatedOption,
80                 int nSmoothingIterations,
81                 char **papszOptions,
82                 GDALProgressFunc pfnProgress,
83                 void * pProgressArg );
84 
85 CPLErr CPL_DLL CPL_STDCALL
86 GDALPolygonize( GDALRasterBandH hSrcBand,
87                 GDALRasterBandH hMaskBand,
88                 OGRLayerH hOutLayer, int iPixValField,
89                 char **papszOptions,
90                 GDALProgressFunc pfnProgress,
91                 void * pProgressArg );
92 
93 CPLErr CPL_DLL CPL_STDCALL
94 GDALFPolygonize( GDALRasterBandH hSrcBand,
95                 GDALRasterBandH hMaskBand,
96                 OGRLayerH hOutLayer, int iPixValField,
97                 char **papszOptions,
98                 GDALProgressFunc pfnProgress,
99                 void * pProgressArg );
100 
101 CPLErr CPL_DLL CPL_STDCALL
102 GDALSieveFilter( GDALRasterBandH hSrcBand, GDALRasterBandH hMaskBand,
103                  GDALRasterBandH hDstBand,
104                  int nSizeThreshold, int nConnectedness,
105                  char **papszOptions,
106                  GDALProgressFunc pfnProgress,
107                  void * pProgressArg );
108 
109 /*
110  * Warp Related.
111  */
112 
113 typedef int
114 (*GDALTransformerFunc)( void *pTransformerArg,
115                         int bDstToSrc, int nPointCount,
116                         double *x, double *y, double *z, int *panSuccess );
117 
118 #define GDAL_GTI2_SIGNATURE     "GTI2"
119 
120 typedef struct {
121     GByte abySignature[4];
122     const char *pszClassName;
123     GDALTransformerFunc pfnTransform;
124     void (*pfnCleanup)( void * pTransformerArg );
125     CPLXMLNode *(*pfnSerialize)( void * pTransformerArg );
126     void* (*pfnCreateSimilar)( void* pTransformerArg, double dfSrcRatioX, double dfSrcRatioY );
127 } GDALTransformerInfo;
128 
129 void CPL_DLL GDALDestroyTransformer( void *pTransformerArg );
130 int  CPL_DLL GDALUseTransformer( void *pTranformerArg,
131                                  int bDstToSrc, int nPointCount,
132                                  double *x, double *y, double *z,
133                                  int *panSuccess );
134 void* GDALCreateSimilarTransformer( void* psTransformerArg, double dfSrcRatioX, double dfSrcRatioY );
135 
136 
137 /* High level transformer for going from image coordinates on one file
138    to image coordiantes on another, potentially doing reprojection,
139    utilizing GCPs or using the geotransform. */
140 
141 void CPL_DLL *
142 GDALCreateGenImgProjTransformer( GDALDatasetH hSrcDS, const char *pszSrcWKT,
143                                  GDALDatasetH hDstDS, const char *pszDstWKT,
144                                  int bGCPUseOK, double dfGCPErrorThreshold,
145                                  int nOrder );
146 void CPL_DLL *
147 GDALCreateGenImgProjTransformer2( GDALDatasetH hSrcDS, GDALDatasetH hDstDS,
148                                   char **papszOptions );
149 void CPL_DLL *
150 GDALCreateGenImgProjTransformer3( const char *pszSrcWKT,
151                                   const double *padfSrcGeoTransform,
152                                   const char *pszDstWKT,
153                                   const double *padfDstGeoTransform );
154 void CPL_DLL GDALSetGenImgProjTransformerDstGeoTransform( void *,
155                                                           const double * );
156 void CPL_DLL GDALDestroyGenImgProjTransformer( void * );
157 int CPL_DLL GDALGenImgProjTransform(
158     void *pTransformArg, int bDstToSrc, int nPointCount,
159     double *x, double *y, double *z, int *panSuccess );
160 
161 void GDALSetTransformerDstGeoTransform( void *, const double * );
162 
163 /* Geo to geo reprojection transformer. */
164 void CPL_DLL *
165 GDALCreateReprojectionTransformer( const char *pszSrcWKT,
166                                    const char *pszDstWKT );
167 void CPL_DLL GDALDestroyReprojectionTransformer( void * );
168 int CPL_DLL GDALReprojectionTransform(
169     void *pTransformArg, int bDstToSrc, int nPointCount,
170     double *x, double *y, double *z, int *panSuccess );
171 
172 /* GCP based transformer ... forward is to georef coordinates */
173 void CPL_DLL *
174 GDALCreateGCPTransformer( int nGCPCount, const GDAL_GCP *pasGCPList,
175                           int nReqOrder, int bReversed );
176 
177 /* GCP based transformer with refinement of the GCPs ... forward is to georef coordinates */
178 void CPL_DLL *
179 GDALCreateGCPRefineTransformer( int nGCPCount, const GDAL_GCP *pasGCPList,
180                                 int nReqOrder, int bReversed, double tolerance, int minimumGcps);
181 
182 void CPL_DLL GDALDestroyGCPTransformer( void *pTransformArg );
183 int CPL_DLL GDALGCPTransform(
184     void *pTransformArg, int bDstToSrc, int nPointCount,
185     double *x, double *y, double *z, int *panSuccess );
186 
187 /* Thin Plate Spine transformer ... forward is to georef coordinates */
188 
189 void CPL_DLL *
190 GDALCreateTPSTransformer( int nGCPCount, const GDAL_GCP *pasGCPList,
191                           int bReversed );
192 void CPL_DLL GDALDestroyTPSTransformer( void *pTransformArg );
193 int CPL_DLL GDALTPSTransform(
194     void *pTransformArg, int bDstToSrc, int nPointCount,
195     double *x, double *y, double *z, int *panSuccess );
196 
197 char CPL_DLL ** RPCInfoToMD( GDALRPCInfo *psRPCInfo );
198 
199 /* RPC based transformer ... src is pixel/line/elev, dst is long/lat/elev */
200 
201 void CPL_DLL *
202 GDALCreateRPCTransformer( GDALRPCInfo *psRPC, int bReversed,
203                           double dfPixErrThreshold,
204                           char **papszOptions );
205 void CPL_DLL GDALDestroyRPCTransformer( void *pTransformArg );
206 int CPL_DLL GDALRPCTransform(
207     void *pTransformArg, int bDstToSrc, int nPointCount,
208     double *x, double *y, double *z, int *panSuccess );
209 
210 /* Geolocation transformer */
211 
212 void CPL_DLL *
213 GDALCreateGeoLocTransformer( GDALDatasetH hBaseDS,
214                              char **papszGeolocationInfo,
215                              int bReversed );
216 void CPL_DLL GDALDestroyGeoLocTransformer( void *pTransformArg );
217 int CPL_DLL GDALGeoLocTransform(
218     void *pTransformArg, int bDstToSrc, int nPointCount,
219     double *x, double *y, double *z, int *panSuccess );
220 
221 /* Approximate transformer */
222 void CPL_DLL *
223 GDALCreateApproxTransformer( GDALTransformerFunc pfnRawTransformer,
224                              void *pRawTransformerArg, double dfMaxError );
225 void CPL_DLL GDALApproxTransformerOwnsSubtransformer( void *pCBData,
226                                                       int bOwnFlag );
227 void CPL_DLL GDALDestroyApproxTransformer( void *pApproxArg );
228 int  CPL_DLL GDALApproxTransform(
229     void *pTransformArg, int bDstToSrc, int nPointCount,
230     double *x, double *y, double *z, int *panSuccess );
231 
232 
233 
234 
235 int CPL_DLL CPL_STDCALL
236 GDALSimpleImageWarp( GDALDatasetH hSrcDS,
237                      GDALDatasetH hDstDS,
238                      int nBandCount, int *panBandList,
239                      GDALTransformerFunc pfnTransform,
240                      void *pTransformArg,
241                      GDALProgressFunc pfnProgress,
242                      void *pProgressArg,
243                      char **papszWarpOptions );
244 
245 CPLErr CPL_DLL CPL_STDCALL
246 GDALSuggestedWarpOutput( GDALDatasetH hSrcDS,
247                          GDALTransformerFunc pfnTransformer,
248                          void *pTransformArg,
249                          double *padfGeoTransformOut,
250                          int *pnPixels, int *pnLines );
251 CPLErr CPL_DLL CPL_STDCALL
252 GDALSuggestedWarpOutput2( GDALDatasetH hSrcDS,
253                           GDALTransformerFunc pfnTransformer,
254                           void *pTransformArg,
255                           double *padfGeoTransformOut,
256                           int *pnPixels, int *pnLines,
257                           double *padfExtents,
258                           int nOptions );
259 
260 CPLXMLNode CPL_DLL *
261 GDALSerializeTransformer( GDALTransformerFunc pfnFunc, void *pTransformArg );
262 CPLErr CPL_DLL GDALDeserializeTransformer( CPLXMLNode *psTree,
263                                            GDALTransformerFunc *ppfnFunc,
264                                            void **ppTransformArg );
265 
266 CPLErr CPL_DLL
267 GDALTransformGeolocations( GDALRasterBandH hXBand,
268                            GDALRasterBandH hYBand,
269                            GDALRasterBandH hZBand,
270                            GDALTransformerFunc pfnTransformer,
271                            void *pTransformArg,
272                            GDALProgressFunc pfnProgress,
273                            void *pProgressArg,
274                            char **papszOptions );
275 
276 /* -------------------------------------------------------------------- */
277 /*      Contour Line Generation                                         */
278 /* -------------------------------------------------------------------- */
279 
280 typedef CPLErr (*GDALContourWriter)( double dfLevel, int nPoints,
281                                      double *padfX, double *padfY, void * );
282 
283 typedef void *GDALContourGeneratorH;
284 
285 GDALContourGeneratorH CPL_DLL
286 GDAL_CG_Create( int nWidth, int nHeight,
287                 int bNoDataSet, double dfNoDataValue,
288                 double dfContourInterval, double dfContourBase,
289                 GDALContourWriter pfnWriter, void *pCBData );
290 CPLErr CPL_DLL GDAL_CG_FeedLine( GDALContourGeneratorH hCG,
291                                  double *padfScanline );
292 void CPL_DLL GDAL_CG_Destroy( GDALContourGeneratorH hCG );
293 
294 typedef struct
295 {
296     void   *hLayer;
297 
298     double adfGeoTransform[6];
299 
300     int    nElevField;
301     int    nIDField;
302     int    nNextID;
303 } OGRContourWriterInfo;
304 
305 CPLErr CPL_DLL
306 OGRContourWriter( double, int, double *, double *, void *pInfo );
307 
308 CPLErr CPL_DLL
309 GDALContourGenerate( GDALRasterBandH hBand,
310                             double dfContourInterval, double dfContourBase,
311                             int nFixedLevelCount, double *padfFixedLevels,
312                             int bUseNoData, double dfNoDataValue,
313                             void *hLayer, int iIDField, int iElevField,
314                             GDALProgressFunc pfnProgress, void *pProgressArg );
315 
316 /************************************************************************/
317 /*      Rasterizer API - geometries burned into GDAL raster.            */
318 /************************************************************************/
319 
320 CPLErr CPL_DLL
321 GDALRasterizeGeometries( GDALDatasetH hDS,
322                          int nBandCount, int *panBandList,
323                          int nGeomCount, OGRGeometryH *pahGeometries,
324                          GDALTransformerFunc pfnTransformer,
325                          void *pTransformArg,
326                          double *padfGeomBurnValue,
327                          char **papszOptions,
328                          GDALProgressFunc pfnProgress,
329                          void * pProgressArg );
330 CPLErr CPL_DLL
331 GDALRasterizeLayers( GDALDatasetH hDS,
332                      int nBandCount, int *panBandList,
333                      int nLayerCount, OGRLayerH *pahLayers,
334                      GDALTransformerFunc pfnTransformer,
335                      void *pTransformArg,
336                      double *padfLayerBurnValues,
337                      char **papszOptions,
338                      GDALProgressFunc pfnProgress,
339                      void *pProgressArg );
340 
341 CPLErr CPL_DLL
342 GDALRasterizeLayersBuf( void *pData, int nBufXSize, int nBufYSize,
343                         GDALDataType eBufType, int nPixelSpace, int nLineSpace,
344                         int nLayerCount, OGRLayerH *pahLayers,
345                         const char *pszDstProjection,
346                         double *padfDstGeoTransform,
347                         GDALTransformerFunc pfnTransformer,
348                         void *pTransformArg, double dfBurnValue,
349                         char **papszOptions, GDALProgressFunc pfnProgress,
350                         void *pProgressArg );
351 
352 
353 /************************************************************************/
354 /*  Gridding interface.                                                 */
355 /************************************************************************/
356 
357 /** Gridding Algorithms */
358 typedef enum {
359   /*! Inverse distance to a power */    GGA_InverseDistanceToAPower = 1,
360   /*! Moving Average */                 GGA_MovingAverage = 2,
361   /*! Nearest Neighbor */               GGA_NearestNeighbor = 3,
362   /*! Minimum Value (Data Metric) */    GGA_MetricMinimum = 4,
363   /*! Maximum Value (Data Metric) */    GGA_MetricMaximum = 5,
364   /*! Data Range (Data Metric) */       GGA_MetricRange = 6,
365   /*! Number of Points (Data Metric) */ GGA_MetricCount = 7,
366   /*! Average Distance (Data Metric) */ GGA_MetricAverageDistance = 8,
367   /*! Average Distance Between Data Points (Data Metric) */
368                                         GGA_MetricAverageDistancePts = 9
369 } GDALGridAlgorithm;
370 
371 /** Inverse distance to a power method control options */
372 typedef struct
373 {
374     /*! Weighting power. */
375     double  dfPower;
376     /*! Smoothing parameter. */
377     double  dfSmoothing;
378     /*! Reserved for future use. */
379     double  dfAnisotropyRatio;
380     /*! Reserved for future use. */
381     double  dfAnisotropyAngle;
382     /*! The first radius (X axis if rotation angle is 0) of search ellipse. */
383     double  dfRadius1;
384     /*! The second radius (Y axis if rotation angle is 0) of search ellipse. */
385     double  dfRadius2;
386     /*! Angle of ellipse rotation in degrees.
387      *
388      * Ellipse rotated counter clockwise.
389      */
390     double  dfAngle;
391     /*! Maximum number of data points to use.
392      *
393      * Do not search for more points than this number.
394      * If less amount of points found the grid node considered empty and will
395      * be filled with NODATA marker.
396      */
397     GUInt32 nMaxPoints;
398     /*! Minimum number of data points to use.
399      *
400      * If less amount of points found the grid node considered empty and will
401      * be filled with NODATA marker.
402      */
403     GUInt32 nMinPoints;
404     /*! No data marker to fill empty points. */
405     double  dfNoDataValue;
406 } GDALGridInverseDistanceToAPowerOptions;
407 
408 /** Moving average method control options */
409 typedef struct
410 {
411     /*! The first radius (X axis if rotation angle is 0) of search ellipse. */
412     double  dfRadius1;
413     /*! The second radius (Y axis if rotation angle is 0) of search ellipse. */
414     double  dfRadius2;
415     /*! Angle of ellipse rotation in degrees.
416      *
417      * Ellipse rotated counter clockwise.
418      */
419     double  dfAngle;
420     /*! Minimum number of data points to average.
421      *
422      * If less amount of points found the grid node considered empty and will
423      * be filled with NODATA marker.
424      */
425     GUInt32 nMinPoints;
426     /*! No data marker to fill empty points. */
427     double  dfNoDataValue;
428 } GDALGridMovingAverageOptions;
429 
430 /** Nearest neighbor method control options */
431 typedef struct
432 {
433     /*! The first radius (X axis if rotation angle is 0) of search ellipse. */
434     double  dfRadius1;
435     /*! The second radius (Y axis if rotation angle is 0) of search ellipse. */
436     double  dfRadius2;
437     /*! Angle of ellipse rotation in degrees.
438      *
439      * Ellipse rotated counter clockwise.
440      */
441     double  dfAngle;
442     /*! No data marker to fill empty points. */
443     double  dfNoDataValue;
444 } GDALGridNearestNeighborOptions;
445 
446 /** Data metrics method control options */
447 typedef struct
448 {
449     /*! The first radius (X axis if rotation angle is 0) of search ellipse. */
450     double  dfRadius1;
451     /*! The second radius (Y axis if rotation angle is 0) of search ellipse. */
452     double  dfRadius2;
453     /*! Angle of ellipse rotation in degrees.
454      *
455      * Ellipse rotated counter clockwise.
456      */
457     double  dfAngle;
458     /*! Minimum number of data points to average.
459      *
460      * If less amount of points found the grid node considered empty and will
461      * be filled with NODATA marker.
462      */
463     GUInt32 nMinPoints;
464     /*! No data marker to fill empty points. */
465     double  dfNoDataValue;
466 } GDALGridDataMetricsOptions;
467 
468 CPLErr CPL_DLL
469 GDALGridCreate( GDALGridAlgorithm, const void *, GUInt32,
470                 const double *, const double *, const double *,
471                 double, double, double, double,
472                 GUInt32, GUInt32, GDALDataType, void *,
473                 GDALProgressFunc, void *);
474 
475 GDAL_GCP CPL_DLL *
476 GDALComputeMatchingPoints( GDALDatasetH hFirstImage,
477                            GDALDatasetH hSecondImage,
478                            char **papszOptions,
479                            int *pnGCPCount );
480 CPL_C_END
481 
482 #endif /* ndef GDAL_ALG_H_INCLUDED */
483