Sophie

Sophie

distrib > Fedora > 13 > i386 > by-pkgid > 7fd7c575020aa78a8e2e309ea8909f43 > files > 601

gdal-1.6.2-6.fc13.i686.rpm

<!DOCTYPE html PUBLIC "-//W3C//DTD XHTML 1.0 Transitional//EN" "http://www.w3.org/TR/xhtml1/DTD/xhtml1-transitional.dtd">
<html xmlns="http://www.w3.org/1999/xhtml">
<head>
<meta http-equiv="Content-Type" content="text/xhtml;charset=UTF-8"/>
<title>SDTS_AL: </title>
<link href="tabs.css" rel="stylesheet" type="text/css"/>
<link href="doxygen.css" rel="stylesheet" type="text/css"/>
</head>
<body>
<!-- Generated by Doxygen 1.6.2-20100208 -->
<div class="navigation" id="top">
  <div class="tabs">
    <ul>
      <li><a href="index.html"><span>Main&nbsp;Page</span></a></li>
      <li class="current"><a href="pages.html"><span>Related&nbsp;Pages</span></a></li>
      <li><a href="annotated.html"><span>Classes</span></a></li>
      <li><a href="files.html"><span>Files</span></a></li>
    </ul>
  </div>
</div>
<div class="contents">
<center> &lt;title&gt;SDTS To Shape Example Application&lt;/title&gt; </center><div class="fragment"><pre class="fragment"><span class="comment">/* ****************************************************************************</span>
<span class="comment"> * $Id: sdts2shp.cpp 10645 2007-01-18 02:22:39Z warmerdam $</span>
<span class="comment"> *</span>
<span class="comment"> * Project:  SDTS Translator</span>
<span class="comment"> * Purpose:  Mainline for converting to ArcView Shapefiles.</span>
<span class="comment"> * Author:   Frank Warmerdam, warmerdam@pobox.com</span>
<span class="comment"> *</span>
<span class="comment"> ******************************************************************************</span>
<span class="comment"> * Copyright (c) 1999, Frank Warmerdam</span>
<span class="comment"> *</span>
<span class="comment"> * Permission is hereby granted, free of charge, to any person obtaining a</span>
<span class="comment"> * copy of this software and associated documentation files (the &quot;Software&quot;),</span>
<span class="comment"> * to deal in the Software without restriction, including without limitation</span>
<span class="comment"> * the rights to use, copy, modify, merge, publish, distribute, sublicense,</span>
<span class="comment"> * and/or sell copies of the Software, and to permit persons to whom the</span>
<span class="comment"> * Software is furnished to do so, subject to the following conditions:</span>
<span class="comment"> *</span>
<span class="comment"> * The above copyright notice and this permission notice shall be included</span>
<span class="comment"> * in all copies or substantial portions of the Software.</span>
<span class="comment"> *</span>
<span class="comment"> * THE SOFTWARE IS PROVIDED &quot;AS IS&quot;, WITHOUT WARRANTY OF ANY KIND, EXPRESS</span>
<span class="comment"> * OR IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,</span>
<span class="comment"> * FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL</span>
<span class="comment"> * THE AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER</span>
<span class="comment"> * LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING</span>
<span class="comment"> * FROM, OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER</span>
<span class="comment"> * DEALINGS IN THE SOFTWARE.</span>
<span class="comment"> ****************************************************************************/</span>

<span class="preprocessor">#include &quot;sdts_al.h&quot;</span>
<span class="preprocessor">#include &quot;shapefil.h&quot;</span>
<span class="preprocessor">#include &quot;<a class="code" href="cpl__string_8h.html">cpl_string.h</a>&quot;</span>

CPL_CVSID(<span class="stringliteral">&quot;$Id: sdts2shp.cpp 10645 2007-01-18 02:22:39Z warmerdam $&quot;</span>);

<span class="keyword">static</span> <span class="keywordtype">int</span>  bVerbose = FALSE;

<span class="keyword">static</span> <span class="keywordtype">void</span> WriteLineShapefile( <span class="keyword">const</span> <span class="keywordtype">char</span> *, <a class="code" href="classSDTSTransfer.html">SDTSTransfer</a> *,
                                <span class="keyword">const</span> <span class="keywordtype">char</span> * );
<span class="keyword">static</span> <span class="keywordtype">void</span> WritePointShapefile( <span class="keyword">const</span> <span class="keywordtype">char</span> *, <a class="code" href="classSDTSTransfer.html">SDTSTransfer</a> *,
                                 <span class="keyword">const</span> <span class="keywordtype">char</span> * );
<span class="keyword">static</span> <span class="keywordtype">void</span> WriteAttributeDBF( <span class="keyword">const</span> <span class="keywordtype">char</span> *, <a class="code" href="classSDTSTransfer.html">SDTSTransfer</a> *,
                               <span class="keyword">const</span> <span class="keywordtype">char</span> * );
<span class="keyword">static</span> <span class="keywordtype">void</span> WritePolygonShapefile( <span class="keyword">const</span> <span class="keywordtype">char</span> *, <a class="code" href="classSDTSTransfer.html">SDTSTransfer</a> *, 
                                   <span class="keyword">const</span> <span class="keywordtype">char</span> * );

<span class="keyword">static</span> <span class="keywordtype">void</span>
AddPrimaryAttrToDBFSchema( DBFHandle hDBF, <a class="code" href="classSDTSTransfer.html">SDTSTransfer</a> * poTransfer,
                           <span class="keywordtype">char</span> ** papszModuleList );
<span class="keyword">static</span> <span class="keywordtype">void</span>
WritePrimaryAttrToDBF( DBFHandle hDBF, <span class="keywordtype">int</span> nRecord, 
                       <a class="code" href="classSDTSTransfer.html">SDTSTransfer</a> *, <a class="code" href="classSDTSFeature.html">SDTSFeature</a> * poFeature );
<span class="keyword">static</span> <span class="keywordtype">void</span>
WriteAttrRecordToDBF( DBFHandle hDBF, <span class="keywordtype">int</span> nRecord, 
                      <a class="code" href="classSDTSTransfer.html">SDTSTransfer</a> *, <a class="code" href="classDDFField.html">DDFField</a> * poAttributes );

<span class="comment">/* **********************************************************************/</span>
<span class="comment">/*                               Usage()                                */</span>
<span class="comment">/* **********************************************************************/</span>

<span class="keyword">static</span> <span class="keywordtype">void</span> Usage()

