Geographic Information Systems Stack Exchange is a question and answer site for cartographers, geographers and GIS professionals. Join them; it only takes a minute:

Sign up
Here's how it works:
  1. Anybody can ask a question
  2. Anybody can answer
  3. The best answers are voted up and rise to the top

I need to draw a rectangle in a map canvas and inside it draw routed dashed lines and add small images to it. These actions are to be performed using the QGIS API.

Is there any place with examples that I can start with? All that I need is a direction of implementing this.

share|improve this question

Marco, there are not a lot of example resources for using the QGIS API, per se. You can find some snippets at and in the PyQGIS Cookbook, and online tutorials like QGIS Workshop v1.0.0.

However, your best resource for examples are in existing, working plugins. Load up a bunch of plugins that seem to do what your wanting and do multi-file searches for QGIS API calls.

For example, searching the core plugins and user-installed plugins directories for QgsFeature, depending on your installed plugins, will bring up lots of examples of how to add/edit/manipulate features. Specifically look to fTools for good examples on working with vector features. (Best to learn from the masters than re-invent the wheel here.)

Concerning the pictures you want to add: are they just photos with EXIF data or they georeferenced rasters? With georef'd rasters, you can use the API to add it to the map canvas in QGIS (see this snippet). For getting a shape file of points for your EXIF-with-GPS data photos, look to the photo2shape plugin.

If your photos are just to be placed on print output, you will want to manipulate the Print Composer. Look to plugins that already do similar things with Composer for examples, like Atlas or EasyPrint. You'll want to work with addComposerPicture() in the QgsComposition class.

share|improve this answer

Your Answer


By posting your answer, you agree to the privacy policy and terms of service.

Not the answer you're looking for? Browse other questions tagged or ask your own question.