Sophie

Sophie

distrib > Mandriva > 9.0 > i586 > by-pkgid > d67485fb8ce60f8952179bbde3b5d022 > files > 90

libgdal0-devel-1.1.7-2mdk.i586.rpm

<!DOCTYPE HTML PUBLIC "-//W3C//DTD HTML 4.0 Transitional//EN">
<html><head><meta name="robots" content="noindex">
<meta http-equiv="Content-Type" content="text/html;charset=iso-8859-1">
<title>gdal_misc.cpp Source File</title>
<link href="doxygen.css" rel="stylesheet" type="text/css">
</head><body bgcolor="#ffffff">
<!-- Generated by Doxygen 1.2.3-20001105 on Thu Mar 28 09:47:29 2002 -->
<center>
<a class="qindex" href="index.html">Main Page</a> &nbsp; <a class="qindex" href="hierarchy.html">Class Hierarchy</a> &nbsp; <a class="qindex" href="annotated.html">Compound List</a> &nbsp; <a class="qindex" href="files.html">File List</a> &nbsp; <a class="qindex" href="functions.html">Compound Members</a> &nbsp; <a class="qindex" href="globals.html">File Members</a> &nbsp; <a class="qindex" href="pages.html">Related Pages</a> &nbsp; </center>
<hr><h1>gdal_misc.cpp</h1><div class="fragment"><pre>00001 <font class="comment">/******************************************************************************</font>
00002 <font class="comment"> * $Id: gdal_misc_cpp-source.html,v 1.10 2002/04/16 13:11:48 warmerda Exp $</font>
00003 <font class="comment"> *</font>
00004 <font class="comment"> * Project:  GDAL Core</font>
00005 <font class="comment"> * Purpose:  Free standing functions for GDAL.</font>
00006 <font class="comment"> * Author:   Frank Warmerdam, warmerda@home.com</font>
00007 <font class="comment"> *</font>
00008 <font class="comment"> ******************************************************************************</font>
00009 <font class="comment"> * Copyright (c) 1999, Frank Warmerdam</font>
00010 <font class="comment"> *</font>
00011 <font class="comment"> * Permission is hereby granted, free of charge, to any person obtaining a</font>
00012 <font class="comment"> * copy of this software and associated documentation files (the "Software"),</font>
00013 <font class="comment"> * to deal in the Software without restriction, including without limitation</font>
00014 <font class="comment"> * the rights to use, copy, modify, merge, publish, distribute, sublicense,</font>
00015 <font class="comment"> * and/or sell copies of the Software, and to permit persons to whom the</font>
00016 <font class="comment"> * Software is furnished to do so, subject to the following conditions:</font>
00017 <font class="comment"> *</font>
00018 <font class="comment"> * The above copyright notice and this permission notice shall be included</font>
00019 <font class="comment"> * in all copies or substantial portions of the Software.</font>
00020 <font class="comment"> *</font>
00021 <font class="comment"> * THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS</font>
00022 <font class="comment"> * OR IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,</font>
00023 <font class="comment"> * FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL</font>
00024 <font class="comment"> * THE AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER</font>
00025 <font class="comment"> * LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING</font>
00026 <font class="comment"> * FROM, OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER</font>
00027 <font class="comment"> * DEALINGS IN THE SOFTWARE.</font>
00028 <font class="comment"> ******************************************************************************</font>
00029 <font class="comment"> *</font>
00030 <font class="comment"> * $Log: gdal_misc_cpp-source.html,v $
00030 <font class="comment"> * Revision 1.10  2002/04/16 13:11:48  warmerda
00030 <font class="comment"> * updated
00030 <font class="comment"> *</font>
00031 <font class="comment"> * Revision 1.29  2001/12/07 20:04:21  warmerda</font>
00032 <font class="comment"> * fixed serious bug in random sampler</font>
00033 <font class="comment"> *</font>
00034 <font class="comment"> * Revision 1.28  2001/11/30 03:41:26  warmerda</font>
00035 <font class="comment"> * Fixed bug with the block sampling rate being too low to satisfy large</font>
00036 <font class="comment"> * sample count values.  Fixed bug with tiled images including some uninitialized</font>
00037 <font class="comment"> * or zero data in the sample set on partial edge tiles.</font>
00038 <font class="comment"> *</font>
00039 <font class="comment"> * Revision 1.27  2001/11/26 20:14:01  warmerda</font>
00040 <font class="comment"> * added GDALProjDef stubs for old 'bridges'</font>
00041 <font class="comment"> *</font>
00042 <font class="comment"> * Revision 1.26  2001/11/19 16:03:16  warmerda</font>
00043 <font class="comment"> * moved GDALDectoDMS here</font>
00044 <font class="comment"> *</font>
00045 <font class="comment"> * Revision 1.25  2001/08/15 15:05:44  warmerda</font>
00046 <font class="comment"> * return magnitude for complex samples in random sampler</font>
00047 <font class="comment"> *</font>
00048 <font class="comment"> * Revision 1.24  2001/07/18 04:04:30  warmerda</font>
00049 <font class="comment"> * added CPL_CVSID</font>
00050 <font class="comment"> *</font>
00051 <font class="comment"> * Revision 1.23  2001/05/01 18:09:25  warmerda</font>
00052 <font class="comment"> * added GDALReadWorldFile()</font>
00053 <font class="comment"> *</font>
00054 <font class="comment"> * Revision 1.22  2000/12/04 20:45:14  warmerda</font>
00055 <font class="comment"> * removed unused variable.</font>
00056 <font class="comment"> *</font>
00057 <font class="comment"> * Revision 1.21  2000/10/06 15:22:49  warmerda</font>
00058 <font class="comment"> * added GDALDataTypeUnion</font>
00059 <font class="comment"> *</font>
00060 <font class="comment"> * Revision 1.20  2000/08/18 15:24:48  warmerda</font>
00061 <font class="comment"> * added GDALTermProgress</font>
00062 <font class="comment"> *</font>
00063 <font class="comment"> * Revision 1.19  2000/08/09 16:25:42  warmerda</font>
00064 <font class="comment"> * don't crash if block is null</font>
00065 <font class="comment"> *</font>
00066 <font class="comment"> * Revision 1.18  2000/07/11 14:35:43  warmerda</font>
00067 <font class="comment"> * added documentation</font>
00068 <font class="comment"> *</font>
00069 <font class="comment"> * Revision 1.17  2000/07/05 17:53:33  warmerda</font>
00070 <font class="comment"> * Removed unused code related to nXCheck.</font>
00071 <font class="comment"> *</font>
00072 <font class="comment"> * Revision 1.16  2000/06/27 17:21:26  warmerda</font>
00073 <font class="comment"> * added GDALGetRasterSampleOverview</font>
00074 <font class="comment"> *</font>
00075 <font class="comment"> * Revision 1.15  2000/06/26 22:17:49  warmerda</font>
00076 <font class="comment"> * added scaled progress support</font>
00077 <font class="comment"> *</font>
00078 <font class="comment"> * Revision 1.14  2000/06/05 17:24:05  warmerda</font>
00079 <font class="comment"> * added real complex support</font>
00080 <font class="comment"> *</font>
00081 <font class="comment"> * Revision 1.13  2000/04/21 21:55:32  warmerda</font>
00082 <font class="comment"> * made more robust if block read fails</font>
00083 <font class="comment"> *</font>
00084 <font class="comment"> * Revision 1.12  2000/04/17 20:59:40  warmerda</font>
00085 <font class="comment"> * Removed printf.</font>
00086 <font class="comment"> *</font>
00087 <font class="comment"> * Revision 1.11  2000/04/17 20:59:14  warmerda</font>
00088 <font class="comment"> * fixed sampling bug</font>
00089 <font class="comment"> *</font>
00090 <font class="comment"> * Revision 1.10  2000/03/31 13:41:45  warmerda</font>
00091 <font class="comment"> * added gcp support functions</font>
00092 <font class="comment"> *</font>
00093 <font class="comment"> * Revision 1.9  2000/03/24 00:09:19  warmerda</font>
00094 <font class="comment"> * added sort-of random sampling</font>
00095 <font class="comment"> *</font>
00096 <font class="comment"> * Revision 1.8  2000/03/23 16:53:21  warmerda</font>
00097 <font class="comment"> * use overviews for approximate min/max</font>
00098 <font class="comment"> *</font>
00099 <font class="comment"> * Revision 1.7  2000/03/09 23:21:44  warmerda</font>
00100 <font class="comment"> * added GDALDummyProgress</font>
00101 <font class="comment"> *</font>
00102 <font class="comment"> * Revision 1.6  2000/03/06 21:59:44  warmerda</font>
00103 <font class="comment"> * added min/max calculate</font>
00104 <font class="comment"> *</font>
00105 <font class="comment"> * Revision 1.5  2000/03/06 02:20:15  warmerda</font>
00106 <font class="comment"> * added getname functions for colour interpretations</font>
00107 <font class="comment"> *</font>
00108 <font class="comment"> * Revision 1.4  1999/07/23 19:35:47  warmerda</font>
00109 <font class="comment"> * added GDALGetDataTypeName</font>
00110 <font class="comment"> *</font>
00111 <font class="comment"> * Revision 1.3  1999/05/17 02:00:45  vgough</font>
00112 <font class="comment"> * made pure_virtual C linkage</font>
00113 <font class="comment"> *</font>
00114 <font class="comment"> * Revision 1.2  1999/05/16 19:32:13  warmerda</font>
00115 <font class="comment"> * Added __pure_virtual.</font>
00116 <font class="comment"> *</font>
00117 <font class="comment"> * Revision 1.1  1998/12/06 02:50:16  warmerda</font>
00118 <font class="comment"> * New</font>
00119 <font class="comment"> *</font>
00120 <font class="comment"> */</font>
00121 
00122 <font class="preprocessor">#include "gdal_priv.h"</font>
00123 <font class="preprocessor">#include "cpl_string.h"</font>
00124 
00125 CPL_CVSID(<font class="stringliteral">"$Id: gdal_misc_cpp-source.html,v 1.10 2002/04/16 13:11:48 warmerda Exp $"</font>);
00126 
00127 <font class="comment">/************************************************************************/</font>
00128 <font class="comment">/*                           __pure_virtual()                           */</font>
00129 <font class="comment">/*                                                                      */</font>
00130 <font class="comment">/*      The following is a gross hack to remove the last remaining      */</font>
00131 <font class="comment">/*      dependency on the GNU C++ standard library.                     */</font>
00132 <font class="comment">/************************************************************************/</font>
00133 
00134 <font class="preprocessor">#ifdef __GNUC__</font>
00135 <font class="preprocessor"></font>
00136 <font class="keyword">extern</font> <font class="stringliteral">"C"</font>
00137 <font class="keywordtype">void</font> __pure_virtual()<font class="keyword"></font>
00138 <font class="keyword"></font>
00139 <font class="keyword"></font>{
00140 }
00141 
00142 <font class="preprocessor">#endif</font>
00143 <font class="preprocessor"></font>
00144 <font class="comment">/************************************************************************/</font>
00145 <font class="comment">/*                         GDALDataTypeUnion()                          */</font>
00146 <font class="comment">/************************************************************************/</font>
00147 
00158 GDALDataType <a class="code" href="gdal_h.html#a49">GDALDataTypeUnion</a>( GDALDataType eType1, GDALDataType eType2 )<font class="keyword"></font>
00159 <font class="keyword"></font>
00160 <font class="keyword"></font>{
00161     <font class="keywordtype">int</font>         bFloating, bComplex, nBits, bSigned;
00162 
00163     bComplex = GDALDataTypeIsComplex(eType1) | GDALDataTypeIsComplex(eType2);
00164     
00165     <font class="keywordflow">switch</font>( eType1 )
00166     {
00167       <font class="keywordflow">case</font> GDT_Byte:
00168         nBits = 8;
00169         bSigned = FALSE;
00170         bFloating = FALSE;
00171         <font class="keywordflow">break</font>;
00172         
00173       <font class="keywordflow">case</font> GDT_Int16:
00174       <font class="keywordflow">case</font> GDT_CInt16:
00175         nBits = 16;
00176         bSigned = TRUE;
00177         bFloating = FALSE;
00178         <font class="keywordflow">break</font>;
00179         
00180       <font class="keywordflow">case</font> GDT_UInt16:
00181         nBits = 16;
00182         bSigned = FALSE;
00183         bFloating = FALSE;
00184         <font class="keywordflow">break</font>;
00185         
00186       <font class="keywordflow">case</font> GDT_Int32:
00187       <font class="keywordflow">case</font> GDT_CInt32:
00188         nBits = 32;
00189         bSigned = TRUE;
00190         bFloating = FALSE;
00191         <font class="keywordflow">break</font>;
00192         
00193       <font class="keywordflow">case</font> GDT_UInt32:
00194         nBits = 32;
00195         bSigned = FALSE;
00196         bFloating = FALSE;
00197         <font class="keywordflow">break</font>;
00198 
00199       <font class="keywordflow">case</font> GDT_Float32:
00200       <font class="keywordflow">case</font> GDT_CFloat32:
00201         nBits = 32;
00202         bSigned = TRUE;
00203         bFloating = TRUE;
00204         <font class="keywordflow">break</font>;
00205 
00206       <font class="keywordflow">case</font> GDT_Float64:
00207       <font class="keywordflow">case</font> GDT_CFloat64:
00208         nBits = 64;
00209         bSigned = TRUE;
00210         bFloating = TRUE;
00211         <font class="keywordflow">break</font>;
00212 
00213       <font class="keywordflow">default</font>:
00214         CPLAssert( FALSE );
00215         <font class="keywordflow">return</font> GDT_Unknown;
00216     }
00217 
00218     <font class="keywordflow">switch</font>( eType2 )
00219     {
00220       <font class="keywordflow">case</font> GDT_Byte:
00221         <font class="keywordflow">break</font>;
00222         
00223       <font class="keywordflow">case</font> GDT_Int16:
00224         nBits = MAX(nBits,16);
00225         bSigned = TRUE;
00226         <font class="keywordflow">break</font>;
00227         
00228       <font class="keywordflow">case</font> GDT_UInt16:
00229         nBits = MAX(nBits,16);
00230         <font class="keywordflow">break</font>;
00231         
00232       <font class="keywordflow">case</font> GDT_Int32:
00233       <font class="keywordflow">case</font> GDT_CInt32:
00234         nBits = MAX(nBits,32);
00235         bSigned = TRUE;
00236         <font class="keywordflow">break</font>;
00237         
00238       <font class="keywordflow">case</font> GDT_UInt32:
00239         nBits = MAX(nBits,32);
00240         <font class="keywordflow">break</font>;
00241 
00242       <font class="keywordflow">case</font> GDT_Float32:
00243       <font class="keywordflow">case</font> GDT_CFloat32:
00244         nBits = MAX(nBits,32);
00245         bSigned = TRUE;
00246         bFloating = TRUE;
00247         <font class="keywordflow">break</font>;
00248 
00249       <font class="keywordflow">case</font> GDT_Float64:
00250       <font class="keywordflow">case</font> GDT_CFloat64:
00251         nBits = MAX(nBits,64);
00252         bSigned = TRUE;
00253         bFloating = TRUE;
00254         <font class="keywordflow">break</font>;
00255 
00256       <font class="keywordflow">default</font>:
00257         CPLAssert( FALSE );
00258         <font class="keywordflow">return</font> GDT_Unknown;
00259     }
00260 
00261     <font class="keywordflow">if</font>( nBits == 8 )
00262         <font class="keywordflow">return</font> GDT_Byte;
00263     <font class="keywordflow">else</font> <font class="keywordflow">if</font>( nBits == 16 &amp;&amp; bComplex )
00264         <font class="keywordflow">return</font> GDT_CInt16;
00265     <font class="keywordflow">else</font> <font class="keywordflow">if</font>( nBits == 16 &amp;&amp; bSigned )
00266         <font class="keywordflow">return</font> GDT_Int16;
00267     <font class="keywordflow">else</font> <font class="keywordflow">if</font>( nBits == 16 &amp;&amp; !bSigned )
00268         <font class="keywordflow">return</font> GDT_UInt16;
00269     <font class="keywordflow">else</font> <font class="keywordflow">if</font>( nBits == 32 &amp;&amp; bFloating &amp;&amp; bComplex )
00270         <font class="keywordflow">return</font> GDT_CFloat32;
00271     <font class="keywordflow">else</font> <font class="keywordflow">if</font>( nBits == 32 &amp;&amp; bFloating )
00272         <font class="keywordflow">return</font> GDT_Float32;
00273     <font class="keywordflow">else</font> <font class="keywordflow">if</font>( nBits == 32 &amp;&amp; bComplex )
00274         <font class="keywordflow">return</font> GDT_CInt32;
00275     <font class="keywordflow">else</font> <font class="keywordflow">if</font>( nBits == 32 &amp;&amp; bSigned )
00276         <font class="keywordflow">return</font> GDT_Int32;
00277     <font class="keywordflow">else</font> <font class="keywordflow">if</font>( nBits == 32 &amp;&amp; !bSigned )
00278         <font class="keywordflow">return</font> GDT_UInt32;
00279     <font class="keywordflow">else</font> <font class="keywordflow">if</font>( nBits == 64 &amp;&amp; bComplex )
00280         <font class="keywordflow">return</font> GDT_CFloat64;
00281     <font class="keywordflow">else</font>
00282         <font class="keywordflow">return</font> GDT_Float64;
00283 }
00284 
00285 
00286 <font class="comment">/************************************************************************/</font>
00287 <font class="comment">/*                        GDALGetDataTypeSize()                         */</font>
00288 <font class="comment">/************************************************************************/</font>
00289 <font class="keywordtype">int</font> GDALGetDataTypeSize( GDALDataType eDataType )<font class="keyword"></font>
00290 <font class="keyword"></font>
00291 <font class="keyword"></font>{
00292     <font class="keywordflow">switch</font>( eDataType )
00293     {
00294       <font class="keywordflow">case</font> GDT_Byte:
00295         <font class="keywordflow">return</font> 8;
00296 
00297       <font class="keywordflow">case</font> GDT_UInt16:
00298       <font class="keywordflow">case</font> GDT_Int16:
00299         <font class="keywordflow">return</font> 16;
00300 
00301       <font class="keywordflow">case</font> GDT_UInt32:
00302       <font class="keywordflow">case</font> GDT_Int32:
00303       <font class="keywordflow">case</font> GDT_Float32:
00304       <font class="keywordflow">case</font> GDT_CInt16:
00305         <font class="keywordflow">return</font> 32;
00306 
00307       <font class="keywordflow">case</font> GDT_Float64:
00308       <font class="keywordflow">case</font> GDT_CInt32:
00309       <font class="keywordflow">case</font> GDT_CFloat32:
00310         <font class="keywordflow">return</font> 64;
00311 
00312       <font class="keywordflow">case</font> GDT_CFloat64:
00313         <font class="keywordflow">return</font> 128;
00314 
00315       <font class="keywordflow">default</font>:
00316         CPLAssert( FALSE );
00317         <font class="keywordflow">return</font> 0;
00318     }
00319 }
00320 
00321 <font class="comment">/************************************************************************/</font>
00322 <font class="comment">/*                       GDALDataTypeIsComplex()                        */</font>
00323 <font class="comment">/************************************************************************/</font>
00324 
00325 <font class="keywordtype">int</font> GDALDataTypeIsComplex( GDALDataType eDataType )<font class="keyword"></font>
00326 <font class="keyword"></font>
00327 <font class="keyword"></font>{
00328     <font class="keywordflow">switch</font>( eDataType )
00329     {
00330       <font class="keywordflow">case</font> GDT_CInt16:
00331       <font class="keywordflow">case</font> GDT_CInt32:
00332       <font class="keywordflow">case</font> GDT_CFloat32:
00333       <font class="keywordflow">case</font> GDT_CFloat64:
00334         <font class="keywordflow">return</font> TRUE;
00335 
00336       <font class="keywordflow">default</font>:
00337         <font class="keywordflow">return</font> FALSE;
00338     }
00339 }
00340 
00341 <font class="comment">/************************************************************************/</font>
00342 <font class="comment">/*                        GDALGetDataTypeName()                         */</font>
00343 <font class="comment">/************************************************************************/</font>
00344 
00345 <font class="keyword">const</font> <font class="keywordtype">char</font> *GDALGetDataTypeName( GDALDataType eDataType )<font class="keyword"></font>
00346 <font class="keyword"></font>
00347 <font class="keyword"></font>{
00348     <font class="keywordflow">switch</font>( eDataType )
00349     {
00350       <font class="keywordflow">case</font> GDT_Byte:
00351         <font class="keywordflow">return</font> <font class="stringliteral">"Byte"</font>;
00352 
00353       <font class="keywordflow">case</font> GDT_UInt16:
00354         <font class="keywordflow">return</font> <font class="stringliteral">"UInt16"</font>;
00355 
00356       <font class="keywordflow">case</font> GDT_Int16:
00357         <font class="keywordflow">return</font> <font class="stringliteral">"Int16"</font>;
00358 
00359       <font class="keywordflow">case</font> GDT_UInt32:
00360         <font class="keywordflow">return</font> <font class="stringliteral">"UInt32"</font>;
00361         
00362       <font class="keywordflow">case</font> GDT_Int32:
00363         <font class="keywordflow">return</font> <font class="stringliteral">"Int32"</font>;
00364         
00365       <font class="keywordflow">case</font> GDT_Float32:
00366         <font class="keywordflow">return</font> <font class="stringliteral">"Float32"</font>;
00367 
00368       <font class="keywordflow">case</font> GDT_Float64:
00369         <font class="keywordflow">return</font> <font class="stringliteral">"Float64"</font>;
00370 
00371       <font class="keywordflow">case</font> GDT_CInt16:
00372         <font class="keywordflow">return</font> <font class="stringliteral">"CInt16"</font>;
00373 
00374       <font class="keywordflow">case</font> GDT_CInt32:
00375         <font class="keywordflow">return</font> <font class="stringliteral">"CInt32"</font>;
00376 
00377       <font class="keywordflow">case</font> GDT_CFloat32:
00378         <font class="keywordflow">return</font> <font class="stringliteral">"CFloat32"</font>;
00379 
00380       <font class="keywordflow">case</font> GDT_CFloat64:
00381         <font class="keywordflow">return</font> <font class="stringliteral">"CFloat64"</font>;
00382 
00383       <font class="keywordflow">default</font>:
00384         <font class="keywordflow">return</font> NULL;
00385     }
00386 }
00387 
00388 <font class="comment">/************************************************************************/</font>
00389 <font class="comment">/*                  GDALGetPaletteInterpretationName()                  */</font>
00390 <font class="comment">/************************************************************************/</font>
00391 
00392 <font class="keyword">const</font> <font class="keywordtype">char</font> *<a class="code" href="gdal_h.html#a51">GDALGetPaletteInterpretationName</a>( GDALPaletteInterp eInterp )<font class="keyword"></font>
00393 <font class="keyword"></font>
00394 <font class="keyword"></font>{
00395     <font class="keywordflow">switch</font>( eInterp )
00396     {
00397       <font class="keywordflow">case</font> GPI_Gray:
00398         <font class="keywordflow">return</font> <font class="stringliteral">"Gray"</font>;
00399 
00400       <font class="keywordflow">case</font> GPI_RGB:
00401         <font class="keywordflow">return</font> <font class="stringliteral">"RGB"</font>;
00402         
00403       <font class="keywordflow">case</font> GPI_CMYK:
00404         <font class="keywordflow">return</font> <font class="stringliteral">"CMYK"</font>;
00405 
00406       <font class="keywordflow">case</font> GPI_HLS:
00407         <font class="keywordflow">return</font> <font class="stringliteral">"HLS"</font>;
00408         
00409       <font class="keywordflow">default</font>:
00410         <font class="keywordflow">return</font> <font class="stringliteral">"Unknown"</font>;
00411     }
00412 }
00413 
00414 <font class="comment">/************************************************************************/</font>
00415 <font class="comment">/*                   GDALGetColorInterpretationName()                   */</font>
00416 <font class="comment">/************************************************************************/</font>
00417 
00418 <font class="keyword">const</font> <font class="keywordtype">char</font> *<a class="code" href="gdal_h.html#a50">GDALGetColorInterpretationName</a>( GDALColorInterp eInterp )<font class="keyword"></font>
00419 <font class="keyword"></font>
00420 <font class="keyword"></font>{
00421     <font class="keywordflow">switch</font>( eInterp )
00422     {
00423       <font class="keywordflow">case</font> GCI_Undefined:
00424         <font class="keywordflow">return</font> <font class="stringliteral">"Undefined"</font>;
00425 
00426       <font class="keywordflow">case</font> GCI_GrayIndex:
00427         <font class="keywordflow">return</font> <font class="stringliteral">"Gray"</font>;
00428 
00429       <font class="keywordflow">case</font> GCI_PaletteIndex:
00430         <font class="keywordflow">return</font> <font class="stringliteral">"Palette"</font>;
00431 
00432       <font class="keywordflow">case</font> GCI_RedBand:
00433         <font class="keywordflow">return</font> <font class="stringliteral">"Red"</font>;
00434 
00435       <font class="keywordflow">case</font> GCI_GreenBand:
00436         <font class="keywordflow">return</font> <font class="stringliteral">"Green"</font>;
00437 
00438       <font class="keywordflow">case</font> GCI_BlueBand:
00439         <font class="keywordflow">return</font> <font class="stringliteral">"Blue"</font>;
00440 
00441       <font class="keywordflow">case</font> GCI_AlphaBand:
00442         <font class="keywordflow">return</font> <font class="stringliteral">"Alpha"</font>;
00443 
00444       <font class="keywordflow">case</font> GCI_HueBand:
00445         <font class="keywordflow">return</font> <font class="stringliteral">"Hue"</font>;
00446 
00447       <font class="keywordflow">case</font> GCI_SaturationBand:
00448         <font class="keywordflow">return</font> <font class="stringliteral">"Saturation"</font>;
00449 
00450       <font class="keywordflow">case</font> GCI_LightnessBand:
00451         <font class="keywordflow">return</font> <font class="stringliteral">"Lightness"</font>;
00452 
00453       <font class="keywordflow">case</font> GCI_CyanBand:
00454         <font class="keywordflow">return</font> <font class="stringliteral">"Cyan"</font>;
00455 
00456       <font class="keywordflow">case</font> GCI_MagentaBand:
00457         <font class="keywordflow">return</font> <font class="stringliteral">"Magenta"</font>;
00458 
00459       <font class="keywordflow">case</font> GCI_YellowBand:
00460         <font class="keywordflow">return</font> <font class="stringliteral">"Yellow"</font>;
00461 
00462       <font class="keywordflow">case</font> GCI_BlackBand:
00463         <font class="keywordflow">return</font> <font class="stringliteral">"Black"</font>;
00464         
00465       <font class="keywordflow">default</font>:
00466         <font class="keywordflow">return</font> <font class="stringliteral">"Unknown"</font>;
00467     }
00468 }
00469 
00470 <font class="comment">/************************************************************************/</font>
00471 <font class="comment">/*                      GDALComputeRasterMinMax()                       */</font>
00472 <font class="comment">/************************************************************************/</font>
00473 
00492 <font class="keywordtype">void</font> <a class="code" href="gdal_h.html#a118">GDALComputeRasterMinMax</a>( GDALRasterBandH hBand, <font class="keywordtype">int</font> bApproxOK, 
00493                               <font class="keywordtype">double</font> adfMinMax[2] )<font class="keyword"></font>
00494 <font class="keyword"></font>
00495 <font class="keyword"></font>{
00496     <font class="keywordtype">double</font>       dfMin=0.0, dfMax=0.0;
00497     <a class="code" href="class_GDALRasterBand.html">GDALRasterBand</a> *poBand;
00498 
00499 <font class="comment">/* -------------------------------------------------------------------- */</font>
00500 <font class="comment">/*      Does the driver already know the min/max?                       */</font>
00501 <font class="comment">/* -------------------------------------------------------------------- */</font>
00502     <font class="keywordflow">if</font>( bApproxOK )
00503     {
00504         <font class="keywordtype">int</font>          bSuccessMin, bSuccessMax;
00505 
00506         dfMin = GDALGetRasterMinimum( hBand, &amp;bSuccessMin );
00507         dfMax = GDALGetRasterMaximum( hBand, &amp;bSuccessMax );
00508 
00509         <font class="keywordflow">if</font>( bSuccessMin &amp;&amp; bSuccessMax )
00510         {
00511             adfMinMax[0] = dfMin;
00512             adfMinMax[1] = dfMax;
00513             <font class="keywordflow">return</font>;
00514         }
00515     }
00516     
00517 <font class="comment">/* -------------------------------------------------------------------- */</font>
00518 <font class="comment">/*      If we have overview bands, use them for min/max.                */</font>
00519 <font class="comment">/* -------------------------------------------------------------------- */</font>
00520     <font class="keywordflow">if</font>( bApproxOK )
00521         poBand = (<a class="code" href="class_GDALRasterBand.html">GDALRasterBand</a> *) <a class="code" href="gdal_h.html#a122">GDALGetRasterSampleOverview</a>( hBand, 2500 );
00522     <font class="keywordflow">else</font> 
00523         poBand = (<a class="code" href="class_GDALRasterBand.html">GDALRasterBand</a> *) hBand;
00524     
00525 <font class="comment">/* -------------------------------------------------------------------- */</font>
00526 <font class="comment">/*      Figure out the ratio of blocks we will read to get an           */</font>
00527 <font class="comment">/*      approximate value.                                              */</font>
00528 <font class="comment">/* -------------------------------------------------------------------- */</font>
00529     <font class="keywordtype">int</font>         nBlockXSize, nBlockYSize;
00530     <font class="keywordtype">int</font>         nBlocksPerRow, nBlocksPerColumn;
00531     <font class="keywordtype">int</font>         nSampleRate;
00532     <font class="keywordtype">int</font>         bGotNoDataValue, bFirstValue = TRUE;
00533     <font class="keywordtype">double</font>      dfNoDataValue;
00534 
00535     dfNoDataValue = poBand-&gt;<a class="code" href="class_GDALRasterBand.html#a16">GetNoDataValue</a>( &amp;bGotNoDataValue );
00536 
00537     poBand-&gt;<a class="code" href="class_GDALRasterBand.html#a6">GetBlockSize</a>( &amp;nBlockXSize, &amp;nBlockYSize );
00538     nBlocksPerRow = (poBand-&gt;<a class="code" href="class_GDALRasterBand.html#a2">GetXSize</a>() + nBlockXSize - 1) / nBlockXSize;
00539     nBlocksPerColumn = (poBand-&gt;<a class="code" href="class_GDALRasterBand.html#a3">GetYSize</a>() + nBlockYSize - 1) / nBlockYSize;
00540 
00541     <font class="keywordflow">if</font>( bApproxOK )
00542         nSampleRate = 
00543             (<font class="keywordtype">int</font>) MAX(1,sqrt((<font class="keywordtype">double</font>) nBlocksPerRow * nBlocksPerColumn));
00544     <font class="keywordflow">else</font>
00545         nSampleRate = 1;
00546     
00547     <font class="keywordflow">for</font>( <font class="keywordtype">int</font> iSampleBlock = 0; 
00548          iSampleBlock &lt; nBlocksPerRow * nBlocksPerColumn;
00549          iSampleBlock += nSampleRate )
00550     {
00551         <font class="keywordtype">double</font> dfValue = 0.0;
00552         <font class="keywordtype">int</font>  iXBlock, iYBlock, nXCheck, nYCheck;
00553         <a class="code" href="class_GDALRasterBlock.html">GDALRasterBlock</a> *poBlock;
00554 
00555         iYBlock = iSampleBlock / nBlocksPerRow;
00556         iXBlock = iSampleBlock - nBlocksPerRow * iYBlock;
00557         
00558         poBlock = poBand-&gt;<a class="code" href="class_GDALRasterBand.html#a11">GetBlockRef</a>( iXBlock, iYBlock );
00559         <font class="keywordflow">if</font>( poBlock == NULL )
00560             <font class="keywordflow">continue</font>;
00561         
00562         <font class="keywordflow">if</font>( (iXBlock+1) * nBlockXSize &gt; poBand-&gt;<a class="code" href="class_GDALRasterBand.html#a2">GetXSize</a>() )
00563             nXCheck = poBand-&gt;<a class="code" href="class_GDALRasterBand.html#a2">GetXSize</a>() - iXBlock * nBlockXSize;
00564         <font class="keywordflow">else</font>
00565             nXCheck = nBlockXSize;
00566 
00567         <font class="keywordflow">if</font>( (iYBlock+1) * nBlockYSize &gt; poBand-&gt;<a class="code" href="class_GDALRasterBand.html#a3">GetYSize</a>() )
00568             nYCheck = poBand-&gt;<a class="code" href="class_GDALRasterBand.html#a3">GetYSize</a>() - iYBlock * nBlockYSize;
00569         <font class="keywordflow">else</font>
00570             nYCheck = nBlockYSize;
00571 
00572         <font class="comment">/* this isn't the fastest way to do this, but is easier for now */</font>
00573         <font class="keywordflow">for</font>( <font class="keywordtype">int</font> iY = 0; iY &lt; nYCheck; iY++ )
00574         {
00575             <font class="keywordflow">for</font>( <font class="keywordtype">int</font> iX = 0; iX &lt; nXCheck; iX++ )
00576             {
00577                 <font class="keywordtype">int</font>    iOffset = iX + iY * nBlockXSize;
00578 
00579                 <font class="keywordflow">switch</font>( poBlock-&gt;GetDataType() )
00580                 {
00581                   <font class="keywordflow">case</font> GDT_Byte:
00582                     dfValue = ((GByte *) poBlock-&gt;GetDataRef())[iOffset];
00583                     <font class="keywordflow">break</font>;
00584                   <font class="keywordflow">case</font> GDT_UInt16:
00585                     dfValue = ((GUInt16 *) poBlock-&gt;GetDataRef())[iOffset];
00586                     <font class="keywordflow">break</font>;
00587                   <font class="keywordflow">case</font> GDT_Int16:
00588                     dfValue = ((GInt16 *) poBlock-&gt;GetDataRef())[iOffset];
00589                     <font class="keywordflow">break</font>;
00590                   <font class="keywordflow">case</font> GDT_UInt32:
00591                     dfValue = ((GUInt32 *) poBlock-&gt;GetDataRef())[iOffset];
00592                     <font class="keywordflow">break</font>;
00593                   <font class="keywordflow">case</font> GDT_Int32:
00594                     dfValue = ((GInt32 *) poBlock-&gt;GetDataRef())[iOffset];
00595                     <font class="keywordflow">break</font>;
00596                   <font class="keywordflow">case</font> GDT_Float32:
00597                     dfValue = ((<font class="keywordtype">float</font> *) poBlock-&gt;GetDataRef())[iOffset];
00598                     <font class="keywordflow">break</font>;
00599                   <font class="keywordflow">case</font> GDT_Float64:
00600                     dfValue = ((<font class="keywordtype">double</font> *) poBlock-&gt;GetDataRef())[iOffset];
00601                     <font class="keywordflow">break</font>;
00602                   <font class="keywordflow">case</font> GDT_CInt16:
00603                     dfValue = ((GInt16 *) poBlock-&gt;GetDataRef())[iOffset*2];
00604                     <font class="keywordflow">break</font>;
00605                   <font class="keywordflow">case</font> GDT_CInt32:
00606                     dfValue = ((GInt32 *) poBlock-&gt;GetDataRef())[iOffset*2];
00607                     <font class="keywordflow">break</font>;
00608                   <font class="keywordflow">case</font> GDT_CFloat32:
00609                     dfValue = ((<font class="keywordtype">float</font> *) poBlock-&gt;GetDataRef())[iOffset*2];
00610                     <font class="keywordflow">break</font>;
00611                   <font class="keywordflow">case</font> GDT_CFloat64:
00612                     dfValue = ((<font class="keywordtype">double</font> *) poBlock-&gt;GetDataRef())[iOffset*2];
00613                     <font class="keywordflow">break</font>;
00614                   <font class="keywordflow">default</font>:
00615                     CPLAssert( FALSE );
00616                 }
00617                 
00618                 <font class="keywordflow">if</font>( bGotNoDataValue &amp;&amp; dfValue == dfNoDataValue )
00619                     <font class="keywordflow">continue</font>;
00620 
00621                 <font class="keywordflow">if</font>( bFirstValue )
00622                 {
00623                     dfMin = dfMax = dfValue;
00624                     bFirstValue = FALSE;
00625                 }
00626                 <font class="keywordflow">else</font>
00627                 {
00628                     dfMin = MIN(dfMin,dfValue);
00629                     dfMax = MAX(dfMax,dfValue);
00630                 }
00631             }
00632         }
00633     }
00634 
00635     adfMinMax[0] = dfMin;
00636     adfMinMax[1] = dfMax;
00637 }
00638 
00639 <font class="comment">/************************************************************************/</font>
00640 <font class="comment">/*                         GDALDummyProgress()                          */</font>
00641 <font class="comment">/************************************************************************/</font>
00642 
00707 <font class="keywordtype">int</font> <a class="code" href="gdal_h.html#a52">GDALDummyProgress</a>( <font class="keywordtype">double</font>, <font class="keyword">const</font> <font class="keywordtype">char</font> *, <font class="keywordtype">void</font> * )<font class="keyword"></font>
00708 <font class="keyword"></font>
00709 <font class="keyword"></font>{
00710     <font class="keywordflow">return</font> TRUE;
00711 }
00712 
00713 <font class="comment">/************************************************************************/</font>
00714 <font class="comment">/*                         GDALScaledProgress()                         */</font>
00715 <font class="comment">/************************************************************************/</font>
00716 <font class="keyword">typedef</font> <font class="keyword">struct </font>{ 
00717     GDALProgressFunc pfnProgress;
00718     <font class="keywordtype">void</font> *pData;
00719     <font class="keywordtype">double</font> dfMin;
00720     <font class="keywordtype">double</font> dfMax;
00721 } GDALScaledProgressInfo;
00722 
00723 <font class="keywordtype">int</font> GDALScaledProgress( <font class="keywordtype">double</font> dfComplete, <font class="keyword">const</font> <font class="keywordtype">char</font> *pszMessage, 
00724                         <font class="keywordtype">void</font> *pData )<font class="keyword"></font>
00725 <font class="keyword"></font>
00726 <font class="keyword"></font>{
00727     GDALScaledProgressInfo *psInfo = (GDALScaledProgressInfo *) pData;
00728 
00729     <font class="keywordflow">return</font> psInfo-&gt;pfnProgress( dfComplete * (psInfo-&gt;dfMax - psInfo-&gt;dfMin)
00730                                 + psInfo-&gt;dfMin,
00731                                 pszMessage, psInfo-&gt;pData );
00732 }
00733 
00734 <font class="comment">/************************************************************************/</font>
00735 <font class="comment">/*                      GDALCreateScaledProgress()                      */</font>
00736 <font class="comment">/************************************************************************/</font>
00737 
00738 <font class="keywordtype">void</font> *GDALCreateScaledProgress( <font class="keywordtype">double</font> dfMin, <font class="keywordtype">double</font> dfMax, 
00739                                 GDALProgressFunc pfnProgress, 
00740                                 <font class="keywordtype">void</font> * pData )<font class="keyword"></font>
00741 <font class="keyword"></font>
00742 <font class="keyword"></font>{
00743     GDALScaledProgressInfo *psInfo;
00744 
00745     psInfo = (GDALScaledProgressInfo *) 
00746         <a class="code" href="cpl_conv_h.html#a4">CPLCalloc</a>(<font class="keyword">sizeof</font>(GDALScaledProgressInfo),1);
00747 
00748     <font class="keywordflow">if</font>( ABS(dfMin-dfMax) &lt; 0.0000001 )
00749         dfMax = dfMin + 0.01;
00750 
00751     psInfo-&gt;pData = pData;
00752     psInfo-&gt;pfnProgress = pfnProgress;
00753     psInfo-&gt;dfMin = dfMin;
00754     psInfo-&gt;dfMax = dfMax;
00755 
00756     <font class="keywordflow">return</font> (<font class="keywordtype">void</font> *) psInfo;
00757 }
00758 
00759 <font class="comment">/************************************************************************/</font>
00760 <font class="comment">/*                     GDALDestroyScaledProgress()                      */</font>
00761 <font class="comment">/************************************************************************/</font>
00762 
00763 <font class="keywordtype">void</font> GDALDestroyScaledProgress( <font class="keywordtype">void</font> * pData )<font class="keyword"></font>
00764 <font class="keyword"></font>
00765 <font class="keyword"></font>{
00766     CPLFree( pData );
00767 }
00768 
00769 <font class="comment">/************************************************************************/</font>
00770 <font class="comment">/*                          GDALTermProgress()                          */</font>
00771 <font class="comment">/************************************************************************/</font>
00772 
00773 <font class="keywordtype">int</font> GDALTermProgress( <font class="keywordtype">double</font> dfComplete, <font class="keyword">const</font> <font class="keywordtype">char</font> *pszMessage, <font class="keywordtype">void</font> * )<font class="keyword"></font>
00774 <font class="keyword"></font>
00775 <font class="keyword"></font>{
00776     <font class="keyword">static</font> <font class="keywordtype">double</font> dfLastComplete = -1.0;
00777 
00778     <font class="keywordflow">if</font>( dfLastComplete &gt; dfComplete )
00779     {
00780         <font class="keywordflow">if</font>( dfLastComplete &gt; 1.0 )
00781             dfLastComplete = -1.0;
00782         <font class="keywordflow">else</font>
00783             dfLastComplete = dfComplete;
00784     }
00785 
00786     <font class="keywordflow">if</font>( floor(dfLastComplete*10) != floor(dfComplete*10) )
00787     {
00788         <font class="keywordtype">int</font>    nPercent = (<font class="keywordtype">int</font>) floor(dfComplete*100);
00789 
00790         <font class="keywordflow">if</font>( nPercent == 0 &amp;&amp; pszMessage != NULL )
00791             fprintf( stdout, <font class="stringliteral">"%s:"</font>, pszMessage );
00792 
00793         <font class="keywordflow">if</font>( nPercent == 100 )
00794             fprintf( stdout, <font class="stringliteral">"%d - done.\n"</font>, (<font class="keywordtype">int</font>) floor(dfComplete*100) );
00795         <font class="keywordflow">else</font>
00796         {
00797             fprintf( stdout, <font class="stringliteral">"%d."</font>, (<font class="keywordtype">int</font>) floor(dfComplete*100) );
00798             fflush( stdout );
00799         }
00800     }
00801     <font class="keywordflow">else</font> <font class="keywordflow">if</font>( floor(dfLastComplete*30) != floor(dfComplete*30) )
00802     {
00803         fprintf( stdout, <font class="stringliteral">"."</font> );
00804         fflush( stdout );
00805     }
00806 
00807     dfLastComplete = dfComplete;
00808 
00809     <font class="keywordflow">return</font> TRUE;
00810 }
00811 
00812 <font class="comment">/************************************************************************/</font>
00813 <font class="comment">/*                    GDALGetRasterSampleOverview()                     */</font>
00814 <font class="comment">/************************************************************************/</font>
00815 
00831 GDALRasterBandH <a class="code" href="gdal_h.html#a122">GDALGetRasterSampleOverview</a>( GDALRasterBandH hBand, 
00832                                              <font class="keywordtype">int</font> nDesiredSamples )<font class="keyword"></font>
00833 <font class="keyword"></font>
00834 <font class="keyword"></font>{
00835     <font class="keywordtype">int</font>     nBestSamples; 
00836     GDALRasterBandH hBestBand = hBand;
00837 
00838     nBestSamples = GDALGetRasterBandXSize(hBand) 
00839         * GDALGetRasterBandYSize(hBand);
00840 
00841     <font class="keywordflow">for</font>( <font class="keywordtype">int</font> iOverview = 0; 
00842          iOverview &lt; GDALGetOverviewCount( hBand );
00843          iOverview++ )
00844     {
00845         GDALRasterBandH hOBand = GDALGetOverview( hBand, iOverview );
00846         <font class="keywordtype">int</font>    nOSamples;
00847 
00848         nOSamples = GDALGetRasterBandXSize(hOBand) 
00849             * GDALGetRasterBandYSize(hOBand);
00850 
00851         <font class="keywordflow">if</font>( nOSamples &lt; nBestSamples &amp;&amp; nOSamples &gt; nDesiredSamples )
00852         {
00853             nBestSamples = nOSamples;
00854             hBestBand = hOBand;
00855         }
00856     }
00857 
00858     <font class="keywordflow">return</font> hBestBand;
00859 }
00860 
00861 <font class="comment">/************************************************************************/</font>
00862 <font class="comment">/*                     GDALGetRandomRasterSample()                      */</font>
00863 <font class="comment">/************************************************************************/</font>
00864 
00865 <font class="keywordtype">int</font> GDALGetRandomRasterSample( GDALRasterBandH hBand, <font class="keywordtype">int</font> nSamples, 
00866                                <font class="keywordtype">float</font> *pafSampleBuf )<font class="keyword"></font>
00867 <font class="keyword"></font>
00868 <font class="keyword"></font>{
00869     <a class="code" href="class_GDALRasterBand.html">GDALRasterBand</a> *poBand;
00870 
00871     poBand = (<a class="code" href="class_GDALRasterBand.html">GDALRasterBand</a> *) <a class="code" href="gdal_h.html#a122">GDALGetRasterSampleOverview</a>( hBand, nSamples );
00872 
00873 <font class="comment">/* -------------------------------------------------------------------- */</font>
00874 <font class="comment">/*      Figure out the ratio of blocks we will read to get an           */</font>
00875 <font class="comment">/*      approximate value.                                              */</font>
00876 <font class="comment">/* -------------------------------------------------------------------- */</font>
00877     <font class="keywordtype">int</font>         nBlockXSize, nBlockYSize;
00878     <font class="keywordtype">int</font>         nBlocksPerRow, nBlocksPerColumn;
00879     <font class="keywordtype">int</font>         nSampleRate;
00880     <font class="keywordtype">int</font>         bGotNoDataValue;
00881     <font class="keywordtype">double</font>      dfNoDataValue;
00882     <font class="keywordtype">int</font>         nActualSamples = 0;
00883     <font class="keywordtype">int</font>         nBlockSampleRate;
00884     <font class="keywordtype">int</font>         nBlockPixels, nBlockCount;
00885 
00886     dfNoDataValue = poBand-&gt;<a class="code" href="class_GDALRasterBand.html#a16">GetNoDataValue</a>( &amp;bGotNoDataValue );
00887 
00888     poBand-&gt;<a class="code" href="class_GDALRasterBand.html#a6">GetBlockSize</a>( &amp;nBlockXSize, &amp;nBlockYSize );
00889 
00890     nBlocksPerRow = (poBand-&gt;<a class="code" href="class_GDALRasterBand.html#a2">GetXSize</a>() + nBlockXSize - 1) / nBlockXSize;
00891     nBlocksPerColumn = (poBand-&gt;<a class="code" href="class_GDALRasterBand.html#a3">GetYSize</a>() + nBlockYSize - 1) / nBlockYSize;
00892 
00893     nBlockPixels = nBlockXSize * nBlockYSize;
00894     nBlockCount = nBlocksPerRow * nBlocksPerColumn;
00895 
00896     nSampleRate = (<font class="keywordtype">int</font>) MAX(1,sqrt((<font class="keywordtype">double</font>) nBlockCount)-2.0);
00897 
00898     <font class="keywordflow">if</font>( nSampleRate == nBlocksPerRow &amp;&amp; nSampleRate &gt; 1 )
00899         nSampleRate--;
00900 
00901     <font class="keywordflow">while</font>( nSampleRate &gt; 1 
00902            &amp;&amp; ((nBlockCount-1) / nSampleRate + 1) * nBlockPixels &lt; nSamples )
00903         nSampleRate--;
00904 
00905     nBlockSampleRate = 
00906         MAX(1,nBlockPixels / (nSamples / ((nBlockCount-1) / nSampleRate + 1)));
00907     
00908     <font class="keywordflow">for</font>( <font class="keywordtype">int</font> iSampleBlock = 0; 
00909          iSampleBlock &lt; nBlockCount;
00910          iSampleBlock += nSampleRate )
00911     {
00912         <font class="keywordtype">double</font> dfValue = 0.0, dfReal, dfImag;
00913         <font class="keywordtype">int</font>  iXBlock, iYBlock, iX, iY, iXValid, iYValid, iRemainder = 0;
00914         <a class="code" href="class_GDALRasterBlock.html">GDALRasterBlock</a> *poBlock;
00915 
00916         iYBlock = iSampleBlock / nBlocksPerRow;
00917         iXBlock = iSampleBlock - nBlocksPerRow * iYBlock;
00918 
00919         poBlock = poBand-&gt;<a class="code" href="class_GDALRasterBand.html#a11">GetBlockRef</a>( iXBlock, iYBlock );
00920         <font class="keywordflow">if</font>( poBlock == NULL )
00921             <font class="keywordflow">continue</font>;
00922 
00923         <font class="keywordflow">if</font>( iXBlock * nBlockXSize &gt; poBand-&gt;<a class="code" href="class_GDALRasterBand.html#a2">GetXSize</a>() )
00924             iXValid = poBand-&gt;<a class="code" href="class_GDALRasterBand.html#a2">GetXSize</a>() - iXBlock * nBlockXSize;
00925         <font class="keywordflow">else</font>
00926             iXValid = nBlockXSize;
00927 
00928         <font class="keywordflow">if</font>( iYBlock * nBlockYSize &gt; poBand-&gt;<a class="code" href="class_GDALRasterBand.html#a3">GetYSize</a>() )
00929             iYValid = poBand-&gt;<a class="code" href="class_GDALRasterBand.html#a3">GetYSize</a>() - iYBlock * nBlockYSize;
00930         <font class="keywordflow">else</font>
00931             iYValid = nBlockYSize;
00932 
00933         <font class="keywordflow">for</font>( iY = 0; iY &lt; iYValid; iY++ )
00934         {
00935             <font class="keywordflow">for</font>( iX = iRemainder; iX &lt; iXValid; iX += nBlockSampleRate )
00936             {
00937                 <font class="keywordtype">int</font>     iOffset;
00938 
00939                 iOffset = iX + iY * nBlockXSize; 
00940                 <font class="keywordflow">switch</font>( poBlock-&gt;GetDataType() )
00941                 {
00942                   <font class="keywordflow">case</font> GDT_Byte:
00943                     dfValue = ((GByte *) poBlock-&gt;GetDataRef())[iOffset];
00944                     <font class="keywordflow">break</font>;
00945                   <font class="keywordflow">case</font> GDT_UInt16:
00946                     dfValue = ((GUInt16 *) poBlock-&gt;GetDataRef())[iOffset];
00947                     <font class="keywordflow">break</font>;
00948                   <font class="keywordflow">case</font> GDT_Int16:
00949                     dfValue = ((GInt16 *) poBlock-&gt;GetDataRef())[iOffset];
00950                     <font class="keywordflow">break</font>;
00951                   <font class="keywordflow">case</font> GDT_UInt32:
00952                     dfValue = ((GUInt32 *) poBlock-&gt;GetDataRef())[iOffset];
00953                     <font class="keywordflow">break</font>;
00954                   <font class="keywordflow">case</font> GDT_Int32:
00955                     dfValue = ((GInt32 *) poBlock-&gt;GetDataRef())[iOffset];
00956                     <font class="keywordflow">break</font>;
00957                   <font class="keywordflow">case</font> GDT_Float32:
00958                     dfValue = ((<font class="keywordtype">float</font> *) poBlock-&gt;GetDataRef())[iOffset];
00959                     <font class="keywordflow">break</font>;
00960                   <font class="keywordflow">case</font> GDT_Float64:
00961                     dfValue = ((<font class="keywordtype">double</font> *) poBlock-&gt;GetDataRef())[iOffset];
00962                     <font class="keywordflow">break</font>;
00963                   <font class="keywordflow">case</font> GDT_CInt16:
00964                     dfReal = ((GInt16 *) poBlock-&gt;GetDataRef())[iOffset*2];
00965                     dfImag = ((GInt16 *) poBlock-&gt;GetDataRef())[iOffset*2+1];
00966                     dfValue = sqrt(dfReal*dfReal + dfImag*dfImag);
00967                     <font class="keywordflow">break</font>;
00968                   <font class="keywordflow">case</font> GDT_CInt32:
00969                     dfReal = ((GInt32 *) poBlock-&gt;GetDataRef())[iOffset*2];
00970                     dfImag = ((GInt32 *) poBlock-&gt;GetDataRef())[iOffset*2+1];
00971                     dfValue = sqrt(dfReal*dfReal + dfImag*dfImag);
00972                     <font class="keywordflow">break</font>;
00973                   <font class="keywordflow">case</font> GDT_CFloat32:
00974                     dfReal = ((<font class="keywordtype">float</font> *) poBlock-&gt;GetDataRef())[iOffset*2];
00975                     dfImag = ((<font class="keywordtype">float</font> *) poBlock-&gt;GetDataRef())[iOffset*2+1];
00976                     dfValue = sqrt(dfReal*dfReal + dfImag*dfImag);
00977                     <font class="keywordflow">break</font>;
00978                   <font class="keywordflow">case</font> GDT_CFloat64:
00979                     dfReal = ((<font class="keywordtype">double</font> *) poBlock-&gt;GetDataRef())[iOffset*2];
00980                     dfImag = ((<font class="keywordtype">double</font> *) poBlock-&gt;GetDataRef())[iOffset*2+1];
00981                     dfValue = sqrt(dfReal*dfReal + dfImag*dfImag);
00982                     <font class="keywordflow">break</font>;
00983                   <font class="keywordflow">default</font>:
00984                     CPLAssert( FALSE );
00985                 }
00986             
00987                 <font class="keywordflow">if</font>( bGotNoDataValue &amp;&amp; dfValue == dfNoDataValue )
00988                     <font class="keywordflow">continue</font>;
00989 
00990                 <font class="keywordflow">if</font>( nActualSamples &lt; nSamples )
00991                     pafSampleBuf[nActualSamples++] = dfValue;
00992             }
00993 
00994             iRemainder = iX - iXValid;
00995         }
00996     }
00997 
00998     <font class="keywordflow">return</font> nActualSamples;
00999 }
01000 
01001 <font class="comment">/************************************************************************/</font>
01002 <font class="comment">/*                            GDALInitGCPs()                            */</font>
01003 <font class="comment">/************************************************************************/</font>
01004 
01005 <font class="keywordtype">void</font> GDALInitGCPs( <font class="keywordtype">int</font> nCount, <a class="code" href="struct_GDAL_GCP.html">GDAL_GCP</a> * psGCP )<font class="keyword"></font>
01006 <font class="keyword"></font>
01007 <font class="keyword"></font>{
01008     <font class="keywordflow">for</font>( <font class="keywordtype">int</font> iGCP = 0; iGCP &lt; nCount; iGCP++ )
01009     {
01010         memset( psGCP, 0, <font class="keyword">sizeof</font>(<a class="code" href="struct_GDAL_GCP.html">GDAL_GCP</a>) );
01011         psGCP-&gt;pszId = <a class="code" href="cpl_conv_h.html#a6">CPLStrdup</a>(<font class="stringliteral">""</font>);
01012         psGCP-&gt;pszInfo = <a class="code" href="cpl_conv_h.html#a6">CPLStrdup</a>(<font class="stringliteral">""</font>);
01013         psGCP++;
01014     }
01015 }
01016 
01017 <font class="comment">/************************************************************************/</font>
01018 <font class="comment">/*                           GDALDeinitGCPs()                           */</font>
01019 <font class="comment">/************************************************************************/</font>
01020 
01021 <font class="keywordtype">void</font> GDALDeinitGCPs( <font class="keywordtype">int</font> nCount, <a class="code" href="struct_GDAL_GCP.html">GDAL_GCP</a> * psGCP )<font class="keyword"></font>
01022 <font class="keyword"></font>
01023 <font class="keyword"></font>{
01024     <font class="keywordflow">for</font>( <font class="keywordtype">int</font> iGCP = 0; iGCP &lt; nCount; iGCP++ )
01025     {
01026         CPLFree( psGCP-&gt;pszId );
01027         CPLFree( psGCP-&gt;pszInfo );
01028         psGCP++;
01029     }
01030 }
01031 
01032 <font class="comment">/************************************************************************/</font>
01033 <font class="comment">/*                         GDALDuplicateGCPs()                          */</font>
01034 <font class="comment">/************************************************************************/</font>
01035 
01036 <a class="code" href="struct_GDAL_GCP.html">GDAL_GCP</a> *GDALDuplicateGCPs( <font class="keywordtype">int</font> nCount, <font class="keyword">const</font> <a class="code" href="struct_GDAL_GCP.html">GDAL_GCP</a> *pasGCPList )<font class="keyword"></font>
01037 <font class="keyword"></font>
01038 <font class="keyword"></font>{
01039     <a class="code" href="struct_GDAL_GCP.html">GDAL_GCP</a>    *pasReturn;
01040 
01041     pasReturn = (<a class="code" href="struct_GDAL_GCP.html">GDAL_GCP</a> *) <a class="code" href="cpl_conv_h.html#a3">CPLMalloc</a>(<font class="keyword">sizeof</font>(<a class="code" href="struct_GDAL_GCP.html">GDAL_GCP</a>) * nCount);
01042     GDALInitGCPs( nCount, pasReturn );
01043 
01044     <font class="keywordflow">for</font>( <font class="keywordtype">int</font> iGCP = 0; iGCP &lt; nCount; iGCP++ )
01045     {
01046         CPLFree( pasReturn[iGCP].pszId );
01047         pasReturn[iGCP].pszId = <a class="code" href="cpl_conv_h.html#a6">CPLStrdup</a>( pasGCPList[iGCP].pszId );
01048 
01049         CPLFree( pasReturn[iGCP].pszInfo );
01050         pasReturn[iGCP].pszInfo = <a class="code" href="cpl_conv_h.html#a6">CPLStrdup</a>( pasGCPList[iGCP].pszInfo );
01051 
01052         pasReturn[iGCP].dfGCPPixel = pasGCPList[iGCP].dfGCPPixel;
01053         pasReturn[iGCP].dfGCPLine = pasGCPList[iGCP].dfGCPLine;
01054         pasReturn[iGCP].dfGCPX = pasGCPList[iGCP].dfGCPX;
01055         pasReturn[iGCP].dfGCPY = pasGCPList[iGCP].dfGCPY;
01056         pasReturn[iGCP].dfGCPZ = pasGCPList[iGCP].dfGCPZ;
01057     }
01058 
01059     <font class="keywordflow">return</font> pasReturn;
01060 }
01061                              
01062 <font class="comment">/************************************************************************/</font>
01063 <font class="comment">/*                         GDALReadWorldFile()                          */</font>
01064 <font class="comment">/*                                                                      */</font>
01065 <font class="comment">/*      Helper function for translator implementators wanting           */</font>
01066 <font class="comment">/*      support for ESRI world files.                                   */</font>
01067 <font class="comment">/************************************************************************/</font>
01068 
01069 <font class="keywordtype">int</font> GDALReadWorldFile( <font class="keyword">const</font> <font class="keywordtype">char</font> * pszBaseFilename, <font class="keyword">const</font> <font class="keywordtype">char</font> *pszExtension,
01070                        <font class="keywordtype">double</font> *padfGeoTransform )<font class="keyword"></font>
01071 <font class="keyword"></font>
01072 <font class="keyword"></font>{
01073     <font class="keyword">const</font> <font class="keywordtype">char</font>  *pszTFW;
01074     <font class="keywordtype">char</font>        szExtUpper[32], szExtLower[32];
01075     <font class="keywordtype">int</font>         i;
01076     FILE        *fpTFW;
01077     <font class="keywordtype">char</font>        **papszLines;
01078 
01079     <font class="keywordflow">if</font>( *pszExtension == <font class="charliteral">'.'</font> )
01080         pszExtension++;
01081 
01082 <font class="comment">/* -------------------------------------------------------------------- */</font>
01083 <font class="comment">/*      Generate upper and lower case versions of the extension.        */</font>
01084 <font class="comment">/* -------------------------------------------------------------------- */</font>
01085     strcpy( szExtUpper, pszExtension );
01086     strcpy( szExtLower, pszExtension );
01087 
01088     <font class="keywordflow">for</font>( i = 0; szExtUpper[i] != <font class="charliteral">'\0'</font>; i++ )
01089     {
01090         <font class="keywordflow">if</font>( szExtUpper[i] &gt;= <font class="charliteral">'a'</font> &amp;&amp; szExtUpper[i] &lt;= <font class="charliteral">'z'</font> )
01091             szExtUpper[i] = szExtUpper[i] - <font class="charliteral">'a'</font> + <font class="charliteral">'A'</font>;
01092         <font class="keywordflow">if</font>( szExtLower[i] &gt;= <font class="charliteral">'A'</font> &amp;&amp; szExtLower[i] &lt;= <font class="charliteral">'Z'</font> )
01093             szExtLower[i] = szExtLower[i] - <font class="charliteral">'A'</font> + <font class="charliteral">'a'</font>;
01094     }
01095 
01096 <font class="comment">/* -------------------------------------------------------------------- */</font>
01097 <font class="comment">/*      Try lower case, then upper case.                                */</font>
01098 <font class="comment">/* -------------------------------------------------------------------- */</font>
01099     pszTFW = <a class="code" href="cpl_conv_h.html#a16">CPLResetExtension</a>( pszBaseFilename, szExtLower );
01100 
01101     fpTFW = VSIFOpen( pszTFW, <font class="stringliteral">"rt"</font> );
01102 
01103 <font class="preprocessor">#ifndef WIN32</font>
01104 <font class="preprocessor"></font>    <font class="keywordflow">if</font>( fpTFW == NULL )
01105     {
01106         pszTFW = <a class="code" href="cpl_conv_h.html#a16">CPLResetExtension</a>( pszBaseFilename, szExtUpper );
01107         fpTFW = VSIFOpen( pszTFW, <font class="stringliteral">"rt"</font> );
01108     }
01109 <font class="preprocessor">#endif</font>
01110 <font class="preprocessor"></font>    
01111     <font class="keywordflow">if</font>( fpTFW == NULL )
01112         <font class="keywordflow">return</font> FALSE;
01113 
01114     VSIFClose( fpTFW );
01115 
01116 <font class="comment">/* -------------------------------------------------------------------- */</font>
01117 <font class="comment">/*      We found the file, now load and parse it.                       */</font>
01118 <font class="comment">/* -------------------------------------------------------------------- */</font>
01119     papszLines = CSLLoad( pszTFW );
01120     <font class="keywordflow">if</font>( CSLCount(papszLines) &gt;= 6 
01121         &amp;&amp; atof(papszLines[0]) != 0.0
01122         &amp;&amp; atof(papszLines[3]) != 0.0 )
01123     {
01124         padfGeoTransform[0] = atof(papszLines[4]);
01125         padfGeoTransform[1] = atof(papszLines[0]);
01126         padfGeoTransform[2] = atof(papszLines[2]);
01127         padfGeoTransform[3] = atof(papszLines[5]);
01128         padfGeoTransform[4] = atof(papszLines[1]);
01129         padfGeoTransform[5] = atof(papszLines[3]);
01130 
01131         <font class="comment">// correct for center of pixel vs. top left of pixel</font>
01132         padfGeoTransform[0] -= 0.5 * padfGeoTransform[1];
01133         padfGeoTransform[0] -= 0.5 * padfGeoTransform[2];
01134         padfGeoTransform[3] -= 0.5 * padfGeoTransform[4];
01135         padfGeoTransform[3] -= 0.5 * padfGeoTransform[5];
01136 
01137         CSLDestroy(papszLines);
01138 
01139         <font class="keywordflow">return</font> TRUE;
01140     }
01141     <font class="keywordflow">else</font>
01142     {
01143         <a class="code" href="cpl_error_h.html#a29">CPLDebug</a>( <font class="stringliteral">"GDAL"</font>, 
01144                   <font class="stringliteral">"GDALReadWorldFile(%s) found file, but it was corrupt."</font>,
01145                   pszTFW );
01146         CSLDestroy(papszLines);
01147         <font class="keywordflow">return</font> FALSE;
01148     }
01149 }
01150 
01151 <font class="comment">/************************************************************************/</font>
01152 <font class="comment">/*                            GDALDecToDMS()                            */</font>
01153 <font class="comment">/*                                                                      */</font>
01154 <font class="comment">/*      Translate a decimal degrees value to a DMS string with          */</font>
01155 <font class="comment">/*      hemisphere.                                                     */</font>
01156 <font class="comment">/************************************************************************/</font>
01157 
01158 <font class="keyword">const</font> <font class="keywordtype">char</font> *GDALDecToDMS( <font class="keywordtype">double</font> dfAngle, <font class="keyword">const</font> <font class="keywordtype">char</font> * pszAxis,
01159                           <font class="keywordtype">int</font> nPrecision )<font class="keyword"></font>
01160 <font class="keyword"></font>
01161 <font class="keyword"></font>{
01162     <font class="keywordtype">int</font>         nDegrees, nMinutes;
01163     <font class="keywordtype">double</font>      dfSeconds;
01164     <font class="keywordtype">char</font>        szFormat[30];
01165     <font class="keyword">static</font> <font class="keywordtype">char</font> szBuffer[50];
01166     <font class="keyword">const</font> <font class="keywordtype">char</font>  *pszHemisphere;
01167     
01168 
01169     nDegrees = (<font class="keywordtype">int</font>) ABS(dfAngle);
01170     nMinutes = (<font class="keywordtype">int</font>) ((ABS(dfAngle) - nDegrees) * 60);
01171     dfSeconds = (ABS(dfAngle) * 3600 - nDegrees*3600 - nMinutes*60);
01172 
01173     <font class="keywordflow">if</font>( EQUAL(pszAxis,<font class="stringliteral">"Long"</font>) &amp;&amp; dfAngle &lt; 0.0 )
01174         pszHemisphere = <font class="stringliteral">"W"</font>;
01175     <font class="keywordflow">else</font> <font class="keywordflow">if</font>( EQUAL(pszAxis,<font class="stringliteral">"Long"</font>) )
01176         pszHemisphere = <font class="stringliteral">"E"</font>;
01177     <font class="keywordflow">else</font> <font class="keywordflow">if</font>( dfAngle &lt; 0.0 )
01178         pszHemisphere = <font class="stringliteral">"S"</font>;
01179     <font class="keywordflow">else</font>
01180         pszHemisphere = <font class="stringliteral">"N"</font>;
01181 
01182     sprintf( szFormat, <font class="stringliteral">"%%3dd%%2d\'%%.%df\"%s"</font>, nPrecision, pszHemisphere );
01183     sprintf( szBuffer, szFormat, nDegrees, nMinutes, dfSeconds );
01184 
01185     <font class="keywordflow">return</font>( szBuffer );
01186 }
01187 
01188 <font class="comment">/************************************************************************/</font>
01189 <font class="comment">/* -------------------------------------------------------------------- */</font>
01190 <font class="comment">/*      The following stubs are present to ensure that older GDAL       */</font>
01191 <font class="comment">/*      bridges don't fail with newer libraries.                        */</font>
01192 <font class="comment">/* -------------------------------------------------------------------- */</font>
01193 <font class="comment">/************************************************************************/</font>
01194 
01195 CPL_C_START
01196 
01197 <font class="keywordtype">void</font> *GDALCreateProjDef( <font class="keyword">const</font> <font class="keywordtype">char</font> * pszDef )<font class="keyword"></font>
01198 <font class="keyword"></font>{
01199     <a class="code" href="cpl_error_h.html#a29">CPLDebug</a>( <font class="stringliteral">"GDAL"</font>, <font class="stringliteral">"GDALCreateProjDef no longer supported."</font> );
01200     <font class="keywordflow">return</font> NULL;
01201 }
01202 
01203 CPLErr GDALReprojectToLongLat( <font class="keywordtype">void</font> *pDef, <font class="keywordtype">double</font> *, <font class="keywordtype">double</font> * )<font class="keyword"></font>
01204 <font class="keyword"></font>{
01205     <a class="code" href="cpl_error_h.html#a29">CPLDebug</a>( <font class="stringliteral">"GDAL"</font>, <font class="stringliteral">"GDALReprojectToLatLong no longer supported."</font> );
01206     <font class="keywordflow">return</font> CE_Failure;
01207 }
01208 
01209 CPLErr GDALReprojectFromLongLat( <font class="keywordtype">void</font> *pDef, <font class="keywordtype">double</font> *, <font class="keywordtype">double</font> * )<font class="keyword"></font>
01210 <font class="keyword"></font>{
01211     <a class="code" href="cpl_error_h.html#a29">CPLDebug</a>( <font class="stringliteral">"GDAL"</font>, <font class="stringliteral">"GDALReprojectFromLatLong no longer supported."</font> );
01212     <font class="keywordflow">return</font> CE_Failure;
01213 }
01214 
01215 <font class="keywordtype">void</font> GDALDestroyProjDef( <font class="keywordtype">void</font> *pDef )<font class="keyword"></font>
01216 <font class="keyword"></font>
01217 <font class="keyword"></font>{
01218     <a class="code" href="cpl_error_h.html#a29">CPLDebug</a>( <font class="stringliteral">"GDAL"</font>, <font class="stringliteral">"GDALDestroyProjDef no longer supported."</font> );
01219 }
01220 
01221 CPL_C_END
</div></pre><hr><address><small>Generated at Thu Mar 28 09:47:29 2002 for GDAL by
<a href="http://www.stack.nl/~dimitri/doxygen/index.html">
<img src="doxygen.gif" alt="doxygen" align="middle" border=0 
width=110 height=53></a>1.2.3-20001105 written by <a href="mailto:dimitri@stack.nl">Dimitri van Heesch</a>,
 &copy;&nbsp;1997-2000</small></address>
</body>
</html>