⭐ 欢迎来到虫虫下载站! | 📦 资源下载 📁 资源专辑 ℹ️ 关于我们
⭐ 虫虫下载站

📄 rfc6_sqlgeom.html

📁 gdal库的学习文档
💻 HTML
📖 第 1 页 / 共 2 页
字号:
    psField = poFeature-&gt;GetRawFieldRef( op-&gt;field_index );</pre><p><pre></pre><p>In ogrfeaturequery.cpp OGRFeatureQuery::FieldCollector should be modifyed to add the field names like:<p><pre></pre><p><pre>if( op-&gt;field_index &gt;= poTargetDefn-&gt;GetFieldCount()        &amp;&amp; op-&gt;field_index &lt; poTargetDefn-&gt;GetFieldCount() + SPECIAL_FIELD_COUNT)         pszFieldName = SpecialFieldNames[op-&gt;field_index];</pre><p><pre></pre><p>In ogrdatasource.cpp ExecuteSQL() will allocate the arrays according to the number of the special fields:<p><pre></pre><p><pre>sFieldList.names = (char **)         CPLMalloc( sizeof(char *) * (nFieldCount+SPECIAL_FIELD_COUNT) );sFieldList.types = (swq_field_type *)          CPLMalloc( sizeof(swq_field_type) * (nFieldCount+SPECIAL_FIELD_COUNT) );sFieldList.table_ids = (int *)         CPLMalloc( sizeof(int) * (nFieldCount+SPECIAL_FIELD_COUNT) );sFieldList.ids = (int *)         CPLMalloc( sizeof(int) * (nFieldCount+SPECIAL_FIELD_COUNT) );</pre><p><pre></pre><p>And the fields will be added as<p><pre></pre><p><pre>for (iField = 0; iField &lt; SPECIAL_FIELD_COUNT; iField++){    sFieldList.names[sFieldList.count] = SpecialFieldNames[iField];    sFieldList.types[sFieldList.count] = SpecialFieldTypes[iField];    sFieldList.table_ids[sFieldList.count] = 0;    sFieldList.ids[sFieldList.count] = nFIDIndex + iField;    sFieldList.count++;}</pre><p><pre></pre><p>For supporting the SQL based queries we should also modify the constructor of OGRGenSQLResultsLayer in ogr_gensql.cpp and set the field type properly:<p><pre></pre><p><pre>else if ( psColDef-&gt;field_index &gt;= iFIDFieldIndex ){    switch ( SpecialFieldTypes[psColDef-&gt;field_index - iFIDFieldIndex] )    {    case SWQ_INTEGER:        oFDefn.SetType( OFTInteger );        break;    case SWQ_STRING:        oFDefn.SetType( OFTString );        break;    case SWQ_FLOAT:        oFDefn.SetType( OFTReal );        break;    }}</pre><p><pre></pre><p>Some of the queries will require to modify OGRGenSQLResultsLayer::PrepareSummary in ogr_gensql.cpp will be simplified (GetFieldAsString will be used in all cases to access the field values):<p><pre></pre><p><pre>pszError = swq_select_summarize( psSelectInfo, iField, poSrcFeature-&gt;GetFieldAsString( psColDef-&gt;field_index ) );</pre><p><pre></pre><p>OGRGenSQLResultsLayer::TranslateFeature should also be modifyed when copying the fields from primary record to the destination feature<p><pre></pre><p><pre> if ( psColDef-&gt;field_index &gt;= iFIDFieldIndex &amp;&amp;            psColDef-&gt;field_index &lt; iFIDFieldIndex + SPECIAL_FIELD_COUNT ){    switch (SpecialFieldTypes[psColDef-&gt;field_index - iFIDFieldIndex])    {    case SWQ_INTEGER:        poDstFeat-&gt;SetField( iField, poSrcFeat-&gt;GetFieldAsInteger(psColDef-&gt;field_index) );    case SWQ_STRING:        poDstFeat-&gt;SetField( iField, poSrcFeat-&gt;GetFieldAsString(psColDef-&gt;field_index) );    }}</pre><p><pre></pre><p>For supporting the 'order by' queries we should also modify OGRGenSQLResultsLayer::CreateOrderByIndex() as:<p><pre></pre><p><pre>if ( psKeyDef-&gt;field_index &gt;= iFIDFieldIndex){    if ( psKeyDef-&gt;field_index &lt; iFIDFieldIndex + SPECIAL_FIELD_COUNT )    {        switch (SpecialFieldTypes[psKeyDef-&gt;field_index - iFIDFieldIndex])        {        case SWQ_INTEGER:            psDstField-&gt;Integer = poSrcFeat-&gt;GetFieldAsInteger(psKeyDef-&gt;field_index);        case SWQ_STRING:            psDstField-&gt;String = CPLStrdup( poSrcFeat-&gt;GetFieldAsString(psKeyDef-&gt;field_index) );        }    }    continue;}</pre><p><pre></pre><p>All of the strings allocated previously should be deallocated later in the same function as:<p><pre></pre><p><pre>if ( psKeyDef-&gt;field_index &gt;= iFIDFieldIndex ){    /* warning: only special fields of type string should be deallocated */    if (SpecialFieldTypes[psKeyDef-&gt;field_index - iFIDFieldIndex] == SWQ_STRING)    {        for( i = 0; i &lt; nIndexSize; i++ )        {            OGRField *psField = pasIndexFields + iKey + i * nOrderItems;            CPLFree( psField-&gt;String );        }    }    continue;}</pre><p><pre></pre><p>When ordering by the field values the OGRGenSQLResultsLayer::Compare should also be modifyed:<p><pre></pre><p><pre>if( psKeyDef-&gt;field_index &gt;= iFIDFieldIndex )    poFDefn = NULL;else    poFDefn = poSrcLayer-&gt;GetLayerDefn()-&gt;GetFieldDefn(         psKeyDef-&gt;field_index );</pre><p><pre>if( (pasFirstTuple[iKey].Set.nMarker1 == OGRUnsetMarker         &amp;&amp; pasFirstTuple[iKey].Set.nMarker2 == OGRUnsetMarker)    || (pasSecondTuple[iKey].Set.nMarker1 == OGRUnsetMarker         &amp;&amp; pasSecondTuple[iKey].Set.nMarker2 == OGRUnsetMarker) )    nResult = 0;else if ( poFDefn == NULL ){    switch (SpecialFieldTypes[psKeyDef-&gt;field_index - iFIDFieldIndex])    {    case SWQ_INTEGER:        if( pasFirstTuple[iKey].Integer &lt; pasSecondTuple[iKey].Integer )            nResult = -1;        else if( pasFirstTuple[iKey].Integer &gt; pasSecondTuple[iKey].Integer )            nResult = 1;        break;    case SWQ_STRING:        nResult = strcmp(pasFirstTuple[iKey].String,                        pasSecondTuple[iKey].String);        break;    }}</pre><p><pre></pre><h2><a class="anchor" name="rfc6_addingnewspecial">Adding New Special Fields</a></h2>Adding a new special field in a subsequent development phase is fairly straightforward and the following steps should be made:<p>1. In ogr_p.h a new constant should be added with the value of the SPECIAL_FIELD_COUNT and SPECIAL_FIELD_COUNT should be incremented by one.<p>2. In ogrfeaturequery.cpp the special field string and the type should be added to SpecialFieldNames and SpecialFieldTypes respectively<p>3. The field value accessors (OGRFeature::GetFieldAsString, OGRFeature::GetFieldAsInteger, OGRFeature::GetFieldAsDouble) should be modifyed to provide the value of the new special field. All of these functions provide const return values so GetFieldAsString should retain the value in the m_pszTmpFieldValue member.<p>4. When adding a new value with a type other than SWQ_INTEGER and SWQ_STRING the following functions might also be modified accordingly:<p><ul><li>OGRGenSQLResultsLayer::OGRGenSQLResultsLayer<p></li><li>OGRGenSQLResultsLayer::TranslateFeature<p></li><li>OGRGenSQLResultsLayer::CreateOrderByIndex<p></li><li>OGRGenSQLResultsLayer::Compare<p></li><li>OGRFeatureQueryEvaluator<p></li></ul><h2><a class="anchor" name="rfc6_backward">Backward Compatibility</a></h2>In most cases the backward compatibility of the OGR library will be retained. However the special fields will potentially conflict with regard fields with the given names. When accessing the field values the special fields will take pecedence over the other fields with the same names.<p>When using OGRFeature::GetFieldAsString the returned value will be stored as a member variable instead of a static variable. The string will be deallocated and will no longer be usable after the destruction of the feature.<h2><a class="anchor" name="rfc6_testing">Regression Testing</a></h2>A new gdalautotest/ogr/ogr_sqlspecials.py script to test support for all special fields in the ExecuteSQL() call and with WHERE clauses.<h2><a class="anchor" name="rfc6_documentation">Documentation</a></h2>The OGR SQL document will be updated to reflect the support for special fields.<h2><a class="anchor" name="rfc6_staffing">Implementation Staffing</a></h2>Tamas Szekeres will implement the bulk of the RFC in time for GDAL/OGR 1.4.0.<p>Frank Warmerdam will consider how the backward compatibility issues (with special regard to the modified lifespan of the GetFieldAsString returned value) will affect the other parts of the OGR project and will write the Python regression testing script.<h2><a class="anchor" name="rfc6_references">References</a></h2><ul><li>Tracking bug for this feature (containing all of the proposed code changes):<p><a href="http://bugzilla.remotesensing.org/show_bug.cgi?id=1333">http://bugzilla.remotesensing.org/show_bug.cgi?id=1333</a><p></li><li>MapServer related bugs:<p><a href="http://mapserver.gis.umn.edu/bugs/show_bug.cgi?id=1129">http://mapserver.gis.umn.edu/bugs/show_bug.cgi?id=1129</a><p><a href="http://mapserver.gis.umn.edu/bugs/show_bug.cgi?id=1438">http://mapserver.gis.umn.edu/bugs/show_bug.cgi?id=1438</a><p></li></ul><h2><a class="anchor" name="rfc6_voting">Voting History</a></h2>Frank Warmerdam +1 Daniel Morissette +1 Howard Butler +0 Andrey Kiselev +1 <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.5.1.</body></html>

⌨️ 快捷键说明

复制代码 Ctrl + C
搜索代码 Ctrl + F
全屏模式 F11
切换主题 Ctrl + Shift + D
显示快捷键 ?
增大字号 Ctrl + =
减小字号 Ctrl + -