3

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.

1 Answer 1

1

Marco, there are not a lot of example resources for using the QGIS API, per se. You can find some snippets at plugins.qgis.org 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.

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

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