[Qgis-developer] Getting center of layer in lat/long

Nathan Woodrow madmanwoo at gmail.com
Fri Jun 13 16:24:11 PDT 2014


Hey Mark

I think you are over thinking it ;)

Iface.mapCanvas().extent() will give you the event of the view.
Extent.center() for the middle.

You can transform this using the coordinate transformation classes.

Nathan
On Jun 14, 2014 8:59 AM, "Mark Coletti" <mcoletti at gmail.com> wrote:

> First, long time no see!  Been a while since I've posted to this mailing
> list.  ;)
>
> I'm developing a plug-in that will allow a user to use the Twitter REST
> API to create a layer of tweets.  Yes, I already know of the articles on
> the net regarding how to do that manually.  However, I'm wrapping that
> functionality in a nice GUI to shield the lay user from messing about with
> code.
>
> I already have the plugin working with specified lat/lon coordinates and a
> given radius.  That's the easy part.  What I'd also like to do is have the
> user specify such things as "gimme the tweets for the current layer extent"
> or "gimme the tweets for just the area in the viewport."  I *suspect* that
> these are easy, but my first pass through the available high level
> documentation didn't give me a whole lot to steer by.
>
> For the first scenario, I would need to do the following:
>
>
>    1. get the current layer
>    2. get the MBR for said layer
>    3. compute the centroid/midpoint
>    4. project to lat/lon if necessary
>    5. compute distance from midpoint to edge
>
> Step #1 would, I presume, entail talking to the singleton layer manager to
> get the currently selected layer.  Step #2 would presumably be available in
> the corresponding QgsLayer object.  Step #3 I could use the GEOS geometry
> ops to compute.  Step #4 would be a bit tricky since I'd have to first
> determine if reprojection was even necessary, and if so then jump through
> the hoops to get my lat/lon.  Step #5 I note the existence of QgsDistance,
> which I could use to compute the distance from the centroid to an edge of
> the layer MBR; doing a flat or ellipsoidal distance calculation would
> depend on the CRS of the selected layer, natch.
>
> My nagging feeling is "surely this, or a subset of these, is/are common
> use cases" ... and that there'd be corresponding syntactic sugar for
> implementing them.  The QgsDistance class is sort of an example since it
> presumably handles projection and geometric distance headaches for you in
> desired units.
>
> So, does there exist such a set of convenience classes/functions?
>  Similarly does there exist somewhere a set of corresponding code snippets?
>  (The official online code snippets don't cover these, alas.)
>
> Cheers!
>
> Mark
> --
> mcoletti at gmail.com
>
>
> _______________________________________________
> Qgis-developer mailing list
> Qgis-developer at lists.osgeo.org
> http://lists.osgeo.org/mailman/listinfo/qgis-developer
>
-------------- next part --------------
An HTML attachment was scrubbed...
URL: <http://lists.osgeo.org/pipermail/qgis-developer/attachments/20140614/49b3520a/attachment.html>


More information about the Qgis-developer mailing list