[Qgis-developer] calling createEmptyDataSource from python

Marco Hugentobler marco.hugentobler at karto.baug.ethz.ch
Mon Jun 9 10:46:35 EDT 2008


> Removing the reference modifier from function parameters creates in my
> opinion cleaner, easier to read code and is more consistent with the
> Qt4 programming style which was are at least striving to achieve on
> public parts of the API. In a similar vein its preferred to use QList
> over std::list on public methods, and QPair over std::pair.

I think the mechanism of Qt to use implicitely sharing may be confusing for 
many programmers which know C++ but not Qt. And even those how know Qt need 
to bookmark the list with shared classes and check if class XY uses sharing 
or not. So in my opinion, it is much clearer to read code with the 
references.

Regards,
Marco 

Am Samstag 07 Juni 2008 00:40:38 schrieb Tim Sutton:
> Hi Stefanie
>
> Another thing:
>
> +bool createEmptyDataSource(const QString& provider,
> +                          const QString& filename,
> +                          const QString& fileformat,
> +                          const QString& enc,
> +                          QGis::WKBTYPE geometrytype,
> +                          const std::list<std::pair<QString, QString>
>
> >& attributes) {
>
> In Qt its not really necessary to pass by reference like this since Qt
> uses implicit sharing / copy one write which basically means if you
> pass a Qt object to a function, it does not make a copy of the object
> until the receiving class tries to change it. You can read more here:
>
> http://cartan.cas.suffolk.edu/qtdocs/shared.html
>
> Removing the reference modifier from function parameters creates in my
> opinion cleaner, easier to read code and is more consistent with the
> Qt4 programming style which was are at least striving to achieve on
> public parts of the API. In a similar vein its preferred to use QList
> over std::list on public methods, and QPair over std::pair.
>
> I wonder if it doesnt make sense to wrap the functionality you have
> kindly provided as a method in qgsvectorfilewriter and update qgsapp
> to defer to that method rather. Basically, your method above
> implemented in qgsvectorfilewriter would provide a convenience method
> that removes the need to building a qgsfieldmap first. That approach
> would seem to conform to Martins (I think good) suggestion while
> providing you the convenience you were looking for.
>
> >   * 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.  :-)
>
> QgsVectorFileWriter will do this for you too. One of the unit tests I
> have written illustrates the use of QgsVectorFileWriter if you look
> under tests/src/core.
>
> Keep those patches coming ! :-)
>
> Regards
>
> Tim
>
> 2008/6/6 Stefanie Tellex <stefie10 at media.mit.edu>:
> > 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
> >
> > _______________________________________________
> > Qgis-developer mailing list
> > Qgis-developer at lists.osgeo.org
> > http://lists.osgeo.org/mailman/listinfo/qgis-developer



-- 
Dr. Marco Hugentobler
Institute of Cartography
ETH Zurich
Technical Advisor QGIS Project Steering Committee


More information about the Qgis-developer mailing list