[Qgis-developer] Cleanly create memory layer in Python?
Ricardo Filipe Soares Garcia da
ricardo.garcia.silva at gmail.com
Thu Jan 6 17:01:33 EST 2011
Hi Chris
In the 'Profile from lines' plugin I'm using a similar approach:
# python code
projectionSettingKey = "Projections/defaultBehaviour"
oldProjectionSetting = self.qgisSettings.value(projectionSettingKey)
self.qgisSettings.setValue(projectionSettingKey, "useGlobal")
self.qgisSettings.sync()
pointLayer = QgsVectorLayer("Point", "temporary_points", "memory")
pointLayer.setCrs(linesLayer.crs())
self.qgisSettings.setValue(projectionSettingKey, oldProjectionSetting)
This was discussed a while back at another thread in this mailing-list
(08/09/2010) and this was a suggestion from Martin Dobias. It seems at
the moment it is as clean as it gets (its still a bit unclean though
;))
I'd also be interested in knowing alternative ways to do this.
On Thu, Jan 6, 2011 at 8:16 PM, Chris Crook <ccrook at linz.govt.nz> wrote:
> Hi All
>
> I'm wanting to create a memory provider in Python without invoking the CRS selection dialog (even if the QGIS settings are set to "Prompt for CRS when a new layer is created".
>
> At the moment my code looks like:
>
> settings = QSettings()
> prjSetting = settings.value("/Projections/defaultBehaviour")
> settings.setValue("/Projections/defaultBehaviour", QVariant(""))
> layer = QgsVectorLayer("point",name,"memory")
> if prjSetting:
> settings.setValue("/Projections/defaultBehaviour",prjSetting)
>
> This does work, but it seems a bit cumbersome (at first glance it doesn't even look like creating a vector layer!), so I'm wondering if there is a cleaner approach..
>
> Cheers
> Chris
> ______________________________________________________________________________________________________
>
> This message contains information, which is confidential and may be subject to legal privilege.
> If you are not the intended recipient, you must not peruse, use, disseminate, distribute or copy this message.
> If you have received this message in error, please notify us immediately (Phone 0800 665 463 or info at linz.govt.nz) and destroy the original message.
> LINZ accepts no responsibility for changes to this email, or for any attachments, after its transmission from LINZ.
>
> Thank you.
> ______________________________________________________________________________________________________
> _______________________________________________
> Qgis-developer mailing list
> Qgis-developer at lists.osgeo.org
> http://lists.osgeo.org/mailman/listinfo/qgis-developer
>
--
___________________________ ___ __
Ricardo Garcia Silva
More information about the Qgis-developer
mailing list