The Stack Overflow podcast is back! Listen to an interview with our new CEO.

Questions tagged [python]

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

Filter by
Sorted by
Tagged with
11
votes
3answers
4k views

What are pros and cons of Python add-ins vs .NET add-ins to ArcGIS for Desktop?

I found in ESRI .NET help: Python All ArcGIS Desktop applications include an embedded scripting language called Python. Many areas of ArcGIS—particularly geoprocessing—are accessible through ...
11
votes
2answers
8k views

Reading postgis geometry with shapely

I am doing a small-scale workflow in ipython notebook with geopandas and shapely, pulling a bunch of geospatial data, sometimes from shapefiles, sometimes from postgis (where more expensive processing ...
11
votes
2answers
12k views

How to change the value of an attribute using QgsFeature in PyQGIS?

I would like to update one attribute of a feature. However, I don't know to update it using the feature object. I have to use data provider to update it. layers = QgsMapLayerRegistry.instance()....
11
votes
2answers
14k views

Creating Shapely MultiPolygons from shapefile MultiPolygons

I'm reading a shapefile using Fiona: with fiona.open('data/boroughs/boroughs_n.shp') as source: mpolys = [p for p in source] candidate = polys[0]['geometry'] this gives me a dict containing a ...
11
votes
3answers
1k views

Downloading and processing raster files in Python? [closed]

I am fairly new to python and seek guidance for a question which might sound trivial to many. Is there a way to use 'wget' in a python script to download raster files from a server and process them ...
11
votes
1answer
7k views

GDAL polygonize in python creating blank polygon?

I am having trouble using the Polygonize function in python. The cookbook example for this can be found here. The relevant portion of my code is: sourceRaster = gdal.Open('myraster.tif') band = ...
11
votes
2answers
1k views

How to add different sized rasters in GDAL so the result is only in the intersected region

I'm writing a Python method that adds two rasters and generates a single raster output. For reasons beyond my control, the extents of the input rasters are different, but they do overlap. Is it ...
11
votes
4answers
13k views

using shapely: translating between Polygons and MultiPolygons

[EDIT: the solution to this was simply to use OGR to read shapefiles. See geographika's example.] In an ESRI shapefile, there is no distinction between Polygons and MultiPolygons. Furthermore, there ...
11
votes
3answers
8k views

What units are used by GeoPandas/Shapely area and distance functions?

it looks like a silly question, yet I can't find clear answer on that: what units geopandas/shapely use calculating distance/area between objects?
11
votes
2answers
4k views

Measuring distance in spherical Mercator vs zoned UTM

I've got points in WGS84 lat/long and I'd like to measure "small" (less than say 5km) distances between them. I can use the haversine formula from http://www.movable-type.co.uk/scripts/latlong.html ...
11
votes
1answer
11k views

Python can't read shapefile

I am trying to open a shapefile with Jupyter notebook, but I can't get it to open. The shapefile is located in the same folder as my workbook, and Python can't identify it even if I use the full path. ...
11
votes
2answers
963 views

Can ArcGIS and OSGeo4W share the same python install? [duplicate]

I don't like unnecessary duplication. Is it possible to install python only once and have both ArcGIS and OSGeo4W using it?
11
votes
1answer
277 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 ...
11
votes
3answers
6k views

Python equivalent of gdalbuildvrt

Is there a way to perform the same task as the gdalbuildvrt utility using GDAL Python bindings? So far I have not found any way to do this other than creating a vrt of a single dataset and manually ...
11
votes
3answers
7k 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 ...
11
votes
1answer
26k views

Reading, modifying and writing a geotiff with GDAL in python

I'm trying the learn the ropes of Remote Sensing image processing using Python GDAL bindings and numpy. As a first attempt, I'm reading a Landsat8 geotiff file, do a simple manipulation and write the ...
11
votes
2answers
578 views

Count raster value in a bounding box (spatial extent)

Given a bounding box, how can I count the number of specific values (say, I am interested in the number of value == 1 ) in a raster in 1) arcpy, or 2) raster package in R?
11
votes
2answers
732 views

