Tagged Questions

Python is an open source interpreted programming language used in many GIS programs.

learn more… | top users | synonyms

0
votes
1answer
153 views

How to save image to disk with with gdal_translate?

I do: import os from gdal import * filename = 'c:/rast.jpg' outputTif = 'c:/rastOut.tif' os.system('gdal_translate filename outputTif') but it returns "1". gdal_translate doesn't save the image ...
1
vote
1answer
232 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?
0
votes
1answer
178 views

OWSLib and python3

Trying to install OWSlib-master (and 0.7.1) from https://github.com/geopython/OWSLib yields problems that ultimately seem to be related to python3 >c:\Python32\python.exe setup.py install running ...
0
votes
1answer
383 views

qgis plugin: “WindowsError: [Error 6] The handle is invalid”

OS: Windows 7 64bit GIS: QGIS 1.8 (qgis.org/downloads/QGIS-OSGeo4W-1.8.0-2-Setup.exe) path variable: GISBASE=C:\Program Files (x86)\Quantum GIS Lisboa\apps\grass\grass-6.4.3RC2 ...
1
vote
0answers
104 views

Using Python to Switch Layout Templates

Using ArcMap 10.1: Since there is not a way to control portrait or landscape of the layout view through python, is there a way to switch layout templates without opening a new mxd through python? ...
2
votes
2answers
203 views

Python Toolbox Raster Parameter Error

I borrowed a simple script I found online to clip a shapefile from the extent of a raster. It works perfectly from the ArcMap built in python command prompt. I modified is slightly to use in a tool. ...
3
votes
0answers
289 views

Field calculator error [duplicate]

NOTE: This problem is similar to one that was answered here: Why does Field Calculator return 0 values when decimals are expected? I'm relatively new to python, and am trying to run a simple field ...
0
votes
1answer
233 views

Using the API of QSpatiaLite plugin

I am using the popular QSpatiaLite plugin for QGIS. Since I am creating and modifying SpatiaLite tables directly with Python (using pyspatialite), I wonder whether I can automate tasks such as ...
1
vote
1answer
577 views

Why does Add Field to Layer File give “ERROR 000840: The value is not a Feature Layer”?

I'm trying to add a field to a layer file, but it always gives an error. What I did was making a closest facility layer and save the result as a layer and after that I tried to add a field, but then ...
3
votes
3answers
1k views

SearchCursor() fails to read feature class

First of all, I would like to apologize if this problem is trivial for you guys since I am very new to ArcPy and Python in general. I want write a script to read attribute table from a feature class ...
1
vote
2answers
165 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: ...
3
votes
1answer
244 views

Finding optimal network with python and network analyst in arcgis 10.0

Hello GIS StackExchange, I'd like to know if there's any way to find the shortest distance across the diagonals of a polygon. I am creating a network analyst solution to determine the most cost ...
8
votes
1answer
421 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! ...
2
votes
1answer
118 views

Script to either rotate existing text element or insert graphic element

I have about 300 maps that contain a text element that needs to be rotated. I am pretty new to python but I have heard how great it is. This seemed like the perfect task for python but I have had no ...
0
votes
0answers
60 views

Replace Null Values Field Calculator [duplicate]

I am using ArcGIS 10 and have a polygon shapefile in which many of the numeric fields are Null. The polygon shapefile in question is produced by joining a polygon shapefile with a point shapefile and ...
2
votes
1answer
347 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() ...
1
vote
1answer
1k views

Python GDAL: Write new raster using projection from old

If I read in a raster image as an array, then make some changes to the values in the array, how do I then save the array as a raster with the same projection information as the original array? In ...
1
vote
2answers
902 views

Merging many rasters using Python

I have a list of many many rasters. I want to have a simple and easy to understand script that takes this and merges it into one big mosaic. I found a similar question but the accepted answer adivises ...
2
votes
1answer
375 views

Am I over-complicating adding and then calculating fields? Suggestions for a better way? (Python)

I'm attempting to re-position a question I asked yesterday here. I am starting to think that the way I wrote my code just isn't the best way. Am I overcomplicating things? I know for a fact that ...
3
votes
1answer
203 views

Arcobjects: DisplayTransformation.FromMapPoint() transforms wrong

I want to transform map coords into page coords in ArcObjects in Python. So I do, say: >>> pApp = NewObj(esriFrame.AppROT, esriFrame.IAppROT).Item(0) >>> pDoc = pApp.Document ...
1
vote
1answer
131 views

How to save 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 = ...
3
votes
2answers
225 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 ...
2
votes
1answer
936 views

Incorrect field name resulted in RuntimeError: ERROR 999999 (Also, better code for adding and calculating fields)

