<div dir="ltr"><blockquote class="gmail_quote" style="margin:0px 0px 0px 0.8ex;border-left:1px solid rgb(204,204,204);padding-left:1ex"><span style="font-size:12.8px">What do you mean by "opening the source" and "retrieving the layer" ?</span><br style="font-size:12.8px"><span style="font-size:12.8px">They sound like the same operation to me ?</span></blockquote><div><br></div><div> In the Python code you are using the OGR Interface</div><div><br></div><div><span style="color:rgb(51,51,51);font-family:consolas,"liberation mono",menlo,courier,monospace;font-size:12px;line-height:20px;white-space:pre">ds </span><span class="gmail-pl-k" style="box-sizing:border-box;color:rgb(167,29,93);font-family:consolas,"liberation mono",menlo,courier,monospace;font-size:12px;line-height:20px;white-space:pre">=</span><span style="color:rgb(51,51,51);font-family:consolas,"liberation mono",menlo,courier,monospace;font-size:12px;line-height:20px;white-space:pre"> ogr.Open(ogruri)</span><br></div><div><span style="color:rgb(51,51,51);font-size:12px;line-height:20px;white-space:pre"><font face="arial, helvetica, sans-serif"><br></font></span></div><div><font face="arial, helvetica, sans-serif"><span style="color:rgb(51,51,51);line-height:20px;white-space:pre">in c++ (as used in </span><font color="#333333"><span style="line-height:20px;white-space:pre">QgsOgrProvider) this corresponds to:</span></font></font></div><div><br></div><div><font color="#333333" face="consolas, liberation mono, menlo, courier, monospace"><span style="font-size:12px;line-height:20px;white-space:pre">OGRDataSourceH hDS = OGROpen( pszPath, bUpdate, &hDriver );</span></font><br></div><div><font color="#333333" face="consolas, liberation mono, menlo, courier, monospace"><span style="font-size:12px;line-height:20px;white-space:pre"><br></span></font></div><div><font color="#333333" face="arial, helvetica, sans-serif"><span style="font-size:12px;line-height:20px;white-space:pre">it will only open the Datasource for use.</span></font></div><div><font color="#333333" face="arial, helvetica, sans-serif"><span style="font-size:12px;line-height:20px;white-space:pre"><br></span></font></div><div><font color="#333333" face="arial, helvetica, sans-serif"><span style="font-size:12px;line-height:20px;white-space:pre">OGR will read the datasource and create the infastructure needed during reading</span></font></div><div><font color="#333333" face="arial, helvetica, sans-serif"><span style="font-size:12px;line-height:20px;white-space:pre">- such as a list of layers</span></font></div><div><font color="#333333" face="arial, helvetica, sans-serif"><span style="font-size:12px;line-height:20px;white-space:pre">-- in gdal 1.* each geometry is 1 layer (with only 1 geometry-field)</span></font></div><div><font color="#333333" face="arial, helvetica, sans-serif"><span style="font-size:12px;line-height:20px;white-space:pre">-- in gdal 2.* each table is 1 layer that may contain more than 1 geometry-field</span></font></div><div><font color="#333333" face="arial, helvetica, sans-serif"><span style="font-size:12px;line-height:20px;white-space:pre"><br></span></font></div><div><font color="#333333" face="arial, helvetica, sans-serif"><span style="font-size:12px;line-height:20px;white-space:pre">At this point you can decide what to do</span></font></div><div><font color="#333333" face="arial, helvetica, sans-serif"><span style="font-size:12px;line-height:20px;white-space:pre">- list the layers and the fields</span></font></div><div><font color="#333333" face="arial, helvetica, sans-serif"><span style="font-size:12px;line-height:20px;white-space:pre">- select a specific layer with a geometry-field</span></font></div><div><font color="#333333" face="arial, helvetica, sans-serif"><span style="font-size:12px;line-height:20px;white-space:pre"><br></span></font></div><div><font color="#333333" face="arial, helvetica, sans-serif"><span style="font-size:12px;line-height:20px;white-space:pre">Either with the layer-id:</span></font></div><div><font color="#333333" face="arial, helvetica, sans-serif"><span style="font-size:12px;line-height:20px;white-space:pre">python:</span></font></div><div><span style="color:rgb(51,51,51);font-family:consolas,"liberation mono",menlo,courier,monospace;font-size:12px;line-height:20px;white-space:pre">ly </span><span class="gmail-pl-k" style="box-sizing:border-box;color:rgb(167,29,93);font-family:consolas,"liberation mono",menlo,courier,monospace;font-size:12px;line-height:20px;white-space:pre">=</span><span style="color:rgb(51,51,51);font-family:consolas,"liberation mono",menlo,courier,monospace;font-size:12px;line-height:20px;white-space:pre"> ds.GetLayer(layerid)</span><font color="#333333" face="arial, helvetica, sans-serif"><span style="font-size:12px;line-height:20px;white-space:pre"><br></span></font></div><div><span style="color:rgb(51,51,51);font-family:consolas,"liberation mono",menlo,courier,monospace;font-size:12px;line-height:20px;white-space:pre"><br></span></div><div><span style="font-family:arial,helvetica,sans-serif;color:rgb(51,51,51);line-height:20px;white-space:pre">in c++ (as used in </span><font color="#333333" style="font-family:arial,helvetica,sans-serif"><span style="line-height:20px;white-space:pre">QgsOgrProvider) this corresponds to:</span></font><span style="color:rgb(51,51,51);font-family:consolas,"liberation mono",menlo,courier,monospace;font-size:12px;line-height:20px;white-space:pre"><br></span></div><div><font color="#333333" face="consolas, liberation mono, menlo, courier, monospace"><span style="font-size:12px;line-height:20px;white-space:pre">ogrLayer = OGR_DS_GetLayer( ogrDataSource, iLayerIndex );</span></font><br></div><div><font color="#333333" face="consolas, liberation mono, menlo, courier, monospace"><span style="font-size:12px;line-height:20px;white-space:pre"><br></span></font></div><div><font color="#333333" face="arial, helvetica, sans-serif"><span style="font-size:12px;line-height:20px;white-space:pre">or with the layer-name</span></font></div><div><span style="font-size:12px;line-height:20px;white-space:pre;color:rgb(51,51,51);font-family:consolas,"liberation mono",menlo,courier,monospace">ogrLayer = OGR_DS_GetLayerByName( ogrDataSource, TO8( sLayerName ) );</span><br></div><div><font color="#333333" face="consolas, liberation mono, menlo, courier, monospace"><span style="font-size:12px;line-height:20px;white-space:pre"><br></span></font></div><div><font color="#333333" face="arial, helvetica, sans-serif"><span style="font-size:12px;line-height:20px;white-space:pre">when all tasks are completed, the Datasource is closed.</span></font></div><div><font color="#333333" face="consolas, liberation mono, menlo, courier, monospace"><span style="font-size:12px;line-height:20px;white-space:pre"><br></span></font></div><div><font face="arial, helvetica, sans-serif"><font color="#333333"><span style="font-size:12px;line-height:20px;white-space:pre">Inside </span></font><span style="color:rgb(51,51,51);line-height:20px;white-space:pre">QgsOgrProvider all of this is done as needed, but when using the OGR-API </span></font><span style="color:rgb(51,51,51);font-family:arial,helvetica,sans-serif;line-height:20px;white-space:pre"> directly </span><span style="color:rgb(51,51,51);line-height:20px;white-space:pre;font-family:arial,helvetica,sans-serif">each step must be done manually.</span></div><div><span style="color:rgb(51,51,51);line-height:20px;white-space:pre;font-family:arial,helvetica,sans-serif"><br></span></div><div><span style="color:rgb(51,51,51);line-height:20px;white-space:pre;font-family:arial,helvetica,sans-serif">Mark Johnson</span></div><div><br></div></div>