[QGIS-Developer] Setting a custom CRS for the map canvas

Tim Sutton tim at kartoza.com
Mon Nov 16 15:57:44 PST 2020


Hi Folks

I am trying to update a 2.x snippet I have which iteratively sets the CRS
with sequentially higher LO values:

https://gist.github.com/timlinux/1057c2c6b5ebda6ed2b5aa8c5aa21372

# Uses a trick from Alexander Neto: "I created a orthographic projection
with lisbon longitude, but with a south hemisphere latitude
# That way kinda looks 3d"
# This will make the QGIS use a world projection and then move the center
# of the CRS sequentially to create a spinning globe effect
import time
from subprocess import call
longitude_increments = 5
image_counter = 1
for i in range(-180, 180, longitude_increments):
  definition = (
  '+proj=ortho +lat_0=-20 +lon_0=%i +x_0=0 +y_0=0 +R=6371000 +units=m
+no_defs +type=crs' % i)
  crs = QgsCoordinateReferenceSystem()
  crs.createFromProj(definition)
  iface.mapCanvas().mapSettings().setDestinationCrs(crs)
  #iface.mapCanvas().setMapUnits(0)
  iface.mapCanvas().refresh()
  iface.mapCanvas().saveAsImage(
    '/tmp/globe-%03d.png' % image_counter)
  image_counter += 1
  print (definition)
  time.sleep(1)
# Now generate the GIF. If this fails try run the call from the command line
# and check the path to convert (provided by ImageMagick) is correct...
call('/usr/bin/convert -delay 35 -loop 0 /tmp/globe-*.png /tmp/globe.gif')

The  example python above using Orthographc North will hopefully make a
more pleasing looking spinny globe. However, in QGIS 3.x the code runs but
if I inspect the mapcanvas CRS after setting the new CRS, it still shows
the old CRS. Can anyone see what I am missing here?

Thanks!

Regards

Tim

-- 
------------------------------------------------------------------------------------------

Tim Sutton
Visit http://kartoza.com to find out about open source:
 * Desktop GIS programming services
 * Geospatial web development
* GIS Training
* Consulting Services
Tim is a member of the QGIS Project Steering Committee
-------------------------------------------------------------------------------------------
-------------- next part --------------
An HTML attachment was scrubbed...
URL: <http://lists.osgeo.org/pipermail/qgis-developer/attachments/20201116/383c8973/attachment.html>


More information about the QGIS-Developer mailing list