This is the bottom half of my code (and it's been edited somewhat to share publicly). The code works perfectly fine when the fieldList has only three fields in it, but when I populate it with all 108 ...
1
vote
1answer
352 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 ...
2
votes
2answers
181 views

How to create a line from more than two points?

I have a loop which calculates two points for each iteration (x3,y3) and (x4,y4). As seen in the code these two points are added for each iteration, which gives i-1 lines. Each line has a individual ...
0
votes
1answer
561 views

How to clip raster by multiple polygons in multi rasters?

Using QGIS, I want to clip a raster by multiple polygons contained in a single shapefile. I read that gdalwarp can clip my raster by multiple polygons BUT the output is a single merged clipped raster. ...
3
votes
2answers
204 views

Is there a way to call the clip function in pyQGIS from the 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.
2
votes
2answers
963 views

How to add a column in QGIS via python

I have a point shapefile and a polygon shapefile in QGIS now I want to use the point shapefile's value add to polygon shapfile(be a column in the end) there are colors with each value and make the ...
11
votes
1answer
444 views

Teaching Python to Land Surveyors

Does anyone have any good examples of using Python to automate or simplify common surveying tasks? I'm teaching a Python/ArcPy lab this week for a GIS class. There are a number of surveying ...
13
votes
1answer
797 views

How can I utilize NumPy arrays to optimize big data geoprocessing?

I'm interested in learning how to utilize NumPy arrays to optimize geoprocessing. Much of my work involves "big data", where geoprocessing often takes days to accomplish certain tasks. Needless to ...
-2
votes
1answer
198 views

How to write Process Dialog log information to text file in ArcGIS?

I have created a custom model. When this model is run, it shows a process dialog which has some log information. I want to write that log information into the text file for further analysis. Does ...
1
vote
1answer
153 views

using ZonalStatisticsAsTable in python script

I use a python script in which the function ZonalStatisticsAsTable is called. In ArcGIS9.3 it all worked fine. Our company just went to ArcGIS 10.1 and now it doesn't work anymore. When looking ...
1
vote
2answers
701 views

python - Calculate field with part of file name

So I previously successfully used the sample code here: Model Builder - How to calculate Field using part of filename # Import standard library modules import arcpy, os, sys from arcpy import env # ...
3
votes
2answers
248 views

Need help assigning values to field using OGR in python

I've got a similar question to this one How to programatically populate a shapefile field with polygon areas in OGR?, but the solution doesn't seem to be working for me. I am trying to import a ...
2
votes
1answer
264 views

Calculate field result is float with Arc tool, integer with arcpy script

I am trying to calculate a field for some points within a python script using arcpy functions. (This is calculating the percentage visibility from a cumulative viewshed, if that matters.) # Process: ...
1
vote
1answer
144 views

How to calculate smallcircle on sphere

I use this python code to calculate a greatcircle: https://code.google.com/p/pyroms/source/browse/trunk/pyroms/greatcircle.py?r=39 After initializing the greatcircle I can calculate points on the ...
2
votes
1answer
301 views

View HTML field data with QT4 browers as a QGIS Run Feature Action Tool

I've successfully populated a sqlite table with an HTML-encoded-table as a field attribute, and so there is literally a Table within a single field value in sqlite, for each record. This is going to ...
1
vote
1answer
905 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 ...
3
votes
2answers
966 views

PyQgis overwrite shape file 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 = ...
0
votes
0answers
176 views

Help in GRASS/QGIS/Python

I have Idea about ArcGIS, and a bit of QGIS and zero programming knowledge, which I am trying for thesedays. I saw GRASS GIS and have started working with shapefiles, which are not being loaded... :( ...
1
vote
0answers
550 views

QGIS plugins with python dependencies [closed]

Problem: I have a Windows XP machine with Python 2.7.3 installed at ‘C:\Python27' and the scipy module installed at ‘C:\Python27\Lib\site-packages'. I installed QGIS 1.8 recently and started ...
3
votes
2answers
189 views

How do I tell GRASS where to find Python?

For some reason, when I start GRASS on my Mac it says that it has found Python 2.6.7. However, /usr/bin/python version is 2.7.2 and I can't find a lower version anywhere on my system. Potentially ...
4
votes
2answers
442 views

Python Script to convert a mass of KMLs to a single fGDB

I have a mass of KML files, approx 350+ that I need in a single fGDB. I lifted a string of code from ESRI help to attempt to do this - I got it working to the point of creating all the individual ...
5
votes
1answer
2k views

Cast arcpy result as an integer instead (arcpy.GetCount_management)

I am trying to get a number by counting how many points are in a shapefile. And this works (I think), except I then am running into trouble using that number somewhere else. Eventually, I'll be using ...
2
votes
3answers
454 views

What Python package to use to calculate midpoint?

I asked a question earlier about how to calculate a midpoint. I was wondering if there is a Python library that does this alreay?
3
votes
1answer
529 views

Python coding question, looping through feature classes, AddField, CalculateField, then errors (might be schema lock)

This is not a SDE question. File GDB. Hi, I have a general question on looping through feature classes in a file geodatabase. I have (attached) a python script that adds a ton of fields and ...
0
votes
0answers
264 views

Select record from table attributes in QGIS and Python

Can anyone tell how I can access to the attribute table of a shp and select a record from a specific row and column using Python (with console or a script). I've been looking for in the qgis API, but ...
1
vote
1answer
92 views

GeoDjango - Use GDAL python binding in the shell

I would like to use the GDAL python binding in my GeoDjango site. The aim of this is to use ogr2ogr capabilities in a script. I am on windows 7 so I have installed GDAL-1.9.2.win32-py2.7 downloaded ...
1
vote
1answer
251 views

ArcPy error: Add Feature Class to Terrain. [closed]

I'm writing a script to convert lidar data (in .las format) into a terrain without going through all the clicking and so I can send it out to neighboring states with similar programs (I'm using ArcGIS ...
2
votes
2answers
769 views

get value from attribute table and change symbology with QGIS and Python

I'm newbie developing plugins for QGIS using Python, this is the first one and it is very frustrating hehe. Ok, this is the situation, I have a 1 point layer in QGIS. Its attribute table has 4 fields ...