[Qgis-developer] how to add crs to a new memory provider layer?

Ricardo Filipe Soares Garcia da ricardo.garcia.silva at gmail.com
Sun Aug 8 21:02:30 EDT 2010


I have implemented the fix suggested by Martin and everything seems to
be working fine.

This plugin creates points along lines according to a user-specified
distance. It can also sample any number of raster layers at the
location of each new point and gather the raster's value.
I'll be releasing it sometime during the week (it'll be called
'Profile from line')

Thank you Martin and Václav for your speedy and most helpful assistance.

2010/8/9 Václav Řehák <rehakv01 at gmail.com>:
> 2010/8/9 Ricardo Filipe Soares Garcia da <ricardo.garcia.silva at gmail.com>:
>> Hi Martin
>>
>> could you please elaborate a bit more on that? How can I get a pointer
>> to this "QSettings" instance that you mention? I couldn't find any
>> reference to it in the online API docs. Maybe you are talking about
>> QgsProject class? If so, how can I get a pointer to it? I am coding in
>> Python.
>
> QSettings is part of PyQT4, not QGIS, so you find the doc in PyQT4
> documentation [1] not in the QGIS API doc.
>
> In my plugin I use it like this:
>
> settings = QSettings()
> dirName = settings.value("/UI/lastShapefileDir").toString()
>
> Vaclav
>
> [1] http://www.riverbankcomputing.co.uk/static/Docs/PyQt4/html/qsettings.html
>
>>
>> Thank you
>>
>> On Sat, Aug 7, 2010 at 4:23 PM, Martin Dobias <wonder.sk at gmail.com> wrote:
>>> On Sat, Aug 7, 2010 at 12:00 AM, Ricardo Filipe Soares Garcia da
>>> <ricardo.garcia.silva at gmail.com> wrote:
>>>> Hi list
>>>> I'm trying to create a plugin that creates a new layer using the
>>>> memory provider. I'd like this new layer to have the same crs as
>>>> another layer ('linesLayer' in my code below). All is going well,
>>>> except that when I add the new layer to the mapLayerRegistry I always
>>>> get prompted for selecting the new layer's crs. So, how do I go about
>>>> defining it programatically? What I want is to not be bothered with
>>>> the dialog to select my layer's crs during the execution of the
>>>> plugin. Currently I am doing:
>>>>
>>>> # python code
>>>> pointLayer = QgsVectorLayer("Point", "temporary_points", "memory")
>>>> pointLayer.setCrs(linesLayer.crs())
>>>> # rest of the code
>>>> self.layerRegistry.addMapLayer(pointLayer)
>>>
>>> Hi Ricardo
>>>
>>> The dialog actually pops up when you construct the vector layer (not
>>> when it is being added to layer registry). Currently I am not aware of
>>> a nice solution. CRS dialog is shown if the key
>>> "/Projections/defaultBehaviour" in QSettings is set to value "prompt".
>>> So you could use a quick and dirty trick to change this setting to
>>> e.g. "useGlobal" before loading the layer, so by default it will get
>>> WGS84 crs, then change the setting back to original value and call
>>> layer's setCrs() to force it to use the correct crs.
>>>
>>> Regards
>>> Martin
>>>
>>
>>
>>
>> --
>> ___________________________ ___ __
>> Ricardo Garcia Silva
>> _______________________________________________
>> 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