[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 15:51:07 EDT 2010


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.

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


More information about the Qgis-developer mailing list