[Qgis-developer] calling createEmptyDataSource from python
Tim Sutton
tim at linfiniti.com
Fri Jun 6 18:43:59 EDT 2008
Hi
Of course I meant to type 'copy on write' ...
Regards
Tim
2008/6/6 Tim Sutton <tim at linfiniti.com>:
> 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
>>
>
>
>
> --
> Tim Sutton
> QGIS Project Steering Committee Member - Release Manager
> Visit http://qgis.org for a great open source GIS
> openModeller Desktop Developer
> Visit http://openModeller.sf.net for a great open source ecological
> niche modelling tool
> Home Page: http://tim.linfiniti.com
> Skype: timlinux
> Irc: timlinux on #qgis at freenode.net
>
--
Tim Sutton
QGIS Project Steering Committee Member - Release Manager
Visit http://qgis.org for a great open source GIS
openModeller Desktop Developer
Visit http://openModeller.sf.net for a great open source ecological
niche modelling tool
Home Page: http://tim.linfiniti.com
Skype: timlinux
Irc: timlinux on #qgis at freenode.net
More information about the Qgis-developer
mailing list