Questions tagged [python]

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

Filter by
Sorted by
Tagged with
10
votes
1answer
4k views

Drivers of Fiona

What drivers does the python package fiona have? When I check the manual it says [...] and the possible formats are enumerated in the fiona.drivers list. However, when I type in python from fiona ...
10
votes
1answer
11k views

Georeferencing raster using GDAL and Python?

I want to georeference a raster using python and GDAL. My current approach is to call gdal_translate and gdalwarp using os.system and an ugly list of ground control points. I'd really like a way to do ...
10
votes
2answers
18k views

Using pyshp to convert .csv file to .shp?

I am trying to understand how I can use the csv module in python to open a csv file in the same folder as the python script, and then create a shapefile using the shapefile module pyshp. The csv file ...
10
votes
4answers
10k views

Getting elevation at lat/long from raster using python?

I was wondering if anyone has some experience in getting elevation data from a raster without using ArcGIS, but rather get the information as a python list or dict? I get my XY data as a list of ...
10
votes
3answers
11k views

Creating button in ArcMap to run Python program?

I have a script that I want to run within ArcMap when a button in a toolbar is clicked, and so far I have only been able to make the script into a script tool. I need it to run as a command, not as a ...
10
votes
4answers
7k views

Reading raw data into geopandas

Is it possible to read raw data into a geopandas GeoDataFrame, a la a pandas DataFrame? For example, the following works: import pandas as pd import requests data = requests.get("https://data....
10
votes
5answers
2k views

How to convert line simple features to topological network?

using Gdal/ OGR is there a way to convert a shp, kml, or PostGIS line layer into a network of nodes and segments so it can be used in packages such as networkx?
10
votes
5answers
3k views

Raster diff: how to check if images have identical values?

Is there a means to check to see if any 2 given raster layers have identical content? We have a problem on our corporate shared storage volume: it's now so big that it takes over 3 days to conduct a ...
10
votes
2answers
7k views

Converting PostGIS table to Shapefile in Python?

I want to convert a PostGIS table into a shapefile (without using pgsql2shp). In order to create a geometry in the shapefile I have to give the Xmin,Ymin and Xmax,Ymax, and the geometry which I have ...
10
votes
2answers
10k views

How to create polygon shapefile from a list of coordinates using python gdal/ogr?

I am trying to create a polygon shapefile from a list of coordinates using open source python tools. The following is what I have so far which was hacked together from the Python GDAL/OGR Cookbook and ...
10
votes
2answers
16k 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: ...
10
votes
3answers
17k views

Reading National Elevation Dataset (ArcGrid/GridFloat/IMG) with Python only tools?

I've found high precision elevation (1/3 - 1/9 arcsecond resolution) data from the National Elevation Dataset provided by the USGS. It comes int IMG, Arcgrid, and GridFloat formats. I know ArcGrid ...
10
votes
1answer
3k views

How to see 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 along when the plugin is run, like a debug screen? I'm asking this to know if there is a way to see print ...
10
votes
2answers
17k views

How to return individual address components (city, state, etc.) from GeoPy geocoder?

I'm using GeoPy to geocode addresses to lat,lng. I would also like to extract the itemized address components (street, city, state, zip) for each address. GeoPy returns a string with the address -- ...
10
votes
1answer
3k views

Convert shapefile from projected coordinates using Python

Newbie here struggling with GIS. I am trying to map out wards for the city of Milwuakee using shapefiles found on their county website county website. I am following the thread here with some success. ...
10
votes
1answer
2k views

Birch algorithm does not cluster as expected

I'm using Birch algorithm from scipy-learn Python package for clustering a set of points in one small city in sets of 10. I use following code: no = len(list_of_points)/10 brc = Birch(...
10
votes
1answer
1k views

How to visualize azimuthal data with uncertainties?

I am trying to make a figure showing azimuthal data with a different range of uncertainties at each point. This oldschool figure from a 1991 paper captures the "bowtie plot" idea that I'm aiming for: ...
10
votes
4answers
13k views

How to import qgis.core to Python app?

I'm new to Python. I want to create GIS app with Python using QGIS library on Window 7 64 bit. The way I do: install QGIS 1.7.0 I set PYTHONPATH=D:\Program Files (x86)\Quantum GIS Wroclaw\apps\qgis\...
10
votes
5answers
7k views

update one shapefile attribute table with values from another dbf table

I try to explain here what I am trying to do: I have one shapefile and one independent dbf table with the same fields. In the dbf table all the fields are populated but in the shapefile attribute ...
10
votes
4answers
2k views

Is there any way to get an email when ArcGIS Server services are stopped/down?

Occasionally, but all too often unfortunately, my AGS services just stop for no reason. I don't usually notice this until the users call me and ask why their maps have no data. Is there any way (I ...
10
votes
1answer
8k views

GeoPandas to_file() saves GeoDataFrame without coordinate system

I have GeoPandas 0.2.1 py27_0 fiona 1.7.0 np110py27_1 Python 2.7.10 installed in Anaconda 2-4.1.1-Windows-x86 environment. I am able to construct GeoDataFrame by reading input datasets and ...
10
votes
1answer
1k views

Teaching Python to Land Surveyors [closed]

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 ...
10
votes
1answer
6k views

When iterating over a vector layer with pyqgis, how do I check whether a feature is selected?

While iterating over a vector layer using the following code (summerized from the example in the pyqgis cookbook), is there a way to check whether a feature is selected? provider = vlayer....
10
votes
1answer
1k views

QGIS Modeler if/else condition, custom script for Modeler

I want to make a simple if/else function inside my Model and I wanted to know if it's possible or not. I want this thing to do that if an Input for 'Segment Layer' is selected that it doesn't have ...
10
votes
2answers
1k views

How to catch PostgreSQL/PostGIS errors in GDAL/OGR Python bindings?

Is it possible to catch PostgreSQL output error messages in OGR after a query has failed? For example conn.ExecuteSQL('SELECT * FROM non_existing_table;') In Postgres this returns an error message: ...
10
votes
2answers
773 views

Aggregating Polygons To Meet Privacy Requirements

I have a point feature class representing office locations of all employers in a certain industry. The feature class has an attribute for storing the number of employees working at each office. ...
10
votes
1answer
4k views

Help with PostGIS polygon geometry - non-closed rings

I've picked up a copy of the super-wicked book 'Python Geospatial Development' by Erik Westra (Amazon link), and I'm working through it. Currently, it's teaching me to load GSHHS coastline data from a ...
10
votes
1answer
4k views

Geopandas Line Polygon Intersection

I'm trying to find where multiple lines intersect a polygon for two different geodataframes: from shapely.geometry import Polygon, LineString import geopandas as gpd polygon = Polygon([(0, 0), (1, 0)...
10
votes
1answer
1k views

Accessing file geodatabase (.gdb) rasters with GDAL?

I'm working on a tool that converts raster layers to arrays for processing with NumPy, and ideally I would like to be able to work with rasters that come packaged in a .gdb without exporting them all (...
10
votes
1answer
1k views

Arcobjects in Python: assign interface to objects with feature (shape) geometry

I am trying to use ArcObject in Python. I do have problem with assigning an interface (i.e. IZ.InterpolateZsBetween) to my object with geometry data, code is: from Comtypes.client import CreateObject,...
10
votes
2answers
358 views

Determine minimum number of polygons from shapefile to cover an area of interest

I have a large number shapefiles representing areas of interest for an analysis that will be conducted using various sources of satellite imagery (IKONOS, RapidEye, etc.). Unfortunately, the imagery ...
10
votes
2answers
6k views

Extract data from netcdf using a shapefile polygon in python

I need to subset data from a NetCDF using a specific shapefile. The data are sea surface temperature and ocean color at 1/4 degree resolution. I have 4 polygons describing the US. Northeast ...
10
votes
2answers
767 views

Can ArcGIS ModelBuilder open Excel file for manual editing, then feed those edits back into model?

I have been tasked with creating a model using ArcGIS ModelBuilder, that initially runs a couple of geoprocessing tasks, before then joining an Excel table to the result of those geoprocesses. However,...
10
votes
2answers
5k views

How to buffer a vector shapefile using ogr python?

I am trying to learn how to use ogr in python using the country and populated places datasets from http://www.naturalearthdata.com/downloads/50m-cultural-vectors/. I am attempting to use filters and ...
10
votes
1answer
525 views

How to connect Qgis with pycharm in Ubuntu OS

I have just started using pycharm with qgis but could not connect both of them. Pycharm always stays in a state of "waiting for connection". Most the tutorials available points to the windows but I am ...
10
votes
1answer
917 views

How to fill composer map with canvas data and export composition as png using Python script in QGIS

I'd like to create a Python script in QGIS that will take some data (shp + tif, in my example), use tamplate Map Composer (from a file) and export created composition to a png image. With almost no ...
10
votes
0answers
422 views

Accessing existing instance of QGIS from stand-alone python script

For my own data analysis pipeline, I am running a split screen setup with iPython notebooks on one side, generating variables from source data, pushing them to a CSV file which QGIS then reads/joins ...
9
votes
3answers
23k views

Using variables from one Python script in other Python scripts?

I want to set up a single python file containing variables that have the locations of all my data sources. This would then be used by all my other scripts, then as a data source changes, I only have ...
9
votes
5answers
6k views

Programmatically edit/update metadata in ArcGIS?

Has anyone succeeded in programmatically updating metadata in ArcGIS 10? Considering using Python/arcpy but ArcObjects (C# or Python/comtypes) is also a possibility. I need to update both the FGDC ...
9
votes
3answers
12k views

Obtaining the data of one selected feature in QGIS using Python?

I have a problem/question regarding python and QGIS. Is it possible to get the data of one selected feature in QGIS using python, and if so how? In my example I have a layer which shows some parcels ...
9
votes
2answers
913 views

How to reduce the size of shapefiles when features are deleted?

This tiny little script deletes all small features in all layers. This works fine but the size of .shp files are not reduced. Please tell me why... canvas = iface.mapCanvas() expr = QgsExpression("$...
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 ...
9
votes
3answers
3k views

Performing a Spatial Query in a loop in PyQGIS

What I am trying to do: loop through a point shapefile and select each point that falls into a polygon. The following code is inspired by a spatial query example I found in a book: mitte_path = r"D:\...
9
votes
2answers
4k views

Determining if shapefile and raster overlap in Python using OGR/GDAL? [closed]

I am building a script in python using OGR/GDAL. I have a set of shapefiles and a set of GeoTiff raster files. I would like to have my script ignore shapefiles if they do not intersect with the ...
9
votes
1answer
5k views

How to transform a selected multipart feature into singlepart features while editing in QGIS?

There are several questions and respective answers for how to make a multipart features Layer into a singlepart features one using QGIS: How to break a single polygon into multiple polys? How to ...
9
votes
1answer
4k views

Intersecting lines to get crossings using Python with QGIS?

I have a set of lines representing bus lines. Some of the lines are overlapping and take the same roads. I am able to extract the nodes. However I am interested in extracting only crossings like ...
9
votes
4answers
12k views

Creating square grid polygon shapefile with Python?

I have the following coordinates minx, maxx, miny ,maxy = 448262.080078, 450360.750122, 6262492.020081, 6262938.950073 I wish to create a square grid of size 1 m using python. import math minx,...
9
votes
3answers
4k views

Is it possible to set the project CRS via a Python command?

Is it possible to set the project CRS of an project in QGIS via a Python command? In my case the user should open QGIS, start my written plugin and this plugin will load spatial data which has the ...
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 ...
9
votes
6answers
2k views

How to programmatically check if the number of shapes = number of table records?

I have a handful of approximately 1000 shapefiles that are corrupted (see attached error message). The shapefiles were generated from eCognition Developer 8. There is a script tool that seems to ...