On Sat, Aug 7, 2010 at 12:00 AM, Ricardo Filipe Soares Garcia da
<[email protected]> 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
_______________________________________________
Qgis-developer mailing list
[email protected]
http://lists.osgeo.org/mailman/listinfo/qgis-developer

Reply via email to