Stack Exchange Network

Stack Exchange network consists of 175 Q&A communities including Stack Overflow, the largest, most trusted online community for developers to learn, share their knowledge, and build their careers.

Visit Stack Exchange

Questions tagged [python]

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

130
votes
5answers
24k views

Accessing ArcObjects from Python?

I would like to be able to script some things that are not exposed via arcgisscripting or ArcPy. How do I access ArcObjects from Python?
16
votes
2answers
11k views

Problem with import qgis.core when writing a stand-alone PyQGIS script

I am trying to write a stand alone python script in windows 7 that uses qgis.core and various other qgis libraries. I have found an old question on this subject here: Writing standalone Python ...
91
votes
13answers
103k views

Installing GDAL with Python on windows?

Can anyone explain how to install GDAL/OGR with Python on Windows? I have Windows Vista and I have tried following the information on the website and it does not seem to bind the exe files for me. ...
43
votes
1answer
22k views

Getting pixel value of GDAL raster under OGR point without NumPy?

I am working on a computational model of the abundance of wild pollinators across a landscape. The model itself is complete, and I am now struggling with a post-processing step. I have my GDAL ...
44
votes
7answers
78k views

Converting projected coordinates to lat/lon using Python?

I assume this is a basic question but I can't seem to find or recognize the solution. This site returns Point: X: -11705274.6374 Y: 4826473.6922 when you searching with the first key value of ...
17
votes
3answers
20k views

How to install 3rd party python libraries for QGIS on Windows?

How can I use 3rd party libraries on QGIS plugins on Windows? I've developed a plugin that uses rasterio and numpy for a customer, but he's having problems installing rasterio and numpy. Actually ...
40
votes
5answers
32k views

How to call gdal_translate from Python code?

Is it possible to use some gdal API to call gdal_translate from Python code? I do not mean simply executing the gdal_translate.exe from the file system, but rather call it somehow in code so I do not ...
12
votes
4answers
9k views

How to split a .tif image into several tiles?

I have an image of size 1GB (.tif), with the width and height 94000x71680. I would like to chunk this image into 20000X20000 tiles so that I can process them. How can I do this?
9
votes
2answers
3k views

Guidelines for using ArcObjects from Python

By far, Accessing ArcObjects from Python? is my most read and referenced Q&A on GIS Stack Exchange. In spite of that success, it's probably one of my weakest areas when it comes to actual use. A ...
11
votes
3answers
6k views

How to add support for FileGDB (Esri file gdb API) driver in fiona?

There has been a tons of questions on that but none of them solved my problem. I have a machine with: Windows 7 x64 Python 3.4.3 x64 gdal installed: gdalinfo --version --> GDAL 1.11.4, released ...
36
votes
4answers
23k views

Simple thematic mapping of shapefile using Python?

I wish to visualize geographical data in Python, without using ArcGIS/ArcPy, and make a map. On the internet I found how to make a thematic map using Python: Here is some code that I tried: ...
24
votes
4answers
32k views

How to write Shapely geometries to shapefiles?

Can someone demonstrate a simple way to write geometry data-structures from shapely into shapefiles? I am particularly interested in polygons with holes and linestrings. It would also be beneficial to ...
12
votes
3answers
9k views

Dissolving polygons based on attributes with Python (shapely, fiona)?

I have been trying to create a function that does basically the same thing that the QGIS "dissolve" function. I thought it would be super easy but well apparently not. So from what I have gathered ...
13
votes
3answers
18k views

gdal ImportError in python on Windows

Trying to import gdal for Python 2.7.3 on Windows XP: >>> import gdal Traceback (most recent call last): File "<stdin>", line 1, in <module> File "C:\Python27\lib\site-...
6
votes
3answers
3k views

Python, comtypes and ArcObjects: Error creating AppROT object

I am experimenting with comtypes and ArcObjects under Python 2.6.5 and ArcGIS 10 SP1. I'm using the pure Python method to wrap the ArcObjects OLBs described in this answer, but getting an error in the ...
4
votes
2answers
10k views

Intersect Shapefiles using Shapely

What I'd like to try and do is intersect some point buffers with census tracts, maintain their ID's and the tracts attributes. I found a sample from http://www.macwright.org/2012/10/31/gis-with-...
26
votes
4answers
35k views

