[Qgis-developer] calling createEmptyDataSource from python

Martin Dobias wonder.sk at gmail.com
Sun Jun 8 09:09:32 EDT 2008


On Fri, Jun 6, 2008 at 11:32 PM, Stefanie Tellex <stefie10 at media.mit.edu> wrote:
> 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.

It's because this createEmptyDataSource has been done long before than
QgsVectorFileWriter have been actually made working. And none adapted
QgisApp class to work with it. From my point of view,
createEmptyDataSource is something to be removed in future.

> 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.

Our policy currently is not to use STL container classes like
std::list but use their Qt equivalents (for more coherent code) at
least for public API. Using a map for passing fields is unnecessary,
but it's not a problem.
Finally, vector file writer doesn't have to be opened and closed, it
can be used directly to save features after openining, see the python
bindings wiki page (at bottom):
http://wiki.qgis.org/qgiswiki/PythonBindings

>   * 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.

Actually how createEmptyDataSource work is not really the right
direction. Creating new data sources with other providers is something
I'd like to enable with some greater changes in vectors handling -
basically to follow the way how it's done e.g. in OGR: their data
source class is a collection of layers (e.g. a directory), layers have
the same meaning. Withing data source class you're able to open or
create new layers. This is a saner way. Moreover, when creating new
layers, providers usually need to specify some additional properties.
(in OGR it's e.g. file format)

>   * 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.  :-)

As Tim noted already, QgsVectorFileWriter does this too. And yes, they
are important :)

So these are my reasons why I don't want to apply your patch.

Regards
Martin


More information about the Qgis-developer mailing list