How to set transparency to multiple raster values with Python

With the following code I can set 100% transparency to raster value 0: map=None for lyr in QgsMapLayerRegistry.instance().mapLayers().values(): if lyr.name() == "some_layer": map= lyr tr=None ...
11
votes
2answers
17k views

How to create a Shapely LineString from two Points

If have two points, from which I want to create a straight LineString object: from shapely.geometry import Point, LineString A = Point(0,0) B = Point(1,1) The Shapely manual for LineString states: ...
11
votes
3answers
8k views

Getting intersection of multiple polygons efficiently in Python

I would like to get the intersection of multiple polygons. Using Python's shapely package, I can find the intersection of two polygons using the intersection function. Is there a similar efficient ...
11
votes
3answers
3k views

Image processing using Python, GDAL and Scikit-Image

I am struggling with a processing and hopefully I will be able to solve here. I work with Remote Sensing applied to Forestry, especially working with LiDAR data. The idea is to use Scikit-image for ...
11
votes
1answer
7k views

How can I add button to the QGIS toolbar or create my own toolbar?

I want to create a button and add it to the QGIS toolbar or alternatively create my own toolbar and add the button here. A plugin should be started when the user clicks the button.
11
votes
1answer
5k views

Is it possible to take automatically a “screenshot” of my selected feature in QGIS using Python?

