Inside gdalallregister 3: register the specified driver

Source: Internet
Author: User

Now let's take a closer look at how to register a driver code and look at the following code:

#ifdef FRMT_vrt    GDALRegister_VRT();#endif   

You can specify or cancel frmt_vrt during compilation to control whether the statement is compiled into an executable program. When using the VC ++ compiler on Windows, you can modify the extraflags value of the frmts/makefile. VC file, for example:

EXTRAFLAGS  =-DFRMT_nitf -DFRMT_gtiff -DFRMT_jpeg

Therefore, my program only registers these three drivers.

Now let's see how the registration function is implemented internally. Quickly read the code of the void gdalregister_gtiff () function. It mainly creates a gdaldriver object, sets attributes, and CALLS getgdaldrivermanager ()-> registerdriver (podriver) to add it. So now you can answer What register is. Create a driver object for each driver and add it to the singleton object gdaldrivermanager.

Note that the class declaration of gdaldrivermanger is in the gdal_priv.h file. The dual pointer is used to save all the driver pointers to facilitate access like an array, and the <key, value> the map of the structure also saves the driver pointer to facilitate string search.

class CPL_DLL GDALDriverManager : public GDALMajorObject{    int         nDrivers;    GDALDriver  **papoDrivers;    char        *pszHome;    typedef std::map<CPLString, GDALDriver *> NameDriverMap;    NameDriverMap m_NameDriverMap;

The function comments of gdal are all written in the CPP file, which is good. I have always wanted to do this, so it is convenient to maintain the Code, without the need to skip the file.

Int gdaldrivermanager: registerdriver (gdaldriver * podriver) function code implementation is not complex, that is, it is stored in the container.

The big algorithm is so simple. Now let's take a closer look at what value is stored in the driver. The code:

        poDriver->SetDescription( "GTiff" );        poDriver->SetMetadataItem( GDAL_DMD_LONGNAME, "GeoTIFF" );        poDriver->SetMetadataItem( GDAL_DMD_HELPTOPIC, "frmt_gtiff.html" );        poDriver->SetMetadataItem( GDAL_DMD_MIMETYPE, "image/tiff" );        poDriver->SetMetadataItem( GDAL_DMD_EXTENSION, "tif" );        poDriver->SetMetadataItem( GDAL_DMD_CREATIONDATATYPES,                                    "Byte UInt16 Int16 UInt32 Int32 Float32 "                                   "Float64 CInt16 CInt32 CFloat32 CFloat64" );        poDriver->SetMetadataItem( GDAL_DMD_CREATIONOPTIONLIST,                                    szCreateOptions );        poDriver->SetMetadataItem( GDAL_DCAP_VIRTUALIO, "YES" );        poDriver->pfnOpen = GTiffDataset::Open;        poDriver->pfnCreate = GTiffDataset::Create;        poDriver->pfnCreateCopy = GTiffDataset::CreateCopy;        poDriver->pfnUnloadDriver = GDALDeregister_GTiff;        poDriver->pfnIdentify = GTiffDataset::Identify;

The previous part sets metadata, and the important thing is szcreateoptions. This is an XML string with a lot of information. You can understand the meaning of this string only when you understand the gtiff format. The value of szcreateoptions used in my program will be posted at the end of this article.

Then, you can set some function pointers, including open, create, and createcopy.

<CreationOptionList>  <Option name="COMPRESS" type="string-select">    <Value>NONE</Value>     <Value>LZW</Value>     <Value>PACKBITS</Value>     <Value>JPEG</Value>     <Value>CCITTRLE</Value>     <Value>CCITTFAX3</Value>     <Value>CCITTFAX4</Value>     <Value>DEFLATE</Value>   </Option>  <Option name="PREDICTOR" type="int" description="Predictor Type" />   <Option name="JPEG_QUALITY" type="int" description="JPEG quality 1-100" default="75" />   <Option name="ZLEVEL" type="int" description="DEFLATE compression level 1-9" default="6" />   <Option name="NBITS" type="int" description="BITS for sub-byte files (1-7), sub-uint16 (9-15), sub-uint32 (17-31)" />   <Option name="INTERLEAVE" type="string-select" default="PIXEL">    <Value>BAND</Value>     <Value>PIXEL</Value>   </Option>  <Option name="TILED" type="boolean" description="Switch to tiled format" />   <Option name="TFW" type="boolean" description="Write out world file" />   <Option name="RPB" type="boolean" description="Write out .RPB (RPC) file" />   <Option name="BLOCKXSIZE" type="int" description="Tile Width" />   <Option name="BLOCKYSIZE" type="int" description="Tile/Strip Height" />   <Option name="PHOTOMETRIC" type="string-select">    <Value>MINISBLACK</Value>     <Value>MINISWHITE</Value>     <Value>PALETTE</Value>     <Value>RGB</Value>     <Value>CMYK</Value>     <Value>YCBCR</Value>     <Value>CIELAB</Value>     <Value>ICCLAB</Value>     <Value>ITULAB</Value>   </Option>  <Option name="SPARSE_OK" type="boolean" description="Can newly created files have missing blocks?" default="FALSE" />   <Option name="ALPHA" type="boolean" description="Mark first extrasample as being alpha" />   <Option name="PROFILE" type="string-select" default="GDALGeoTIFF">    <Value>GDALGeoTIFF</Value>     <Value>GeoTIFF</Value>     <Value>BASELINE</Value>   </Option>  <Option name="PIXELTYPE" type="string-select">    <Value>DEFAULT</Value>     <Value>SIGNEDBYTE</Value>   </Option>  <Option name="BIGTIFF" type="string-select" description="Force creation of BigTIFF file">    <Value>YES</Value>     <Value>NO</Value>     <Value>IF_NEEDED</Value>     <Value>IF_SAFER</Value>   </Option>  <Option name="ENDIANNESS" type="string-select" default="NATIVE" description="Force endianness of created file. For DEBUG purpose mostly">    <Value>NATIVE</Value>     <Value>INVERTED</Value>     <Value>LITTLE</Value>     <Value>BIG</Value>   </Option>  <Option name="COPY_SRC_OVERVIEWS" type="boolean" default="NO" description="Force copy of overviews of source dataset (CreateCopy())" /> </CreationOptionList>

Contact Us

The content source of this page is from Internet, which doesn't represent Alibaba Cloud's opinion; products and services mentioned on that page don't have any relationship with Alibaba Cloud. If the content of the page makes you feel confusing, please write us an email, we will handle the problem within 5 days after receiving your email.

If you find any instances of plagiarism from the community, please send an email to: info-contact@alibabacloud.com and provide relevant evidence. A staff member will contact you within 5 working days.

A Free Trial That Lets You Build Big!

Start building with 50+ products and up to 12 months usage for Elastic Compute Service

  • Sales Support

    1 on 1 presale consultation

  • After-Sales Support

    24/7 Technical Support 6 Free Tickets per Quarter Faster Response

  • Alibaba Cloud offers highly flexible support services tailored to meet your exact needs.