Skip to main content

All Questions

Tagged with or
Filter by
Sorted by
Tagged with
8 votes
4 answers
9k views

How to find the polygon inside which a point lies?

I have a layer with polygonal features. Each feature has attributes and values. I also have a list of co-ordinates and I would like to know which feature (or polygon) the co-ordinates lie in. Could ...
Shubham Goyal's user avatar
5 votes
2 answers
3k views

How to add layer/raster with specific position in the QGIS layer list?

I use addRasterLayer(rast,'Name') but this adds the raster to the top. It is possible to set position when I add raster at once? Is it possible??
user7172's user avatar
  • 1,529
2 votes
1 answer
665 views

How to store attributes of a large shapefile in a list?

I am trying to store the attributes of a shapefile into a list. With following code it works for smaller shapes: addA = [] While provider.nextFeature(feat): attrs = feat.attributeMap() for (k,...
user18550's user avatar
12 votes
1 answer
8k views

Writing vector layer to CSV file with geometry using PyQGIS?

I use Python try to write vector layer file to csv file with this code: QgsVectorFileWriter.writeAsVectorFormat(mylayer, r'c:\temp\xyz.csv', "utf-8", None, "CSV") It can export to xyz.csv but only ...
Anubiz's user avatar
  • 121
5 votes
2 answers
4k views

Setting up Python 2.7 to work in both QGIS and ArcGIS Desktop?

I have both ArcGIS 10.1 and QGIS 1.8 installed and both include Python 2.7 in slightly different setups and in different folders (c:\Python27\ArcGIS10.1\ and c:\Program Files (x86)\Quantum GIS Lisboa\...
Uffe Kousgaard's user avatar
13 votes
7 answers
10k views

Calculating Image boundary / footprint of satellite images using open source tools?

I need to create the polygon outlines of several single layer raster images, not the extent/bounding box, but the area without the nodata values, as shown here: Creating shapefile showing footprints ...
spib's user avatar
  • 483
0 votes
1 answer
131 views

Make many lines in one layer (Python)

I what to create many lines with this code: v_layer = QgsVectorLayer("LineString", "cable", "memory") pr = v_layer.dataProvider() seg = QgsFeature() seg.setGeometry(QgsGeometry.fromPolyline([...
user1573901's user avatar
0 votes
2 answers
186 views

Python to get ids from shapefile don't return all records

I have some Python code to get the ids and georeference from a shapefile: canvas = qgis.utils.iface.mapCanvas() allLayers = canvas.layers() nos = QgsFeature() for i in allLayers: if i.name()=='...
user1573901's user avatar
0 votes
1 answer
191 views

How to convert geometry of shapefile to decimals

I try to create a line with two points. These points are obtained in a shapefile layer. How can I convert that points to decimals?
user1573901's user avatar
0 votes
2 answers
2k views

How to display data from a feature?

I want to display data based on the feature currently selected/clicked on. I am following a tutorial from http://www.qgisworkshop.org/html/workshop/plugins_tutorial.html. It initially shows you how ...
Cedric Ramirez's user avatar
2 votes
1 answer
2k views

How to use expression in QgsVectorlayer label by using python?

how to show the two field values as a label on features. I have done it for a field called "ErrorDescr" with this i need to show another field values. Other field is "MarkerId" layer....
venkat's user avatar
  • 1,051
13 votes
2 answers
17k views

How can I programatically create and add features to a memory layer in QGIS 1.9?

I had a working plugin in QGIS 1.8 which read data from an MSAccess database and added it to a series of memory layers. There is some processing involved in the interim so I don't think simply using ...
Adam Bioletti's user avatar
6 votes
1 answer
4k views

Understanding QGIS API documentation to write Python code using QgsVectorLayer?

I am not sure how to use the API documentation to code in Python. For example, I want to determine whether a layer is a point, line or polygon layer and found the following in the API documentation: ...
user1420372's user avatar
1 vote
1 answer
2k views

Running a script with QgsFeature from within the console

I am trying to run a script from the QGis Python console (similar to: http://spatialgalaxy.net/2012/01/27/qgis-running-scripts-in-the-python-console/) The line feat=QgsFeature() operates fine from ...
user1420372's user avatar
4 votes
3 answers
7k views

Setting Marker Line symbol for QgsVectorLayer by using Python [closed]

QgsVectorLayer Right click->Properties->Style->Single symbol->click on simple line in tree node ->symbol layer type -> Marker line How do I set marker line symbol programmatically by ...
venkat's user avatar
  • 1,051
-1 votes
4 answers
3k views

Making line with arrow head in QgsVectorLayer using Python [closed]

I need to draw a line with an arrow head or after drawing the line I need to make it as arrow head line by using Python or can we set any arrow head symbol for line features by using Python? I seek ...
venkat's user avatar
  • 1,051
1 vote
1 answer
1k views

Open QGIS project with parameters

I am looking at a piece of work to deploy QGIS as the standard within an organisation. There is an existing piece of software that I need to link to QGIS so that when a button is pressed within the ...
Mark's user avatar
  • 605
34 votes
1 answer
10k views

Drawing perpendicular lines in PyQGIS

I have a situation like this: What I need to do is to connect each point to every line that is at most, let's say 200 m, away from the point. In other words, I need to draw a perpendicular line from ...
PeterBorook's user avatar
3 votes
1 answer
4k views

How to "Merge Selected Features" with python?

I have been looking for the answer to this question for some time now, but can't seem to find it! My problem is straight forward: I have one layer It contains lots of features (only polygons), say ...
Simon Ternsjo's user avatar
4 votes
2 answers
4k views

Creating QGIS layers in python console vs stand-alone application

I am having trouble creating a QGIS vector layer in a stand-alone python script while exactly the same code works fine in python console inside QGIS. The following code results in a proper ...
srk's user avatar
  • 173
12 votes
3 answers
7k views

Automatically reloading raster layers if source is changed in QGIS using PyQGIS

How to automatically reloaded raster layer if source is changed? (The path is the same but inside source file are changes) I use: qgis.utils.iface.mapCanvas().refresh() but layer not refresh. # #...
user7172's user avatar
  • 1,529
17 votes
1 answer
6k views

Is it possible to show our custom message in QGIS Status bar using python?

Is there any way to show our custom message in Qgis Status bar using python? Just like in arcgis IApplication.statusbar.message(0) = "Please wait..." like that is there any option to show progressbar ...
venkat's user avatar
  • 1,051
4 votes
1 answer
2k views

Using WHERE CLAUSE to filter features by its attribute in PyQGIS [closed]

How do I get features by their attributes (similar to Iqueryfilter in ArcObjects) in QGIS using Python? Instead of getting all features and filter it manually, is there any option to use whereclause ...
venkat's user avatar
  • 1,051
3 votes
1 answer
603 views

How to get a message when the map is moved in QGIS?

I want to get a message when every time I move the map. I had: def info(self): QMessageBox.information( self, self.tr( "Info" ), self.tr("info") ) I suppose that used to be something like that.....
user7172's user avatar
  • 1,529
18 votes
4 answers
19k views

Filter features based on their attributes using Python

How to get features by their attributes (similar to 'IQueryFilter' in ArcObjects) in QGIS using Python? Instead of getting all features and filter it manually, is there any option to use where clause ...
venkat's user avatar
  • 1,051
5 votes
1 answer
3k views

Joining table to shapefile using PyQGIS [closed]

Joining shapefiles is a relatively straightforward proess in QGIS using 'add vector join' in the layer properties menu. I can add a csv file as a vector layer, as well as a shapefile, and join the two ...
Krausers's user avatar
  • 554
15 votes
1 answer
6k views

Seeing print commands through Python Script while programming plugin for QGIS

Is there a way that from running a custom plugin made for QGIS that a Python Shell can appear when the plugin is run, like a debug screen? I'm asking this to know if there is a way to see print ...
NothingToSay's user avatar
9 votes
1 answer
3k views

Speed of editing attributes in QGIS from a Python plugin

I'm trying to edit the value of an attribute for each feature in a layer using a QGIS Python plugin. I've found that doing this outside of editing mode is much slower than while editing (even ...
Snorfalorpagus's user avatar
1 vote
1 answer
148 views

Custom Model should be used with ArcMap or ArcCatalog?

I have one basic question , when you create custom model using model builder in ArcGIS. It should be used with ArcMap or ArcCatalog? Reason I am asking this question is I have created a model and I am ...
Dharmesh's user avatar
3 votes
1 answer
2k views

Python Script that calls the Voronoi Polygons Function?

I've been looking to see if there was a way to call Voronoi Polygons function found in Vector/Geometry Tools, directly from the code but I have not found one. Does this currently exist? Is there a way ...
NothingToSay's user avatar
4 votes
1 answer
3k views

How to get CRS of a raster layer in pyqgis?

I have this problem accessing to the coordinate reference system(crs) of a raster layer map. I wonder if such thing is possible? I have used this xml from GDAL open map service to load in a raster ...
Justin's user avatar
  • 41
3 votes
2 answers
3k views

Determining coordinates of corners of raster layer using PyQGIS?

How can we determine the coordinates of the corners of the raster layer? The image opens function QgsRasterLayer.
user17033's user avatar
13 votes
1 answer
576 views

How to save python session in QGIS?

After running a lot of scripts in QGIS' python console, I have more than 10 dictionaries and lists, and I need these for further analysis. Is there a way to save python session, with all these ...
PeterBorook's user avatar
1 vote
1 answer
1k views

How to add MS SQL table using python console?

I have MS SQL Server 2008 R2 database. How to add MS SQL Table using python console in QGIS?
Mari's user avatar
  • 11
2 votes
2 answers
1k views

How to handle adding a PostGIS layer in pyQgis without saving password?

I'm writing python plugin and trying to find the right way to add PostGIS layer on the map without storing user password. After adding layer on the map, I strip out the password from uri like this: ...
AlexSV's user avatar
  • 319
12 votes
1 answer
2k views

How to address the new "Task-Completed" QgsMessageBar in Python?

I am really amazed what huge steps the QGIS development has taken in the last months. The new iconset, the improved Print composer and many more changes to be seen in QGIS 2.0 are really awesome! ...
Curlew's user avatar
  • 8,180
5 votes
1 answer
3k views

How to add one or more points to an existing polyline or polygon?

Using the following code, I make a polyline with two points. vl = QgsVectorLayer("LineString", layerName, "memory") pr = vl.dataProvider() vl.startEditing() fet = QgsFeature() fet....
Toke's user avatar
  • 379
4 votes
2 answers
2k views

How to check if two qgsPoints are equal in PyQgis

I have two points: a=QgsGeometry.fromPoint(QgsPoint(227739,908343)) b=QgsGeometry.fromPoint(QgsPoint(227739,908343)) but when I run: a==b it returns False. What am I doing wrong? Update: it ...
PeterBorook's user avatar
1 vote
0 answers
217 views

Saving after using fet.setFeatureId in PyQGIS?

By using the following code, I want to change the id of the line when saving the line. But the setFeatureId command, gives a false when doing the commitChanges(). Any idea how to change the id? vl ...
Toke's user avatar
  • 379
4 votes
2 answers
663 views

How to write an equivalent to MapBasic's CreateLine in pyQGIS?

I know this kind of question has been asked, in part, before - specifically: Seeing QGIS Python Commands and: How is object created as line using createline stored in .tab file? but this is a specific ...
Andrew Tice's user avatar
2 votes
1 answer
1k views

How to store selected attributes of vector layer using PyQGIS

I'm following this PyQgis workshop: http://www.qgisworkshop.org/html/workshop/python_in_qgis_tutorial2.html#accessing-data-attributes I have a point layer shapefile. I want to be able to retrieve and ...
PeterBorook's user avatar
11 votes
3 answers
9k views

Calling clip function in pyQGIS from python console?

Is there a way to call the clip function in QQGIS from the python console? It is found under geoprocessing tools in the vector menu.
Toke's user avatar
  • 379
3 votes
1 answer
2k views

How to calculate all paired shortest path using PyQGIS?

The code for shortest path analysis with PyQGIS specifies start and end nodes explicitly: pStart = QgsPoint( -1.37144, 0.543836 ) pStop = QgsPoint( -1.1027, 0.699986 ) http://www.qgis.org/pyqgis-...
Alex's user avatar
  • 935
2 votes
1 answer
2k views

How to get vector feature by mouse location?

I'm writing a photo grouping plugin. My current problem can be broken up into "end goal" and "baby steps", because I think that's what I want. But if there's a way to get to the end by a different ...
B Freed's user avatar
  • 45
4 votes
1 answer
5k views

How to change vector attributes values?

I want to change vector attributes values. i could not get the command fet.setAttribute indeed, it is mentionned in http://hub.qgis.org/issues/7223 that: "The QgsFeature instance now must be ...
nano's user avatar
  • 41
6 votes
2 answers
4k views

PyQgis overwrite shapefile and adding layer to QGIS

I am creating a shapefile in Python by: driver = ogr.GetDriverByName('ESRI Shapefile') datasource = driver.CreateDataSource('c:/temp/toke2.shp') layer = datasource.CreateLayer('layerName',geom_type=...
Toke's user avatar
  • 379
10 votes
6 answers
16k views

Creating label formatted like " 1,000' " from numeric field?

This question builds on a previous question I came across at gis.stackexchange: How to easily edit attribute data using Regular Expressions? Perhaps someone can point me in the right direction? I ...
clhenrick's user avatar
  • 1,843
2 votes
1 answer
3k views

How to write a CSV from Python console in QGIS?

I am trying to write out a CSV file from a vector layer made up of points using the python console in QGIS. I've tried the following command: QgsVectorFileWriter.writeAsVectorFormat(layer_Map, Folder ...
Dom's user avatar
  • 83
2 votes
3 answers
2k views

Relative paths not working in model builder

I checked "Store relative path names" in my model, but ArcGIS seems to ignore the settings - the paths are always the same as on my computer. Plus, the "Store relative path names" unchecks ...
Pavel V.'s user avatar
  • 1,517
6 votes
3 answers
2k views

Save a layer for each unique value using Python in QGIS

I have a map, in which each region is defined as an attribute of the map (I can select each region from the attribute table). I am trying to create new layers each one containing only 1 region using ...
Dom's user avatar
  • 83