[Qgis-developer] calling createEmptyDataSource from python

Stefanie Tellex stefie10 at media.mit.edu
Fri Jun 6 17:32:31 EDT 2008


Hi Martin,

I didn't know about QgsVectorFileWriter.  How come qgisapp.cpp doesn't 
use it to create a new layer?  I was looking there to figure out how to 
make a new empty data source, and saw it was doing fancy stuff to call 
createEmptyDataSource in the ogr library.

I think my patch is better for three reasons:
   * It seems like it would be more work to call QgsVectorFileWriter 
from python than it would be to use the patch I submitted to call 
createEmptyDataSource from python.  With the patch I submitted, 
createEmptyDataSource gets passed a list of tuples specifying the 
fields, while QgsVectorFileWriter wants a QgsFieldMap, and has to be 
opened and closed to save the shapefile.
    * my patch refactors createEmptyDataSource into a function in 
QgsVectorDataProvider, which cleans up the code in qgisapp, makes it 
easier to change qgis app to use createEmptyDataSource with other 
providers, and makes it so python and qgisapp use the same mechanism for 
making new empty data sources.
    * createEmptyDataSource not only makes file.shp, but also file.dbf, 
file.prj, and file.shx.  I don't know what they are, but they sound 
important.  :-)

Thanks,

Stefanie






Martin Dobias wrote:
> On Thu, Jun 5, 2008 at 4:34 AM, Stefanie Tellex <stefie10 at media.mit.edu> wrote:
>> Hi,
>>
>> Is there a way to call the ogr provider's createEmptyDataSource function
>> from python?  I could try using ctypes, but I wasn't sure if it would work
>> with the sip interface.  Combining two ways of talking to C/C++ from python
>> seems hairy.
> 
> Hi Stefanie,
> 
> what about using QgsVectorFileWriter instead? Or is there anything
> that you'd like to use and it's not available?
> 
> Bye
> Martin



More information about the Qgis-developer mailing list