[Qgis-developer] Selecting with On-the-fly enabled (PyQGIS)

Martin Dobias wonder.sk at gmail.com
Mon Mar 18 02:31:01 PDT 2013


Hi

On Mon, Mar 18, 2013 at 10:17 AM, fegyi001 <fegyi001 at gmail.com> wrote:
> Hi everyone,
>
> I have problems with a specific task. I intend to write a new module, during
> which the user has to select features from the map canvas. My project is in
> EPSG:23700. There are shapefiles from different coordinate systems, such as
> EPSG:23700, EPSG:4326, EPSG:32633 and even without projection. On-the-fly
> projection is enabled.
>
> Everything works fine when selecting features from the EPSG:23700 and the
> projection-less features. But when I try to click on a feature in the other
> files, they are not highlighted and therefore not selected. When I disable
> the on-the-fly projection, the EPSG:4326 and EPSG:32633 features are
> transformed back to their normal place, and I can click on them. But I
> INTEND to use on-the-fly projection, so this is a big problem for me.
>
> When I use the official icons for selecting features, however, the selection
> works just fine with features from ALL EPSGs.
>
> Does anyone has an idea what should I do? I'm quite new to Python
> programming and to the QGIS API.

When fetching features from vector layer/provider, the rectangle you
specify as a filter is in layer's CRS. To convert from project's CRS
to layer's CRS you can use QgsCoordinateTransform class, or with a
convenience call in QgsMapRenderer (which can be accessed from
QgsMapCanvas) - something like this:
layerPoint = canvas.mapRenderer().mapToLayerCoordinates(layer, point)

Regards
Martin


More information about the Qgis-developer mailing list