Matt
  • Member for 9 years, 4 months
  • Last seen more than a month ago
Programmatically load composer from template and generate atlas using PyQGIS
Accepted answer
19 votes

If anyone is interested here is the code I ended up with. This will turn on/off specific layers in the table of contents (from a list of layers), load a selected composer template from file, generate ...

View answer
Running Python script on opening QGIS project?
12 votes

Put your script in .qgis/python/startup.py and it should run when QGIS is opened. However, this will run with any project you open, which you may not want. So you might be better off setting up a ...

View answer
Missing Georeferencer
Accepted answer
7 votes

You need to enable it in the plugins menu. Goto 'Plugins' > 'Manage and install plugins' > 'Installed'. Then make sure GDAL Georeferencer is ticked.

View answer
Making map using PyQGIS?
Accepted answer
5 votes

This bit of code might help you programmatically carry out steps 3 and 4. It will load a composer template from file and export a map to jpeg by creating a atlas. It will require some tweaking but ...

View answer
why does my script not save a layer when it encounters a " \" character in the string
Accepted answer
4 votes

In Python a backslash is an escape character. In order to put a backslash in the string you need to need to put another backslash next to it to stop it from forcing a new line. myString = "this is\...

View answer
"CRS selector" dialog after running a script
Accepted answer
4 votes

You can specify the CRS when you create your memory layer: vl = QgsVectorLayer('LineString?crs=EPSG:2964', 'MyLayer' , 'memory')

View answer
Problem connecting local POSTGIS in QGIS
4 votes

You need to tell QGIS that the database server is on running localhost. Try making Host = 'localhost'. Also you are trying to connect to the postgres maintenance db. Try creating a spatial database ...

View answer
how to open second window in my plugin for QGIS?
3 votes

If you have compiled your Ui file to a .py with pyuic then you setup like this: yourplugin_dialog.py: from PyQt4 import QtCore, QtGui from ui_yourdialog import Ui_YourDialog #create the dialog for ...

View answer
ogr2ogr/python overwrite PostGIS table
Accepted answer
3 votes

Not a direct answer using python GDAL bindings but I have used the python subprocess module to call the GDAL command line utility to batch load Shapefiles into into postGIS. Something like this would ...

View answer
How to programmatically fill a datetime field with datetime.datetime.now() function
3 votes

A Shapefile stores dates in a date field with this format: yyyy-mm-dd. So some string formatting is required. import datetime now = datetime.datetime.now() month = now.month year = now.year day = ...

View answer
keeping track of edited features QGIS
Accepted answer
3 votes

Assuming you are using PostGIS, you may want to look into implementing your own edit tracking system in postgres. A great tutorial can be found at this blog. The general idea is that after each edit/...

View answer
Features placed 7.5 thousand kms off correct location using QGIS?
Accepted answer
3 votes

It does sounds like you have changed the CRS half through adding the features. You can re-project those points by selecting them, then right click on the shapefile layer in the table of contents and ...

View answer
os.system /subprocess.call error handling when error in command line function?
Accepted answer
3 votes

Try this out, if the exit status is 0 then the command has run as expected. program = "C:\Path\to\GDAL" command = 'gdal_rasterize -a ICE_TYPE -where \"ICE_TYPE=\'Open Water\'\" -b 1 -burn 5 -l ' + ...

View answer
Postgis geometry type = Geometry
3 votes

You could add a new geometry column to your table with the specified point/line/poly and then copy the geometry from the current geometry column. ALTER TABLE your_table ADD COLUMN geom geometry(...

View answer
Installing tweepy for tweeter 2qgis?
2 votes

Tweepy is a python module, like any other module you must install it to the Python instance you wish to use. To use it within the plugin you must install it to your Qgis Python instance (located in ...

View answer
GeoServer / OpenLayers : Front-End interface
2 votes

Openlayers is just a JavaScript library, so you can use whichever Integrated Development Environment (IDE) you feel most comfortable using for web development. If you are using a Java web framework ...

View answer
PyQGIS reload a QGIS plugin
Accepted answer
2 votes

Adding a toolbar: # Create toolbar self.toolbar = self.iface.addToolBar("My Toolbar") self.toolbar.setObjectName("My toolbar Plugin") self.toolbar.addAction(self.action) self.btn = QAction(QIcon(":/...

View answer
How can I determine which polygons contain other polygons?
Accepted answer
2 votes

You can achieve this using PostGIS spatial functions. St_Within will return True if geom A is totally within geom B. There are other similar functions you can use if this isn’t suitable, check the ...

View answer
Getting file paths of loaded layers in QGIS plugin?
2 votes

You can get a list of the layers in the table of contents and perform actions like so: legend = self.iface.legendInterface() layers = legend.layers() for each_layer in layers: if each_layer.type()...

View answer
How to create a link in the message body of email with Python?
Accepted answer
2 votes

Using the smtplib module you will need to create a HTML email and them simply put a HTML link in it. From the docs: import smtplib from email.mime.multipart import MIMEMultipart from email.mime....

View answer
Identifying Left and Right Mouse Button Clicks in PyQgis application
Accepted answer
1 votes

I think you are best trying to subclass an existing tool. Here is an example with the identify tool. class MySelectorTool(QgsMapToolIdentify): """Inherits the QGIS identify tool (tool is ...

View answer
GeoServer create map from image
Accepted answer
1 votes

You have the right idea. Geo-reference the image first, this can be done with the QGIS geo-referenceing tool, you will need some background mapping for reference. Publish the image with a WMS ...

View answer
How to get value and store it in a variable from a line edit or text edit in pyQT?
1 votes

You can grab the text like so: text = self.your_plugin_dlg.ui.yourLineEdit.text()

View answer
Disconnect QGIS from database without closing the whole program
1 votes

If you are using psycopg2 then you can close the connection to Postgres like so con.close()

View answer
How to choose workspace when uploading SLD to Geoserver with the REST API
Accepted answer
1 votes

Solved. Downloaded master from here. Then... cat.create_style("my_sld", f.read(), overwrite=False, workspace='workspacename')

View answer
Tick boxes for a qgis plugin written in python
Accepted answer
1 votes

Yes this is possible. I think you are looking for a checkbox. self.yourCheckbox = QtGui.QCheckBox(self.layoutWidget) self.yourCheckbox.setObjectName(_fromUtf8("Checkboxname")) Then to see if its ...

View answer
Get all points with in some range of a point (or range of point) in MySQL
Accepted answer
1 votes

I'm not to familiar with the MySQL spatial functions but from a quick look at the docs you should be able to to buffer your original points by 10m to create a new geometries and then use the st_within ...

View answer
Using Qt Designer to Create a Form in QGIS that can search for a specific point in a layer
1 votes

If you don't have much experience with PyQt, I would suggest that you use the QGIS Plugin Builder plugin to get you started. This will generate a basic plugin structure including UI which you can then ...

View answer
Recently-opened documents option in QGIS
Accepted answer
1 votes

You will need to add your layers/data and save a map file (.qgs extension). There is an 'Open Recent' option in the file menu for your recently opened map files. A QGIS project would be the equivalent ...

View answer
Query MYSQL database inside a python plugin
Accepted answer
1 votes

I would use string formatting. This example uses the MySQLdb module. import MySQLdb db = MySQLdb.connect(host="servername", user="username", passwd="yourpw", db="dbname") cur = db.cursor() cur....

View answer