How to fully load a raster into a numpy array?

I have been trying to check my filters on DEM raster for pattern recognition and it is always resulting in missing last rows and columns(like..20). I have tried with PIL library, image load. Then with ...
36
votes
7answers
17k views

Nearest neighbor between point layer and line layer? [closed]

I've asked this question several times on stackoverflow and irc between #qgis and #postgis and I also tried to code it or implement it my self in postgis with no real answer. Using programming (most ...
26
votes
7answers
26k views

How to set all pixels with value <= 0 to “nodata” in DEM raster?

I have a DEM raster with pixel values between about 3000 and -0.0003. I need to set all pixel with a value of 0 and smaler (<=0) to "nodata" (for later raster calculations and to reduce the ...
13
votes
2answers
3k views

How to call the interpolation plugin from the python console?

I would like to call the QGIS interpolation plugin function (TIN method) (Raster->Interpolate) from python console. I can't find the corresponding function within QGIS API or within the ...
6
votes
2answers
3k views

How to iterate over layers and export them as PNG images with PyQGIS in a standalone script

I would like to export specific layers as a png from a QGIS .qgs map. From the table of contents the script would first export the "boundary, climits, and Div1_Irrig_1956_0" layers as one png. The ...
49
votes
17answers
35k views

Learning Python programming with generic GIS goals in mind?

In your opinion, what is the best book/site to learn Python with GIS goals in mind? By "best", I mean: not very long (book) easy to understand (book/site) good practical examples (book/site) For ...
28
votes
4answers
24k views

How to get raster corner coordinates using Python GDAL bindings?

Is there a way to get the corner coordinates (in degrees lat/long) from a raster file using gdal's Python bindings? A few searches online have convinced me that there is not, so I have developed a ...
9
votes
2answers
5k views

Programmatically load composer from template and generate atlas using pyQgis

I Am trying to build a plugin to load a print composer from file, generate an atlas and export to image. So far I have been successful in loading the template and exporting it to image. I have been ...
20
votes
4answers
18k views

Using ogr2ogr to convert GML to shapefile in Python?

I am trying to convert a GML to an ESRI shapefile using ogr2ogr utility in a python script. I have successfully installed the GDAL/OGR package via osgeo but I am now struggling to find/understand ...
8
votes
2answers
4k views

How to automatically reload raster layers if source is changed in QGIS?

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. # #...
31
votes
10answers
15k views

Seeking Python tools/modules/add-ins for GIS?

With ArcGIS 10, Python has become the de-facto scripting language for ESRI. While leading Open source software like QGIS, GeoServer, PostGIS all supports Python. Thus it became important to know/learn ...
29
votes
4answers
31k views

Writing numpy array to raster file

I'm new to GIS. I have some code that converts infrared images of Mars into thermal inertia maps, which are then stored as 2D numpy arrays. I've been saving these maps as hdf5 files but I'd really ...
24
votes
1answer
2k views

Creating sector lights in QGIS?

I'm using QGIS 2.18. I need to create sector lights for navigational purposes on a map. I have the light sector data as fields giving becon_id, start degree, end degree and color in a shapefile with ...
26
votes
3answers
26k views

Clipping raster with vector layer using GDAL

I have installed GDAL using the Osgeo installer. How can I clip a raster layer with a vector layer programmatically? Is there any GDAL API available which can help me with this? I am using Python.
23
votes
5answers
21k views

How to add attribute field to existing Shapefile via Python without ArcGIS?

I have a Python script that adds an attribute field to a Shapefile if doesn't exist. This is easy to do with ArcGIS (graphically or via Python), but I'm looking for something that doesn't depend on ...
8
votes
2answers
2k views

Plugins crashing with “No module named qgsprojectionselectionwidget” in Windows?

My Python QGIS plugin works on Ubuntu (at least for me, and all fatal bugs reported so far are solved), but when I run it on QGIS installed from the official 2.10.1 64-bit installer for Windows (on ...
4
votes
1answer
2k views

How to render area that crosses 180°?

The problem is that the Chukotka Peninsula is located in the Western Hemisphere. So it is on the left side of Natural Earth Datasets. It needs to be moved to the right. I tried to use following srs(...
10
votes
6answers
12k views

Starting and stopping ArcGIS Server map services using Python?

Is it possible to programmatically stop and start ArcGIS Server map services using Python?
18
votes
1answer
22k views

GDAL/Python: How do I get coordinate system name from SpatialReference?

In Python, using GDAL, I've extracted a raster's projection as a WKT string as follows: wkt = dataset.GetProjection() # wkt is 'PROJCS["GDA_1994_Transverse_Mercator",GEOGCS["GDA_1994",DATUM["GDA_1994"...
6
votes
1answer
479 views

Buffering point with different distance toward N, E, S, W using ArcGIS for Desktop?

I want to create buffer polygon(with curved edges) from points like this using ArcGIS for Desktop. distance toward North from a point 5, toward South 1.5, toward west 1, toward East 2. all this ...
3
votes
3answers
2k views

Couldn't load SIP Module

After reinstalling QGIS, the desktop program runs but generates the python error "Couldn't load SIP Module Pythin support will be disabled" Because of this error, no plug-ins will load. I found a ...
33
votes
4answers
36k views

Python Script examples for geoprocessing shapefiles without using arcpy

I would like to use a Python script that is not based on arcpy to do things like query a shapefile by attributes, create new layer from selection, and calculate areas of a polygon and convert ...
62
votes
22answers
71k views

Python GDAL package missing header file when installing via pip

I asked this question on Stack Overflow before I realised this site existed. As this site it more appropriate, I'll ask it here too. I'm trying to install gdal from pip pip install gdal inside a ...
12
votes
2answers
13k views

Calculating shortest distance from point to line using QGIS?

What is the best method to calculate the distance from the nearest road for a series of address points in QGIS, having a very big dataset? (QGIS 2.0.1, Win XP) I read the answers to previous similar ...
16
votes
3answers
13k views

Generating GeoJSON with Python

I want to programmatically create a GeoJSON file using polygons from a shapefile but adding attributes from my own application. This is easily done for a shapefile: def create_data_dayer(self,...
9
votes
2answers
3k views

Is there a python option to “join attributes by location”?

I am trying to perform the function join attributes by location as found on the QGIS menu Vector>Data Management Tools. I am seeking an open source python option for this. I know arcpy has a spatial ...
7
votes
1answer
4k views

How to evaluate raster calculator expressions from the console?

How can I execute from the console an expression that should be used with the raster calculator? I'm searching for something like this: qgis.someRasterCalcClass.evaluate("boh@1 + boh@2", "outputfile....
8
votes
1answer
1k views

What is the purpose of some functions and files in QGIS Python plugins?

I'm just trying to understand the architecture of a QGIS Plugin created with the QGIS Plugin Builder, as well as the workflow and the linkage among generated files. If possible, I'd prefer a diagram. ...
4
votes
3answers
8k views

Using PyShp to convert polygons in *.csv to *.shp files?

I'm converting csv data to shapefiles using the pyshp python library. What I want to do is very similar to Using pyshp to convert .csv file to .shp?, except that I don't know how to handle polygons. ...
7
votes
2answers
8k views

Intersecting two shapefiles from Python or command line?

I'm new to working with geo data and trying to address a similar question to the one posted as How to calculate the size of a particular area below a buffer in QGIS Using command line and/or shapely/...
6
votes
3answers
7k views

How can I specify the CRS of a raster layer in pyqgis?

I manipulating netcdf raster data from the QGIS python console. The metadata of my netcdf file does not provide the Reference system. However I know it is 'EPSG:4326' I am writing a python script to ...
6
votes
2answers
3k views

ArcObjects + comtypes at 10.1 and newer

Has anyone played around with using ArcObjects in Python at version 10.1? I am having all sorts of problems, such as TypeErrors when wrapping the ESRI OLB modules and AttributeErrors when attempting ...
6
votes
3answers
6k views

Reclassifying rasters using GDAL and Python?

Using @SS_Rebelious very useful answer, I am trying to reclassify rasters using GDAL and Python. I have a grayscale raster (with values ranging from 0 to 255) and I want to reclassify it to a binary ...
6
votes
2answers
580 views

Odd behavior in a QGIS plugin: my function is triggered twice

I have a plugin with a function (triggered by a button) that selects a specific layer by name, then shows its attribute table. When I close the plugin and open it again, the attribute table pops up ...