{
    printf( <span class="stringliteral">&quot;Usage: sdts2shp CATD_filename [-o shapefile_name]\n&quot;</span>
            <span class="stringliteral">&quot;                [-m module_name] [-v]\n&quot;</span>
            <span class="stringliteral">&quot;\n&quot;</span>
            <span class="stringliteral">&quot;Modules include `LE01&#39;, `PC01&#39;, `NP01&#39; and `ARDF&#39;\n&quot;</span> );
    
    exit( 1 );
}

<span class="comment">/* **********************************************************************/</span>
<span class="comment">/*                                main()                                */</span>
<span class="comment">/* **********************************************************************/</span>

<span class="keywordtype">int</span> main( <span class="keywordtype">int</span> nArgc, <span class="keywordtype">char</span> ** papszArgv )

{
{
    <span class="keywordtype">int</span>         i;
    <span class="keyword">const</span> <span class="keywordtype">char</span>  *pszCATDFilename = NULL;
    <span class="keyword">const</span> <span class="keywordtype">char</span>  *pszMODN = <span class="stringliteral">&quot;LE01&quot;</span>;
    <span class="keywordtype">char</span>        *pszShapefile = <span class="stringliteral">&quot;sdts_out.shp&quot;</span>;
    <a class="code" href="classSDTSTransfer.html">SDTSTransfer</a> oTransfer;
   

<span class="comment">/* -------------------------------------------------------------------- */</span>
<span class="comment">/*      Interpret commandline switches.                                 */</span>
<span class="comment">/* -------------------------------------------------------------------- */</span>
    <span class="keywordflow">if</span>( nArgc &lt; 2 )
        Usage();

    pszCATDFilename = papszArgv[1];

    <span class="keywordflow">for</span>( i = 2; i &lt; nArgc; i++ )
    {
        <span class="keywordflow">if</span>( EQUAL(papszArgv[i],<span class="stringliteral">&quot;-m&quot;</span>) &amp;&amp; i+1 &lt; nArgc )
            pszMODN = papszArgv[++i];
        <span class="keywordflow">else</span> <span class="keywordflow">if</span>( EQUAL(papszArgv[i],<span class="stringliteral">&quot;-o&quot;</span>) &amp;&amp; i+1 &lt; nArgc )
            pszShapefile = papszArgv[++i];
        <span class="keywordflow">else</span> <span class="keywordflow">if</span>( EQUAL(papszArgv[i],<span class="stringliteral">&quot;-v&quot;</span>) )
            bVerbose = TRUE;
        <span class="keywordflow">else</span>
        {
            printf( <span class="stringliteral">&quot;Incomplete, or unsupported option `%s&#39;\n\n&quot;</span>,
                    papszArgv[i] );
            Usage();
        }
    }

<span class="comment">/* -------------------------------------------------------------------- */</span>
<span class="comment">/*      Massage shapefile name to have no extension.                    */</span>
<span class="comment">/* -------------------------------------------------------------------- */</span>
    pszShapefile = strdup( pszShapefile );
    <span class="keywordflow">for</span>( i = strlen(pszShapefile)-1; i &gt;= 0; i-- )
    {
        <span class="keywordflow">if</span>( pszShapefile[i] == <span class="charliteral">&#39;.&#39;</span> )
        {
            pszShapefile[i] = <span class="charliteral">&#39;\0&#39;</span>;
            <span class="keywordflow">break</span>;
        }
        <span class="keywordflow">else</span> <span class="keywordflow">if</span>( pszShapefile[i] == <span class="charliteral">&#39;/&#39;</span> || pszShapefile[i] == <span class="charliteral">&#39;\\&#39;</span> )
            <span class="keywordflow">break</span>;
    }

<span class="comment">/* -------------------------------------------------------------------- */</span>
<span class="comment">/*      Open the transfer.                                              */</span>
<span class="comment">/* -------------------------------------------------------------------- */</span>
    <span class="keywordflow">if</span>( !oTransfer.<a class="code" href="classSDTSTransfer.html#a6aa55051a8c6baa8c24764f0d5e7c279">Open</a>( pszCATDFilename ) )
    {
        fprintf( stderr,
                 <span class="stringliteral">&quot;Failed to read CATD file `%s&#39;\n&quot;</span>,
                 pszCATDFilename );
        exit( 100 );
    }

<span class="comment">/* -------------------------------------------------------------------- */</span>
<span class="comment">/*      Dump available layer in verbose mode.                           */</span>
<span class="comment">/* -------------------------------------------------------------------- */</span>
    <span class="keywordflow">if</span>( bVerbose )
    {
        printf( <span class="stringliteral">&quot;Layers:\n&quot;</span> );
        <span class="keywordflow">for</span>( i = 0; i &lt; oTransfer.GetLayerCount(); i++ )
        {
            <span class="keywordtype">int</span>         iCATDEntry = oTransfer.<a class="code" href="classSDTSTransfer.html#a8a161e795535c6baae7583535f9da7c8">GetLayerCATDEntry</a>(i);
            
            printf( <span class="stringliteral">&quot;  %s: `%s&#39;\n&quot;</span>,
                    oTransfer.<a class="code" href="classSDTSTransfer.html#aea48d5c34a76fec1fb347dbf9d59d9e5">GetCATD</a>()-&gt;GetEntryModule(iCATDEntry),
                    oTransfer.<a class="code" href="classSDTSTransfer.html#aea48d5c34a76fec1fb347dbf9d59d9e5">GetCATD</a>()-&gt;<a class="code" href="classSDTS__CATD.html#aaf182655b4e1a35c8d479c38909e73ae">GetEntryTypeDesc</a>(iCATDEntry) );
        }
        printf( <span class="stringliteral">&quot;\n&quot;</span> );
    }

<span class="comment">/* -------------------------------------------------------------------- */</span>
<span class="comment">/*      Check that module exists.                                       */</span>
<span class="comment">/* -------------------------------------------------------------------- */</span>
    <span class="keywordflow">if</span>( oTransfer.<a class="code" href="classSDTSTransfer.html#a7161e78c4e3aef778251231bfc95106e">FindLayer</a>( pszMODN ) == -1 )
    {
        fprintf( stderr, <span class="stringliteral">&quot;Unable to identify module: %s\n&quot;</span>, pszMODN );
        exit( 1 );
    }

<span class="comment">/* -------------------------------------------------------------------- */</span>
<span class="comment">/*      If the module is an LE module, write it to an Arc file.         */</span>
<span class="comment">/* -------------------------------------------------------------------- */</span>
    <span class="keywordflow">if</span>( pszMODN[0] == <span class="charliteral">&#39;L&#39;</span> || pszMODN[0] == <span class="charliteral">&#39;l&#39;</span> )
    {
        WriteLineShapefile( pszShapefile, &amp;oTransfer, pszMODN );
    }

<span class="comment">/* -------------------------------------------------------------------- */</span>
<span class="comment">/*      If the module is an attribute primary one, dump to DBF.         */</span>
<span class="comment">/* -------------------------------------------------------------------- */</span>
    <span class="keywordflow">else</span> <span class="keywordflow">if</span>( pszMODN[0] == <span class="charliteral">&#39;A&#39;</span> || pszMODN[0] == <span class="charliteral">&#39;a&#39;</span> 
             || pszMODN[0] == <span class="charliteral">&#39;B&#39;</span> || pszMODN[0] == <span class="charliteral">&#39;b&#39;</span> ) 
    {
        WriteAttributeDBF( pszShapefile, &amp;oTransfer, pszMODN );
    }

<span class="comment">/* -------------------------------------------------------------------- */</span>
<span class="comment">/*      If the module is a point one, dump to Shapefile.                */</span>
<span class="comment">/* -------------------------------------------------------------------- */</span>
    <span class="keywordflow">else</span> <span class="keywordflow">if</span>( pszMODN[0] == <span class="charliteral">&#39;N&#39;</span> || pszMODN[0] == <span class="charliteral">&#39;N&#39;</span> )
    {
        WritePointShapefile( pszShapefile, &amp;oTransfer, pszMODN );
    }

<span class="comment">/* -------------------------------------------------------------------- */</span>
<span class="comment">/*      If the module is a polygon one, dump to Shapefile.              */</span>
<span class="comment">/* -------------------------------------------------------------------- */</span>
    <span class="keywordflow">else</span> <span class="keywordflow">if</span>( pszMODN[0] == <span class="charliteral">&#39;P&#39;</span> || pszMODN[0] == <span class="charliteral">&#39;p&#39;</span> )
    {
        WritePolygonShapefile( pszShapefile, &amp;oTransfer, pszMODN );
    }

    <span class="keywordflow">else</span>
    {
        fprintf( stderr, <span class="stringliteral">&quot;Unrecognised module name: %s\n&quot;</span>, pszMODN );
    }

    CPLFree( pszShapefile );
}    
<span class="preprocessor">#ifdef DBMALLOC</span>
<span class="preprocessor"></span>    malloc_dump(1);
<span class="preprocessor">#endif</span>
<span class="preprocessor"></span>}

<span class="comment">/* **********************************************************************/</span>
<span class="comment">/*                         WriteLineShapefile()                         */</span>
<span class="comment">/* **********************************************************************/</span>

<span class="keyword">static</span> <span class="keywordtype">void</span> WriteLineShapefile( <span class="keyword">const</span> <span class="keywordtype">char</span> * pszShapefile,
                                <a class="code" href="classSDTSTransfer.html">SDTSTransfer</a> * poTransfer,
                                <span class="keyword">const</span> <span class="keywordtype">char</span> * pszMODN )

{
    <a class="code" href="classSDTSLineReader.html">SDTSLineReader</a>      *poLineReader;
    
<span class="comment">/* -------------------------------------------------------------------- */</span>
<span class="comment">/*      Fetch a reference to the indexed Pointgon reader.                */</span>
<span class="comment">/* -------------------------------------------------------------------- */</span>
    poLineReader = (<a class="code" href="classSDTSLineReader.html">SDTSLineReader</a> *) 
        poTransfer-&gt;<a class="code" href="classSDTSTransfer.html#a028d3ec2c7b3bcc719137e632b907ca3">GetLayerIndexedReader</a>( poTransfer-&gt;<a class="code" href="classSDTSTransfer.html#a7161e78c4e3aef778251231bfc95106e">FindLayer</a>( pszMODN ) );
    
    <span class="keywordflow">if</span>( poLineReader == NULL )
    {
        fprintf( stderr, <span class="stringliteral">&quot;Failed to open %s.\n&quot;</span>,
                 poTransfer-&gt;<a class="code" href="classSDTSTransfer.html#aea48d5c34a76fec1fb347dbf9d59d9e5">GetCATD</a>()-&gt;GetModuleFilePath( pszMODN ) );
        <span class="keywordflow">return</span>;
    }

    poLineReader-&gt;<a class="code" href="classSDTSIndexedReader.html#a2c6df4e9ddb8ef56529c8055e766548e">Rewind</a>();

<span class="comment">/* -------------------------------------------------------------------- */</span>
<span class="comment">/*      Create the Shapefile.                                           */</span>
<span class="comment">/* -------------------------------------------------------------------- */</span>
    SHPHandle   hSHP;

    hSHP = SHPCreate( pszShapefile, SHPT_ARC );
    <span class="keywordflow">if</span>( hSHP == NULL )
    {
        fprintf( stderr, <span class="stringliteral">&quot;Unable to create shapefile `%s&#39;\n&quot;</span>,
                 pszShapefile );
        <span class="keywordflow">return</span>;
    }

<span class="comment">/* -------------------------------------------------------------------- */</span>
<span class="comment">/*      Create the database file, and our basic set of attributes.      */</span>
<span class="comment">/* -------------------------------------------------------------------- */</span>
    DBFHandle   hDBF;
    <span class="keywordtype">int</span>         nLeftPolyField, nRightPolyField;
    <span class="keywordtype">int</span>         nStartNodeField, nEndNodeField, nSDTSRecordField;
    <span class="keywordtype">char</span>        szDBFFilename[1024];

    sprintf( szDBFFilename, <span class="stringliteral">&quot;%s.dbf&quot;</span>, pszShapefile );

    hDBF = DBFCreate( szDBFFilename );
    <span class="keywordflow">if</span>( hDBF == NULL )
    {
        fprintf( stderr, <span class="stringliteral">&quot;Unable to create shapefile .dbf for `%s&#39;\n&quot;</span>,
                 pszShapefile );
        <span class="keywordflow">return</span>;
    }

    nSDTSRecordField = DBFAddField( hDBF, <span class="stringliteral">&quot;SDTSRecId&quot;</span>, FTInteger, 8, 0 );
    nLeftPolyField = DBFAddField( hDBF, <span class="stringliteral">&quot;LeftPoly&quot;</span>, FTString, 12, 0 );
    nRightPolyField = DBFAddField( hDBF, <span class="stringliteral">&quot;RightPoly&quot;</span>, FTString, 12, 0 );
    nStartNodeField = DBFAddField( hDBF, <span class="stringliteral">&quot;StartNode&quot;</span>, FTString, 12, 0 );
    nEndNodeField = DBFAddField( hDBF, <span class="stringliteral">&quot;EndNode&quot;</span>, FTString, 12, 0 );

    <span class="keywordtype">char</span>  **papszModRefs = poLineReader-&gt;<a class="code" href="classSDTSIndexedReader.html#a4bc517f41916afab133cfadc01568b12">ScanModuleReferences</a>();
    AddPrimaryAttrToDBFSchema( hDBF, poTransfer, papszModRefs );
    CSLDestroy( papszModRefs );
    
<span class="comment">/* ==================================================================== */</span>
<span class="comment">/*      Process all the line features in the module.                    */</span>
<span class="comment">/* ==================================================================== */</span>
    <a class="code" href="classSDTSRawLine.html">SDTSRawLine</a> *poRawLine;
        
    <span class="keywordflow">while</span>( (poRawLine = poLineReader-&gt;GetNextLine()) != NULL )
    {
        <span class="keywordtype">int</span>             iShape;
        
<span class="comment">/* -------------------------------------------------------------------- */</span>
<span class="comment">/*      Write out a shape with the vertices.                            */</span>
<span class="comment">/* -------------------------------------------------------------------- */</span>
        SHPObject       *psShape;

        psShape = SHPCreateSimpleObject( SHPT_ARC, poRawLine-&gt;<a class="code" href="classSDTSRawLine.html#a72862b7f33aa3c2d8bcdb8fd10ddb08f">nVertices</a>,
                                         poRawLine-&gt;<a class="code" href="classSDTSRawLine.html#a92d7e25050ef1805437d08b4c1c8ed01">padfX</a>, poRawLine-&gt;<a class="code" href="classSDTSRawLine.html#acd228dec9203c3630dfd7dfbe8d3a5bf">padfY</a>,
                                         poRawLine-&gt;<a class="code" href="classSDTSRawLine.html#a4c77082a7332bdfa0579721dc5d31d2a">padfZ</a> );

        iShape = SHPWriteObject( hSHP, -1, psShape );

        SHPDestroyObject( psShape );

<span class="comment">/* -------------------------------------------------------------------- */</span>
<span class="comment">/*      Write out the attributes.                                       */</span>
<span class="comment">/* -------------------------------------------------------------------- */</span>
        <span class="keywordtype">char</span>    szID[13];

        DBFWriteIntegerAttribute( hDBF, iShape, nSDTSRecordField,
                                  poRawLine-&gt;<a class="code" href="classSDTSFeature.html#ab66b82d3476e99c450fa6f485d4ae44f">oModId</a>.<a class="code" href="classSDTSModId.html#ae427a43cfae8b2ceb1ad077a948a07fa">nRecord</a> );
        
        sprintf( szID, <span class="stringliteral">&quot;%s:%ld&quot;</span>,
                 poRawLine-&gt;<a class="code" href="classSDTSRawLine.html#a711b3ab4bd6eb441d38e0ca9cbe17c34">oLeftPoly</a>.<a class="code" href="classSDTSModId.html#a34c509529df3af8c5fa931f6fdf35747">szModule</a>,
                 poRawLine-&gt;<a class="code" href="classSDTSRawLine.html#a711b3ab4bd6eb441d38e0ca9cbe17c34">oLeftPoly</a>.<a class="code" href="classSDTSModId.html#ae427a43cfae8b2ceb1ad077a948a07fa">nRecord</a> );
        DBFWriteStringAttribute( hDBF, iShape, nLeftPolyField, szID );

        sprintf( szID, <span class="stringliteral">&quot;%s:%ld&quot;</span>,
                 poRawLine-&gt;<a class="code" href="classSDTSRawLine.html#a943b8ef6fc95400dcf9a18138e52c027">oRightPoly</a>.<a class="code" href="classSDTSModId.html#a34c509529df3af8c5fa931f6fdf35747">szModule</a>,
                 poRawLine-&gt;<a class="code" href="classSDTSRawLine.html#a943b8ef6fc95400dcf9a18138e52c027">oRightPoly</a>.<a class="code" href="classSDTSModId.html#ae427a43cfae8b2ceb1ad077a948a07fa">nRecord</a> );
        DBFWriteStringAttribute( hDBF, iShape, nRightPolyField, szID );

        sprintf( szID, <span class="stringliteral">&quot;%s:%ld&quot;</span>,
                 poRawLine-&gt;<a class="code" href="classSDTSRawLine.html#a2ea525f5ad1f425a197edbe675124a79">oStartNode</a>.<a class="code" href="classSDTSModId.html#a34c509529df3af8c5fa931f6fdf35747">szModule</a>,
                 poRawLine-&gt;<a class="code" href="classSDTSRawLine.html#a2ea525f5ad1f425a197edbe675124a79">oStartNode</a>.<a class="code" href="classSDTSModId.html#ae427a43cfae8b2ceb1ad077a948a07fa">nRecord</a> );
        DBFWriteStringAttribute( hDBF, iShape, nStartNodeField, szID );

        sprintf( szID, <span class="stringliteral">&quot;%s:%ld&quot;</span>,
                 poRawLine-&gt;<a class="code" href="classSDTSRawLine.html#a42cfb6a4e2f895e304c307d9e6270cd0">oEndNode</a>.<a class="code" href="classSDTSModId.html#a34c509529df3af8c5fa931f6fdf35747">szModule</a>,
                 poRawLine-&gt;<a class="code" href="classSDTSRawLine.html#a42cfb6a4e2f895e304c307d9e6270cd0">oEndNode</a>.<a class="code" href="classSDTSModId.html#ae427a43cfae8b2ceb1ad077a948a07fa">nRecord</a> );
        DBFWriteStringAttribute( hDBF, iShape, nEndNodeField, szID );

        WritePrimaryAttrToDBF( hDBF, iShape, poTransfer, poRawLine );

        <span class="keywordflow">if</span>( !poLineReader-&gt;<a class="code" href="classSDTSIndexedReader.html#ac2f097b0ba6e558c4d9e35bf0bc08d4f">IsIndexed</a>() )
            <span class="keyword">delete</span> poRawLine;
    }

<span class="comment">/* -------------------------------------------------------------------- */</span>
<span class="comment">/*      Close, and cleanup.                                             */</span>
<span class="comment">/* -------------------------------------------------------------------- */</span>
    DBFClose( hDBF );
    SHPClose( hSHP );
}    

<span class="comment">/* **********************************************************************/</span>
<span class="comment">/*                        WritePointShapefile()                         */</span>
<span class="comment">/* **********************************************************************/</span>

<span class="keyword">static</span> <span class="keywordtype">void</span> WritePointShapefile( <span class="keyword">const</span> <span class="keywordtype">char</span> * pszShapefile,
                                 <a class="code" href="classSDTSTransfer.html">SDTSTransfer</a> * poTransfer,
                                 <span class="keyword">const</span> <span class="keywordtype">char</span> * pszMODN )

{
    <a class="code" href="classSDTSPointReader.html">SDTSPointReader</a>     *poPointReader;

<span class="comment">/* -------------------------------------------------------------------- */</span>
<span class="comment">/*      Fetch a reference to the indexed Pointgon reader.                */</span>
<span class="comment">/* -------------------------------------------------------------------- */</span>
    poPointReader = (<a class="code" href="classSDTSPointReader.html">SDTSPointReader</a> *) 
        poTransfer-&gt;<a class="code" href="classSDTSTransfer.html#a028d3ec2c7b3bcc719137e632b907ca3">GetLayerIndexedReader</a>( poTransfer-&gt;<a class="code" href="classSDTSTransfer.html#a7161e78c4e3aef778251231bfc95106e">FindLayer</a>( pszMODN ) );
    
    <span class="keywordflow">if</span>( poPointReader == NULL )
    {
        fprintf( stderr, <span class="stringliteral">&quot;Failed to open %s.\n&quot;</span>,
                 poTransfer-&gt;<a class="code" href="classSDTSTransfer.html#aea48d5c34a76fec1fb347dbf9d59d9e5">GetCATD</a>()-&gt;GetModuleFilePath( pszMODN ) );
        <span class="keywordflow">return</span>;
    }

    poPointReader-&gt;<a class="code" href="classSDTSIndexedReader.html#a2c6df4e9ddb8ef56529c8055e766548e">Rewind</a>();

<span class="comment">/* -------------------------------------------------------------------- */</span>
<span class="comment">/*      Create the Shapefile.                                           */</span>
<span class="comment">/* -------------------------------------------------------------------- */</span>
    SHPHandle   hSHP;

    hSHP = SHPCreate( pszShapefile, SHPT_POINT );
    <span class="keywordflow">if</span>( hSHP == NULL )
    {
        fprintf( stderr, <span class="stringliteral">&quot;Unable to create shapefile `%s&#39;\n&quot;</span>,
                 pszShapefile );
        <span class="keywordflow">return</span>;
    }

<span class="comment">/* -------------------------------------------------------------------- */</span>
<span class="comment">/*      Create the database file, and our basic set of attributes.      */</span>
<span class="comment">/* -------------------------------------------------------------------- */</span>
    DBFHandle   hDBF;
    <span class="keywordtype">int</span>         nAreaField, nSDTSRecordField;
    <span class="keywordtype">char</span>        szDBFFilename[1024];

    sprintf( szDBFFilename, <span class="stringliteral">&quot;%s.dbf&quot;</span>, pszShapefile );

    hDBF = DBFCreate( szDBFFilename );
    <span class="keywordflow">if</span>( hDBF == NULL )
    {
        fprintf( stderr, <span class="stringliteral">&quot;Unable to create shapefile .dbf for `%s&#39;\n&quot;</span>,
                 pszShapefile );
        <span class="keywordflow">return</span>;
    }

    nSDTSRecordField = DBFAddField( hDBF, <span class="stringliteral">&quot;SDTSRecId&quot;</span>, FTInteger, 8, 0 );
    nAreaField = DBFAddField( hDBF, <span class="stringliteral">&quot;AreaId&quot;</span>, FTString, 12, 0 );
    
    <span class="keywordtype">char</span>  **papszModRefs = poPointReader-&gt;<a class="code" href="classSDTSIndexedReader.html#a4bc517f41916afab133cfadc01568b12">ScanModuleReferences</a>();
    AddPrimaryAttrToDBFSchema( hDBF, poTransfer, papszModRefs );
    CSLDestroy( papszModRefs );

<span class="comment">/* ==================================================================== */</span>
<span class="comment">/*      Process all the line features in the module.                    */</span>
<span class="comment">/* ==================================================================== */</span>
    <a class="code" href="classSDTSRawPoint.html">SDTSRawPoint</a>        *poRawPoint;
        
    <span class="keywordflow">while</span>( (poRawPoint = poPointReader-&gt;GetNextPoint()) != NULL )
    {
        <span class="keywordtype">int</span>             iShape;
        
<span class="comment">/* -------------------------------------------------------------------- */</span>
<span class="comment">/*      Write out a shape with the vertices.                            */</span>
<span class="comment">/* -------------------------------------------------------------------- */</span>
        SHPObject       *psShape;

        psShape = SHPCreateSimpleObject( SHPT_POINT, 1,
                                         &amp;(poRawPoint-&gt;<a class="code" href="classSDTSRawPoint.html#ae64d05f3515a718b0f37cc1aa4073fcf">dfX</a>),
                                         &amp;(poRawPoint-&gt;<a class="code" href="classSDTSRawPoint.html#a56583fff3cc18505192329b60ddc4df7">dfY</a>),
                                         &amp;(poRawPoint-&gt;<a class="code" href="classSDTSRawPoint.html#a4ae18aeea77d43e6818aa7e992c4d1ad">dfZ</a>) );

        iShape = SHPWriteObject( hSHP, -1, psShape );

        SHPDestroyObject( psShape );

<span class="comment">/* -------------------------------------------------------------------- */</span>
<span class="comment">/*      Write out the attributes.                                       */</span>
<span class="comment">/* -------------------------------------------------------------------- */</span>
        <span class="keywordtype">char</span>    szID[13];

        DBFWriteIntegerAttribute( hDBF, iShape, nSDTSRecordField,
                                  poRawPoint-&gt;<a class="code" href="classSDTSFeature.html#ab66b82d3476e99c450fa6f485d4ae44f">oModId</a>.<a class="code" href="classSDTSModId.html#ae427a43cfae8b2ceb1ad077a948a07fa">nRecord</a> );
        
        sprintf( szID, <span class="stringliteral">&quot;%s:%ld&quot;</span>,
                 poRawPoint-&gt;<a class="code" href="classSDTSRawPoint.html#a81ca008dc9fa72b1e84fa91e9b477559">oAreaId</a>.<a class="code" href="classSDTSModId.html#a34c509529df3af8c5fa931f6fdf35747">szModule</a>,
                 poRawPoint-&gt;<a class="code" href="classSDTSRawPoint.html#a81ca008dc9fa72b1e84fa91e9b477559">oAreaId</a>.<a class="code" href="classSDTSModId.html#ae427a43cfae8b2ceb1ad077a948a07fa">nRecord</a> );
        DBFWriteStringAttribute( hDBF, iShape, nAreaField, szID );

        WritePrimaryAttrToDBF( hDBF, iShape, poTransfer, poRawPoint );

        <span class="keywordflow">if</span>( !poPointReader-&gt;<a class="code" href="classSDTSIndexedReader.html#ac2f097b0ba6e558c4d9e35bf0bc08d4f">IsIndexed</a>() )
            <span class="keyword">delete</span> poRawPoint;
    }

<span class="comment">/* -------------------------------------------------------------------- */</span>
<span class="comment">/*      Close, and cleanup.                                             */</span>
<span class="comment">/* -------------------------------------------------------------------- */</span>
    DBFClose( hDBF );
    SHPClose( hSHP );
}    

<span class="comment">/* **********************************************************************/</span>
<span class="comment">/*                         WriteAttributeDBF()                          */</span>
<span class="comment">/* **********************************************************************/</span>

<span class="keyword">static</span> <span class="keywordtype">void</span> WriteAttributeDBF( <span class="keyword">const</span> <span class="keywordtype">char</span> * pszShapefile,
                               <a class="code" href="classSDTSTransfer.html">SDTSTransfer</a> * poTransfer,
                               <span class="keyword">const</span> <span class="keywordtype">char</span> * pszMODN )

{
    <a class="code" href="classSDTSAttrReader.html">SDTSAttrReader</a>      *poAttrReader;

<span class="comment">/* -------------------------------------------------------------------- */</span>
<span class="comment">/*      Fetch a reference to the indexed Pointgon reader.                */</span>
<span class="comment">/* -------------------------------------------------------------------- */</span>
    poAttrReader = (<a class="code" href="classSDTSAttrReader.html">SDTSAttrReader</a> *) 
        poTransfer-&gt;<a class="code" href="classSDTSTransfer.html#a028d3ec2c7b3bcc719137e632b907ca3">GetLayerIndexedReader</a>( poTransfer-&gt;<a class="code" href="classSDTSTransfer.html#a7161e78c4e3aef778251231bfc95106e">FindLayer</a>( pszMODN ) );
    
    <span class="keywordflow">if</span>( poAttrReader == NULL )
    {
        fprintf( stderr, <span class="stringliteral">&quot;Failed to open %s.\n&quot;</span>,
                 poTransfer-&gt;<a class="code" href="classSDTSTransfer.html#aea48d5c34a76fec1fb347dbf9d59d9e5">GetCATD</a>()-&gt;GetModuleFilePath( pszMODN ) );
        <span class="keywordflow">return</span>;
    }

    poAttrReader-&gt;<a class="code" href="classSDTSIndexedReader.html#a2c6df4e9ddb8ef56529c8055e766548e">Rewind</a>();

<span class="comment">/* -------------------------------------------------------------------- */</span>
<span class="comment">/*      Create the database file, and our basic set of attributes.      */</span>
<span class="comment">/* -------------------------------------------------------------------- */</span>
    DBFHandle   hDBF;
    <span class="keywordtype">char</span>        szDBFFilename[1024];

    sprintf( szDBFFilename, <span class="stringliteral">&quot;%s.dbf&quot;</span>, pszShapefile );

    hDBF = DBFCreate( szDBFFilename );
    <span class="keywordflow">if</span>( hDBF == NULL )
    {
        fprintf( stderr, <span class="stringliteral">&quot;Unable to create shapefile .dbf for `%s&#39;\n&quot;</span>,
                 pszShapefile );
        <span class="keywordflow">return</span>;
    }

    DBFAddField( hDBF, <span class="stringliteral">&quot;SDTSRecId&quot;</span>, FTInteger, 8, 0 );

<span class="comment">/* -------------------------------------------------------------------- */</span>
<span class="comment">/*      Prepare the schema.                                             */</span>
<span class="comment">/* -------------------------------------------------------------------- */</span>
    <span class="keywordtype">char</span>        **papszMODNList = CSLAddString( NULL, pszMODN );

    AddPrimaryAttrToDBFSchema( hDBF, poTransfer, papszMODNList );

    CSLDestroy( papszMODNList );
    
<span class="comment">/* ==================================================================== */</span>
<span class="comment">/*      Process all the records in the module.                          */</span>
<span class="comment">/* ==================================================================== */</span>
    <a class="code" href="classSDTSAttrRecord.html">SDTSAttrRecord</a> *poRecord;
    <span class="keywordtype">int</span>         iRecord = 0;

    <span class="keywordflow">while</span>((poRecord = (<a class="code" href="classSDTSAttrRecord.html">SDTSAttrRecord</a>*)poAttrReader-&gt;<a class="code" href="classSDTSIndexedReader.html#a9f5461d109c158088c7e783de52a39f3">GetNextFeature</a>()) != NULL)
    {
        DBFWriteIntegerAttribute( hDBF, iRecord, 0,
                                  poRecord-&gt;<a class="code" href="classSDTSFeature.html#ab66b82d3476e99c450fa6f485d4ae44f">oModId</a>.<a class="code" href="classSDTSModId.html#ae427a43cfae8b2ceb1ad077a948a07fa">nRecord</a> );

        WriteAttrRecordToDBF( hDBF, iRecord, poTransfer, poRecord-&gt;<a class="code" href="classSDTSAttrRecord.html#a4e24281496b75cdd20858ccfef3e8aac">poATTR</a> );

        <span class="keywordflow">if</span>( !poAttrReader-&gt;<a class="code" href="classSDTSIndexedReader.html#ac2f097b0ba6e558c4d9e35bf0bc08d4f">IsIndexed</a>() )
            <span class="keyword">delete</span> poRecord;
        
        iRecord++;
    }

<span class="comment">/* -------------------------------------------------------------------- */</span>
<span class="comment">/*      Close, and cleanup.                                             */</span>
<span class="comment">/* -------------------------------------------------------------------- */</span>
    DBFClose( hDBF );
}    

<span class="comment">/* **********************************************************************/</span>
<span class="comment">/*                       WritePolygonShapefile()                        */</span>
<span class="comment">/* **********************************************************************/</span>

<span class="keyword">static</span> <span class="keywordtype">void</span> WritePolygonShapefile( <span class="keyword">const</span> <span class="keywordtype">char</span> * pszShapefile,
                                   <a class="code" href="classSDTSTransfer.html">SDTSTransfer</a> * poTransfer, 
                                   <span class="keyword">const</span> <span class="keywordtype">char</span> * pszMODN )

{
    <a class="code" href="classSDTSPolygonReader.html">SDTSPolygonReader</a> *poPolyReader;

<span class="comment">/* -------------------------------------------------------------------- */</span>
<span class="comment">/*      Fetch a reference to the indexed polygon reader.                */</span>
<span class="comment">/* -------------------------------------------------------------------- */</span>
    poPolyReader = (<a class="code" href="classSDTSPolygonReader.html">SDTSPolygonReader</a> *) 
        poTransfer-&gt;<a class="code" href="classSDTSTransfer.html#a028d3ec2c7b3bcc719137e632b907ca3">GetLayerIndexedReader</a>( poTransfer-&gt;<a class="code" href="classSDTSTransfer.html#a7161e78c4e3aef778251231bfc95106e">FindLayer</a>( pszMODN ) );
    
    <span class="keywordflow">if</span>( poPolyReader == NULL )
    {
        fprintf( stderr, <span class="stringliteral">&quot;Failed to open %s.\n&quot;</span>,
                 poTransfer-&gt;<a class="code" href="classSDTSTransfer.html#aea48d5c34a76fec1fb347dbf9d59d9e5">GetCATD</a>()-&gt;GetModuleFilePath( pszMODN ) );
        <span class="keywordflow">return</span>;
    }

<span class="comment">/* -------------------------------------------------------------------- */</span>
<span class="comment">/*      Assemble polygon geometries from all the line layers.           */</span>
<span class="comment">/* -------------------------------------------------------------------- */</span>
    poPolyReader-&gt;<a class="code" href="classSDTSPolygonReader.html#aac67cdbc32090bd78e7f7cb81ab15042">AssembleRings</a>( poTransfer );
    
<span class="comment">/* -------------------------------------------------------------------- */</span>
<span class="comment">/*      Create the Shapefile.                                           */</span>
<span class="comment">/* -------------------------------------------------------------------- */</span>
    SHPHandle   hSHP;

    hSHP = SHPCreate( pszShapefile, SHPT_POLYGON );
    <span class="keywordflow">if</span>( hSHP == NULL )
    {
        fprintf( stderr, <span class="stringliteral">&quot;Unable to create shapefile `%s&#39;\n&quot;</span>,
                 pszShapefile );
        <span class="keywordflow">return</span>;
    }

<span class="comment">/* -------------------------------------------------------------------- */</span>
<span class="comment">/*      Create the database file, and our basic set of attributes.      */</span>
<span class="comment">/* -------------------------------------------------------------------- */</span>
    DBFHandle   hDBF;
    <span class="keywordtype">int</span>         nSDTSRecordField;
    <span class="keywordtype">char</span>        szDBFFilename[1024];

    sprintf( szDBFFilename, <span class="stringliteral">&quot;%s.dbf&quot;</span>, pszShapefile );

    hDBF = DBFCreate( szDBFFilename );
    <span class="keywordflow">if</span>( hDBF == NULL )
    {
        fprintf( stderr, <span class="stringliteral">&quot;Unable to create shapefile .dbf for `%s&#39;\n&quot;</span>,
                 pszShapefile );
        <span class="keywordflow">return</span>;
    }

    nSDTSRecordField = DBFAddField( hDBF, <span class="stringliteral">&quot;SDTSRecId&quot;</span>, FTInteger, 8, 0 );

    <span class="keywordtype">char</span>  **papszModRefs = poPolyReader-&gt;<a class="code" href="classSDTSIndexedReader.html#a4bc517f41916afab133cfadc01568b12">ScanModuleReferences</a>();
    AddPrimaryAttrToDBFSchema( hDBF, poTransfer, papszModRefs );
    CSLDestroy( papszModRefs );

<span class="comment">/* ==================================================================== */</span>
<span class="comment">/*      Process all the polygon features in the module.                 */</span>
<span class="comment">/* ==================================================================== */</span>
    <a class="code" href="classSDTSRawPolygon.html">SDTSRawPolygon</a>      *poRawPoly;

    poPolyReader-&gt;<a class="code" href="classSDTSIndexedReader.html#a2c6df4e9ddb8ef56529c8055e766548e">Rewind</a>();
    <span class="keywordflow">while</span>( (poRawPoly = (<a class="code" href="classSDTSRawPolygon.html">SDTSRawPolygon</a> *) poPolyReader-&gt;<a class="code" href="classSDTSIndexedReader.html#a9f5461d109c158088c7e783de52a39f3">GetNextFeature</a>())
           != NULL )
    {
        <span class="keywordtype">int</span>             iShape;

<span class="comment">/* -------------------------------------------------------------------- */</span>
<span class="comment">/*      Write out a shape with the vertices.                            */</span>
<span class="comment">/* -------------------------------------------------------------------- */</span>
        SHPObject       *psShape;

        psShape = SHPCreateObject( SHPT_POLYGON, -1, poRawPoly-&gt;<a class="code" href="classSDTSRawPolygon.html#a3fa3fd600751a7a9d62ffc91453bd9d1">nRings</a>,
                                   poRawPoly-&gt;<a class="code" href="classSDTSRawPolygon.html#a35527511ed9c8ab3cf9b6e71e9833be1">panRingStart</a>, NULL,
                                   poRawPoly-&gt;<a class="code" href="classSDTSRawPolygon.html#a01fe8594f7b24ed15a0c2c0835188d27">nVertices</a>,
                                   poRawPoly-&gt;<a class="code" href="classSDTSRawPolygon.html#aaf5bba1eca16e9a27fcbff59f0bc4e4e">padfX</a>, 
                                   poRawPoly-&gt;<a class="code" href="classSDTSRawPolygon.html#ae48a87c0088e681cc3926dcbd3a37dc4">padfY</a>, 
                                   poRawPoly-&gt;<a class="code" href="classSDTSRawPolygon.html#ac181fc598f9243543a41165ec4908e91">padfZ</a>,
                                   NULL );

        iShape = SHPWriteObject( hSHP, -1, psShape );

        SHPDestroyObject( psShape );

<span class="comment">/* -------------------------------------------------------------------- */</span>
<span class="comment">/*      Write out the attributes.                                       */</span>
<span class="comment">/* -------------------------------------------------------------------- */</span>
        DBFWriteIntegerAttribute( hDBF, iShape, nSDTSRecordField,
                                  poRawPoly-&gt;<a class="code" href="classSDTSFeature.html#ab66b82d3476e99c450fa6f485d4ae44f">oModId</a>.<a class="code" href="classSDTSModId.html#ae427a43cfae8b2ceb1ad077a948a07fa">nRecord</a> );
        WritePrimaryAttrToDBF( hDBF, iShape, poTransfer, poRawPoly );

        <span class="keywordflow">if</span>( !poPolyReader-&gt;<a class="code" href="classSDTSIndexedReader.html#ac2f097b0ba6e558c4d9e35bf0bc08d4f">IsIndexed</a>() )
            <span class="keyword">delete</span> poRawPoly;
    }

<span class="comment">/* -------------------------------------------------------------------- */</span>
<span class="comment">/*      Close, and cleanup.                                             */</span>
<span class="comment">/* -------------------------------------------------------------------- */</span>
    DBFClose( hDBF );
    SHPClose( hSHP );
}    

<span class="comment">/* **********************************************************************/</span>
<span class="comment">/*                        AddPrimaryAttrToDBF()                         */</span>
<span class="comment">/*                                                                      */</span>
<span class="comment">/*      Add the fields from all the given primary attribute modules     */</span>
<span class="comment">/*      to the schema of the passed DBF file.                           */</span>
<span class="comment">/* **********************************************************************/</span>

<span class="keyword">static</span> <span class="keywordtype">void</span>
AddPrimaryAttrToDBFSchema( DBFHandle hDBF, <a class="code" href="classSDTSTransfer.html">SDTSTransfer</a> *poTransfer,
                           <span class="keywordtype">char</span> ** papszModuleList )

{
    <span class="keywordflow">for</span>( <span class="keywordtype">int</span> iModule = 0;
         papszModuleList != NULL &amp;&amp; papszModuleList[iModule] != NULL;
         iModule++ )
    {
        <a class="code" href="classSDTSAttrReader.html">SDTSAttrReader</a>  *poAttrReader;

<span class="comment">/* -------------------------------------------------------------------- */</span>
<span class="comment">/*      Get a reader on the desired module.                             */</span>
<span class="comment">/* -------------------------------------------------------------------- */</span>
        poAttrReader = (<a class="code" href="classSDTSAttrReader.html">SDTSAttrReader</a> *)
            poTransfer-&gt;<a class="code" href="classSDTSTransfer.html#a028d3ec2c7b3bcc719137e632b907ca3">GetLayerIndexedReader</a>(
                poTransfer-&gt;<a class="code" href="classSDTSTransfer.html#a7161e78c4e3aef778251231bfc95106e">FindLayer</a>( papszModuleList[iModule] ) );

        <span class="keywordflow">if</span>( poAttrReader == NULL )
        {
            printf( <span class="stringliteral">&quot;Unable to open attribute module %s, skipping.\n&quot;</span> ,
                    papszModuleList[iModule] );
            <span class="keywordflow">continue</span>;
        }

        poAttrReader-&gt;<a class="code" href="classSDTSIndexedReader.html#a2c6df4e9ddb8ef56529c8055e766548e">Rewind</a>();
        
<span class="comment">/* -------------------------------------------------------------------- */</span>
<span class="comment">/*      Read the first record so we can clone schema information off    */</span>
<span class="comment">/*      of it.                                                          */</span>
<span class="comment">/* -------------------------------------------------------------------- */</span>
        <a class="code" href="classSDTSAttrRecord.html">SDTSAttrRecord</a>  *poAttrFeature;

        poAttrFeature = (<a class="code" href="classSDTSAttrRecord.html">SDTSAttrRecord</a> *) poAttrReader-&gt;<a class="code" href="classSDTSIndexedReader.html#a9f5461d109c158088c7e783de52a39f3">GetNextFeature</a>();
        <span class="keywordflow">if</span>( poAttrFeature == NULL )
        {
            fprintf( stderr,
                     <span class="stringliteral">&quot;Didn&#39;t find any meaningful attribute records in %s.\n&quot;</span>,
                     papszModuleList[iModule] );
        
            <span class="keywordflow">continue</span>;
        }

<span class="comment">/* -------------------------------------------------------------------- */</span>
<span class="comment">/*      Clone schema off the first record.  Eventually we need to       */</span>
<span class="comment">/*      get the information out of the DDR record, but it isn&#39;t         */</span>
<span class="comment">/*      clear to me how to accomplish that with the SDTS++ API.         */</span>
<span class="comment">/*                                                                      */</span>
<span class="comment">/*      The following approach may fail (dramatically) if some          */</span>
<span class="comment">/*      records do not include all subfields.  Furthermore, no          */</span>
<span class="comment">/*      effort is made to make DBF field names unique.  The SDTS        */</span>
<span class="comment">/*      attributes often have names much beyond the 14 character dbf    */</span>
<span class="comment">/*      limit which may result in non-unique attributes.                */</span>
<span class="comment">/* -------------------------------------------------------------------- */</span>
        <a class="code" href="classDDFFieldDefn.html">DDFFieldDefn</a>    *poFDefn = poAttrFeature-&gt;<a class="code" href="classSDTSAttrRecord.html#a4e24281496b75cdd20858ccfef3e8aac">poATTR</a>-&gt;<a class="code" href="classDDFField.html#ae2dc98dc9f24cd548a8b0c7461f4179d">GetFieldDefn</a>();
        <span class="keywordtype">int</span>             iSF;
        <a class="code" href="classDDFField.html">DDFField</a>        *poSR = poAttrFeature-&gt;<a class="code" href="classSDTSAttrRecord.html#a4e24281496b75cdd20858ccfef3e8aac">poATTR</a>;
    
        <span class="keywordflow">for</span>( iSF=0; iSF &lt; poFDefn-&gt;<a class="code" href="classDDFFieldDefn.html#ab0aca50e5913eda6ae7f058ae3e20971">GetSubfieldCount</a>(); iSF++ )
        {
            <a class="code" href="classDDFSubfieldDefn.html">DDFSubfieldDefn</a>     *poSFDefn = poFDefn-&gt;<a class="code" href="classDDFFieldDefn.html#ae9e1df79781078301f83fd09f713e416">GetSubfield</a>( iSF );
            <span class="keywordtype">int</span>         nWidth = poSFDefn-&gt;<a class="code" href="classDDFSubfieldDefn.html#a64fad8aa359e312db97d69245acd7317">GetWidth</a>();
            
            <span class="keywordflow">switch</span>( poSFDefn-&gt;<a class="code" href="classDDFSubfieldDefn.html#ad5bf003ff800ff8acaee62718ae72472">GetType</a>() )
            {
              <span class="keywordflow">case</span> DDFString:
                <span class="keywordflow">if</span>( nWidth == 0 )
                {
                    <span class="keywordtype">int</span>         nMaxBytes;
                
                    <span class="keyword">const</span> <span class="keywordtype">char</span> * pachData = poSR-&gt;<a class="code" href="classDDFField.html#a778da0e37f57a48e1c39e4ee3cf1ca83">GetSubfieldData</a>(poSFDefn,
                                                                  &amp;nMaxBytes);

                    nWidth = strlen(poSFDefn-&gt;<a class="code" href="classDDFSubfieldDefn.html#ad95ecafda6bcf87437030c273eb06643">ExtractStringData</a>(pachData,
                                                                nMaxBytes, NULL ));
                }
            
                DBFAddField( hDBF, poSFDefn-&gt;<a class="code" href="classDDFSubfieldDefn.html#a2fdfa7e689051d44242eb2a46407a756">GetName</a>(), FTString, nWidth, 0 );
                <span class="keywordflow">break</span>;

              <span class="keywordflow">case</span> DDFInt:
                <span class="keywordflow">if</span>( nWidth == 0 )
                    nWidth = 9;

                DBFAddField( hDBF, poSFDefn-&gt;<a class="code" href="classDDFSubfieldDefn.html#a2fdfa7e689051d44242eb2a46407a756">GetName</a>(), FTInteger, nWidth, 0 );
                <span class="keywordflow">break</span>;

              <span class="keywordflow">case</span> DDFFloat:
                DBFAddField( hDBF, poSFDefn-&gt;<a class="code" href="classDDFSubfieldDefn.html#a2fdfa7e689051d44242eb2a46407a756">GetName</a>(), FTDouble, 18, 6 );
                <span class="keywordflow">break</span>;

              <span class="keywordflow">default</span>:
                fprintf( stderr,
                         <span class="stringliteral">&quot;Dropping attribute `%s&#39; of module `%s&#39;.  &quot;</span>
                         <span class="stringliteral">&quot;Type unsupported\n&quot;</span>,
                         poSFDefn-&gt;<a class="code" href="classDDFSubfieldDefn.html#a2fdfa7e689051d44242eb2a46407a756">GetName</a>(),
                         papszModuleList[iModule] );
                <span class="keywordflow">break</span>;
            }
        }

        <span class="keywordflow">if</span>( !poAttrReader-&gt;<a class="code" href="classSDTSIndexedReader.html#ac2f097b0ba6e558c4d9e35bf0bc08d4f">IsIndexed</a>() )
            <span class="keyword">delete</span> poAttrFeature;

    } <span class="comment">/* next module */</span>
}

<span class="comment">/* **********************************************************************/</span>
<span class="comment">/*                       WritePrimaryAttrToDBF()                        */</span>
<span class="comment">/* **********************************************************************/</span>

<span class="keyword">static</span> <span class="keywordtype">void</span>
WritePrimaryAttrToDBF( DBFHandle hDBF, <span class="keywordtype">int</span> iRecord, 
                       <a class="code" href="classSDTSTransfer.html">SDTSTransfer</a> * poTransfer, <a class="code" href="classSDTSFeature.html">SDTSFeature</a> * poFeature )

{
<span class="comment">/* ==================================================================== */</span>
<span class="comment">/*      Loop over all the attribute records linked to this feature.     */</span>
<span class="comment">/* ==================================================================== */</span>
    <span class="keywordtype">int</span>         iAttrRecord;
    
    <span class="keywordflow">for</span>( iAttrRecord = 0; iAttrRecord &lt; poFeature-&gt;<a class="code" href="classSDTSFeature.html#aa5895c63334ebd42bee89be580561548">nAttributes</a>; iAttrRecord++)
    {
        <a class="code" href="classDDFField.html">DDFField</a>        *poSR;

        poSR = poTransfer-&gt;<a class="code" href="classSDTSTransfer.html#a4eeffce018629c3a27102e213255381f">GetAttr</a>( poFeature-&gt;<a class="code" href="classSDTSFeature.html#a506e3a8be93981a5c1092197b9440bc0">paoATID</a>+iAttrRecord );
          
        WriteAttrRecordToDBF( hDBF, iRecord, poTransfer, poSR );
    }
}

<span class="comment">/* **********************************************************************/</span>
<span class="comment">/*                        WriteAttrRecordToDBF()                        */</span>
<span class="comment">/* **********************************************************************/</span>

<span class="keyword">static</span> <span class="keywordtype">void</span>
WriteAttrRecordToDBF( DBFHandle hDBF, <span class="keywordtype">int</span> iRecord, 
                      <a class="code" href="classSDTSTransfer.html">SDTSTransfer</a> * poTransfer, <a class="code" href="classDDFField.html">DDFField</a> * poSR )

{
<span class="comment">/* -------------------------------------------------------------------- */</span>
<span class="comment">/*      Process each subfield in the record.                            */</span>
<span class="comment">/* -------------------------------------------------------------------- */</span>
    <a class="code" href="classDDFFieldDefn.html">DDFFieldDefn</a>        *poFDefn = poSR-&gt;<a class="code" href="classDDFField.html#ae2dc98dc9f24cd548a8b0c7461f4179d">GetFieldDefn</a>();
        
    <span class="keywordflow">for</span>( <span class="keywordtype">int</span> iSF=0; iSF &lt; poFDefn-&gt;<a class="code" href="classDDFFieldDefn.html#ab0aca50e5913eda6ae7f058ae3e20971">GetSubfieldCount</a>(); iSF++ )
    {
        <a class="code" href="classDDFSubfieldDefn.html">DDFSubfieldDefn</a> *poSFDefn = poFDefn-&gt;<a class="code" href="classDDFFieldDefn.html#ae9e1df79781078301f83fd09f713e416">GetSubfield</a>( iSF );
        <span class="keywordtype">int</span>                     iField;
        <span class="keywordtype">int</span>                     nMaxBytes;
        <span class="keyword">const</span> <span class="keywordtype">char</span> *    pachData = poSR-&gt;<a class="code" href="classDDFField.html#a778da0e37f57a48e1c39e4ee3cf1ca83">GetSubfieldData</a>(poSFDefn,
                                                         &amp;nMaxBytes);

<span class="comment">/* -------------------------------------------------------------------- */</span>
<span class="comment">/*      Identify the related DBF field, if any.                         */</span>
<span class="comment">/* -------------------------------------------------------------------- */</span>
        <span class="keywordflow">for</span>( iField = 0; iField &lt; hDBF-&gt;nFields; iField++ )
        {
            <span class="keywordflow">if</span>( EQUALN(poSFDefn-&gt;<a class="code" href="classDDFSubfieldDefn.html#a2fdfa7e689051d44242eb2a46407a756">GetName</a>(),
                       hDBF-&gt;pszHeader+iField*32,10) )
                <span class="keywordflow">break</span>;
        }

        <span class="keywordflow">if</span>( iField == hDBF-&gt;nFields )
            iField = -1;
            
<span class="comment">/* -------------------------------------------------------------------- */</span>
<span class="comment">/*      Handle each of the types.                                       */</span>
<span class="comment">/* -------------------------------------------------------------------- */</span>
        <span class="keywordflow">switch</span>( poSFDefn-&gt;<a class="code" href="classDDFSubfieldDefn.html#ad5bf003ff800ff8acaee62718ae72472">GetType</a>() )
        {
          <span class="keywordflow">case</span> DDFString:
            <span class="keyword">const</span> <span class="keywordtype">char</span>  *pszValue;

            pszValue = poSFDefn-&gt;<a class="code" href="classDDFSubfieldDefn.html#ad95ecafda6bcf87437030c273eb06643">ExtractStringData</a>(pachData, nMaxBytes,
                                                   NULL);

            <span class="keywordflow">if</span>( iField != -1 )
                DBFWriteStringAttribute(hDBF, iRecord, iField, pszValue );
            <span class="keywordflow">break</span>;

          <span class="keywordflow">case</span> DDFFloat:
            <span class="keywordtype">double</span>      dfValue;

            dfValue = poSFDefn-&gt;<a class="code" href="classDDFSubfieldDefn.html#a67fddf36a98106bf445ea49811812b00">ExtractFloatData</a>(pachData, nMaxBytes,
                                                 NULL);

            <span class="keywordflow">if</span>( iField != -1 )
                DBFWriteDoubleAttribute( hDBF, iRecord, iField, dfValue );
            <span class="keywordflow">break</span>;

          <span class="keywordflow">case</span> DDFInt:
            <span class="keywordtype">int</span>         nValue;

            nValue = poSFDefn-&gt;<a class="code" href="classDDFSubfieldDefn.html#a32ecb1b1e3da05e500049e4925dd20e5">ExtractIntData</a>(pachData, nMaxBytes, NULL);

            <span class="keywordflow">if</span>( iField != -1 )
                DBFWriteIntegerAttribute( hDBF, iRecord, iField, nValue );
            <span class="keywordflow">break</span>;

          <span class="keywordflow">default</span>:
            <span class="keywordflow">break</span>;
        }
    } <span class="comment">/* next subfield */</span>
}
</pre></div> </div>
<hr>

Generated for GDAL by 
<a href="http://www.doxygen.org/index.html"><img src="doxygen.png" alt="doxygen" align="middle" border="0"></a> 1.6.2-20100208.
</body>
</html>