I am implementing a tool which allows the user to create a profile of a feature (in my case urban parcels). Is it possible to automatically take a screenshot of this feature (displayed in a QGIS ...
11
votes
1answer
2k views

Copying file geodatabase on ftp site to local disk using Python?

There is a file geodatabase sitting on an ftp site that I would like to download with a Python script. Right now I'm thinking one way to do this is to copy the ftp geodatabase to a geodatabase on my ...
11
votes
2answers
2k views

GeoTIFFs made in GDAL don't have min/max range when loaded in Arc/QGIS

I'm creating some floating point rasters in GDAL with the GeoTIFF driver. When I load the resulting images into QGIS or Arc the default symbology puts the min at -3.40282e38 and max to 3.40282e38, so ...
11
votes
2answers
3k views

How to compute Straight Skeletons using Python?

Is there a Python package which provides an implementation of a Straight Skeleton algorithm? I'm aware that the open source (C++) project CGALcontains an implementation but it seems like cgal-...
11
votes
1answer
3k views

How to hide/show QGisVectorLayer from Python code?

Once created a layer, how can I hide/show it? I can enable/disable rendering of a specific layer by selecting the checkbox through QGIS, but I need to do it programmatically from python code. How can ...
11
votes
1answer
12k views

Python: find a method to calculate the “inner centroid” (also known as labelPoint in arcmap) of a polygon

i am looking for a method to compute the X,Y coordinate of a inner point (also known as labelPoint in arcmap) of a (irregular) polygon. I am try to find a solution without the use of ArcGIS module ...
11
votes
1answer
20k views

How do I maintain a resposive GUI using QThread with PyQGIS

I have been developing some batch processing tools as python plugins for QGIS 1.8. I have found that while my tools are running the GUI becomes non-responsive. The general wisdom is that the work ...
11
votes
2answers
252 views

How could I rate roads for scenic drives?

relative GIS newbie here. I've been working on a personal project to rate roads on how nice a ride they'd be on a motorcycle. I wrote a Python program to work through road data in the TIGER dataset (...
11
votes
3answers
2k views

Histogram Matching using Python to improve mosaicking process of multiple overlapping rasters?

I am trying to do histogram matching using Python to improve the mosaicking process of multiple overlapping rasters. I am basing my code on that found at: http://www.idlcoyote.com/ip_tips/histomatch....
11
votes
2answers
1k views

Metadata -auto build using python

We have a large (10,000 plus) repository of spatial data (shp/gdb/tab vectors and ecw/tif rasters and also las, xyz and DEM data) where some have metadata records in xml using anzlic metadata editor. ...
11
votes
1answer
3k views

Exit script with Python

I've got a Python script for ArcGIS that I'm working on, and I'd like to have the ability to have the script quit if it doesn't have the necessary data available. I tried a straight up sys.exit() but ...
11
votes
1answer
918 views

QGIS export composer as pdf in python

I have a QGIS project which contains a composer. Of course if I go into the GUI I can export it as a pdf etc. For my make script though I want to have this done via a python script. From reading ...
11
votes
1answer
603 views

Python: Break linestring based on condition

I have a geopandas dataframe of a bunch of linestrings that have some data associated with each vertex/point: Point_x = (Lat, Lon, Time, ID, Data1, Data2, Data3) The points are converted to ...
11
votes
1answer
1k views

How to access QGIS module from my virtualenv

I am running an Ubuntu 14.4 and I have installed a python virtual environment. Then I pip installed several python libraries (gdal, lxml, psycopg2 etc.) Also in my system I have the module for QGIS. ...
11
votes
1answer
950 views

What's the binary format of ENVI (Classic) ROIs?

I'm a Pythonist in an office full of ENVI/IDL users. I've created some tools to help bridge the gap, but one big stumbling block is ENVI Classic .roi files, which my colleagues use a lot. I can ...
10
votes
3answers
19k views

Converting X,Y coordinates to lat/long using pyproj and Proj.4 returns the wrong coordinates

I'm writing a python script that reads multiple XML files containing x and y coordinates and combines them all into a single csv file. Latitude and Longitude are required fields in the csv, but I am ...
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?
10
votes
2answers
9k views

Joining (concat) list of similar dataframes in geopandas?

I have a list of dataframes, all of the same structure and all are polygons. How can I add them all together using geopandas?
10
votes
3answers
13k views

'NoneType' object has no attribute

I am new to python geospatial programming. i ran the following script and got the corresponding error message >>> import osgeo >>> import osgeo.ogr >>> shapefile = osgeo....
10
votes
2answers
9k views

How to bypass errors in arcpy for/while loop?

I have a handy script tool that loops through a workspace and renames and copies shapefiles to a feature dataset. However, if there is a corrupted shapefile somewhere in the workspace the script ...
10
votes
5answers
4k views

Who uses FME Python extension and how?

I saw a great interface to FME with Python What you guys are doing with it? I want ideas.
10
votes
2answers
7k views

Filter by bounding box in geopandas?

I have a geopandas dataframe in EPSG:4326 and I'd make a new dataframe consisting of all the rows that fall within a certain bounding box. First I get the bounding box that I care about (which is ...
10
votes
1answer
7k views

Python Script for getting elevation difference between two points

I have several stream segments 1000 Km long. I need to find the elevation difference between two consecutive points of distance 1 Km starting from the upstream to downstream. How can I get the ...
10
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 ...
10
votes
2answers
21k views

Obtain coordinates and corresponding pixel values from GeoTiff using python gdal and save them as numpy array

How can I obtain projected coordinates as well as the actual pixel values at those coordinates from a GeoTiff file and then save them into a numpy array? I have arsenci020l.tif file, and its ...
10
votes
3answers
4k views

How do I prevent Qgis from being detected as “not responding” when running a heavy plugin?

I use the folowing line to inform the user about the status: iface.mainWindow().statusBar().showMessage("Status:" + str(i)) The plugin takes about 2 min to run on my data set but windows detects it ...
10
votes
2answers
7k views

Point (of a linestring) within Polygon using ogr and Python

I'm currently working on a project in which I need to build a topological network out of the geometry features I find in shapefiles. So far using Ben Reilly's open source project I've managed to ...
10
votes
2answers
6k views

How to change the color of a vector layer in pyQGIS?

Is it possible to change the color while adding a vector layer? I have a vector layer with water areas and want to load it with a blue color style. The layer is added with: QgsMapLayerRegistry....