Questions tagged [python]

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

Filter by
Sorted by
Tagged with
14
votes
2answers
16k views

Insert a Point into PostGIS using Python

What is the right way to insert a Point to a PostGIS database using Python?
14
votes
2answers
23k views

How to calculate the bounding box of a geojson object using python or javascript?

I have django app with leaflet on the frontend and I need to calculate the bbox of a geojson object so that I can pass the coordinates to map.fitBounds() I have tried some libs as well as trying the ...
14
votes
2answers
13k views

Creating polygon grid using Geopandas

I'm working with a geodataframe of points and I need to create a grid of rectangular polygons. I know how to have bounds of the geodataframe with gdf.geometry.bounds. Now using this information and ...
14
votes
1answer
12k views

Import shp to Postgis using Python and ogr

I just export a Postgis Table to shp using this tips but I'm not able to import a shp to Postgis using the same library(ogr). Any idea? Thanks a lot f.
14
votes
2answers
15k views

How to get field names in pyqgis 2.0

I am trying to change an plugin from QGIS 1.8 to 2.0. In the 1.8 version I create a table of the field names like this: layer = vlayer provider = layer.dataProvider() feat = QGSFeatrue() allAttrs = ...
14
votes
2answers
16k 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()....
14
votes
3answers
11k views

gdal_calc raster calculator syntax for logical operators and other functions

In documentation for gdal_calc it is stated Command line raster calculator with numpy syntax. Later on there are few examples where in one of them: gdal_calc.py -A input.tif --outfile=result.tif --...
14
votes
3answers
11k views

Gdal: clipping a raster with another raster

I'm writing a simple utility to crop batches of multi-band geotiff raster files to the same (smaller) area. Using gdalwarp, I can easily crop a file using a single-polygon clipping shapefile: ...
14
votes
2answers
10k 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 = ...
14
votes
2answers
10k views

How to get GDAL to create statistics for GTiff in Python

I regularly create my own GeoTIFF rasters with GDAL in Python, e.g.: from osgeo import gdal from numpy import random data = random.uniform(0, 10, (300, 200)) driver = gdal.GetDriverByName('GTiff') ds ...
14
votes
1answer
1k views

Watermarking photos using geotag and creating shapefile from coordinates?

I have geotagged photographs and I would like to place a watermark of the photos location on the front for easy reference as well as creating a shapefile from the coordinates. Does anyone know of ...
14
votes
1answer
776 views

How to use GDAL with PyPy?

I am trying to optimize my python code using pypy. While I am able to import most libraries and run succesfully, I am not able to import GDAL libraries. The same libraries when imported in Python 2.7 ...
14
votes
2answers
3k views

Python, GDAL and building raster attribute tables

I have an integer raster for which I would like to build a raster attribute table using Python and GDAL. I can create a GDAL raster attribute table in Python as follows: >>> rat = gdal....
14
votes
1answer
500 views

Python increasing the filesize of my .mxd

I have a geoprocessing script that runs the following.. arcpy.AddMessage("TEST...") Yes just one line of code. A blank .mxd starts at 391kb for me as I run my script and save the filesize increases....
14
votes
4answers
10k views

Exporting features with attachments for use outside ArcGIS?

ArcGIS 10 features the new ability to add attachments to individual features to feature classes stored in a geodatabase. One use of this would be to add multiple pictures to a specific location, fire ...
14
votes
5answers
18k views

Clustering trajectories (GPS data of (x,y) points) and mining the data

I've got 2 questions on analyzing a GPS dataset. 1) Extracting trajectories I have a huge database of recorded GPS coordinates of the form (latitude, longitude, date-time). According to date-time ...
14
votes
1answer
1k views

Creating nanoscale DEM with GDAL

A bit of a strange question perhaps, but let me give you a breif explanation of the background before my actual questions: Atomic force microscopy (AFM) is a method that, in short (and to my limited ...
14
votes
0answers
1k views

Converting raster (array) to NetworkX graph and do * search? [closed]

I want to use a slope-raster for a a_star path analysis in NetworkX. I am using Python for this project. My test raster looks like this First I read in the raster with GDAL input_raster = "slope5....
13
votes
2answers
12k views

Using Rasterio or GDAL to stack multiple bands without using subprocess commands

Does anyone have a eloquent way of stacking multiple .tif files into a multiple band stack using Rasterio and/or GDAL? I am looking for a way to avoid using a subprocess command like gdal_merge.py ...
13
votes
3answers
19k views

Selecting features using an expression with PyQGIS

How can I select features with PyQGIS using an expression? I tried to use an QgsExpression but the select method doesn't take it: exp = QgsExpression("'ogc_fid' = 482") cLayer = canvas.currentLayer()...
13
votes
6answers
10k views

How do I iterate through every cell in a continuous raster?

See this link for more details. The Problem: I want to loop through a continuous raster (one that has no attribute table), cell by cell, and get the value of the cell. I want to take those values ...
13
votes
1answer
14k views

Geopandas buffer using geodataframe while maintaining the dataframe

The objective is to create a geoDataFrame with buffered geometries AND with all the "attributes" of the original geodataframe. I am able to perform a buffer on my geoDataFrame using: gdfHybasBuffer ...
13
votes
4answers
5k views

Looking for a pythonic way to calculate the length of a WKT linestring

I was quite unsatisfied with Calculating Length of Linestrings in WGS84 in Miles. It kept me wondering if there is a more convenient, Pythonic way to calculate the length of a WKT linestring according ...
13
votes
2answers
9k views

Convert timeseries stack of GTiff raster to single NetCDF

Moving from gdal-dev mailing list: On Mon, Sep 2, 2013 at 7:09 PM, David Shean wrote: Hi list, I'm trying to package a timeseries of GTiff rasters with identical projection/extent/resolution as a ...
13
votes
3answers
7k views

How to zoom to a selected feature with pyQGIS

I want to create a function that selects a feature and zooms to it (similar in QGIS). Therefore there is following function: QgsMapLayerRegistry.instance().addMapLayer(self.vlayer) def zoomTo(self): ...
13
votes
3answers
10k views

GDAL and Python: How to get coordinates for all cells having a specific value?

I've got an Arc/Info Binary Grid---specifically, an ArcGIS flow accumulation raster---and I'd like to identify all cells having a specific value (or in a range of values). Ultimately, I'd like a ...
13
votes
2answers
20k 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. ...
13
votes
4answers
3k views

Python resource for remote sensing? [closed]

I am looking for a good resource (MOOC, book, etc..) to teach Python for remote sensing applications. I am already familiar with http://www.rsgislib.org/ - are there any other resource out there for ...
13
votes
2answers
15k views

Extract raster values within shapefile with pygeoprocessing or gdal

I would like to know how to get all the raster values within a polygon using gdal or pygeoprocessing, without reading the entire grid as an array. pygeoprocessing and gdal can do zonal statistics but ...
13
votes
1answer
8k views

Converting Twitter tweets into points?

I've been doing some research on using R to datamine twitter, but I haven't really found an answer or a decent tutorial for my question. I'm interested in pulling tweets from twitter with a certain ...
13
votes
1answer
5k 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 ...
13
votes
2answers
3k views

How to disable and enable drawing in ArcMap using Python?

The script that I'm writing repositions two data frames and sets their extents. When doing this, it redraws the entire Active View 4 times, slowing the script substantially. Pressing F9 or ...
13
votes
1answer
9k views

How to remove a vector QgsVectorLayer from QGIS python plugin

I managed to add QgsVectorLayer in QGIS through a python plugin, for example: vl = self.iface.addVectorLayer(uri.uri(), layerName, self.dbConn.getProviderName()) But how can I remove it?
13
votes
1answer
5k views

numpy array to GTiff using rasterio without source raster

I have a numpy array that represents rasterized data from a LiDAR point cloud. For example: import numpy as np import rasterio arr = np.random.randint(5, size = (100, 100)) I know information about ...
13
votes
1answer
1k views

Why the order of imports matters in a standalone PyQGIS processing script?

I've come across a weird issue while running standalone PyQGIS processing scripts. The order of imports in the script affects its normal execution. You can reproduce the problem by opening a Python ...
13
votes
1answer
3k views

Import GRASS and SAGA modules to python script

I'm new at this. I am "building" a python plugin for qgis and I want to import modules from GRASS and SAGA but I don't understand how to do it. The plugin I want to import is Kriging interpolation ...
13
votes
3answers
9k 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 ...
13
votes
1answer
4k 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 ...
13
votes
1answer
10k 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 ...
13
votes
2answers
16k 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 ...
13
votes
1answer
2k views

Is there a way to properly have GDAL raise exceptions in Python?

I am working with GDAL in Python and have wanted to get GDAL to raise exceptions so that I can do something useful with them. For instance if a file cannot be opened with gdal.Open() I would like to ...
13
votes
1answer
632 views

Obtaining the distance from the QGIS Measure Tool?

I have built a plugin for feeding a Spatialite database with an input mask. There are two fields which represent the min/max dimension of an object. In the moment I call the Measure Tool (iface....
13
votes
1answer
2k views

OGR/GDAL threading results in low core utilization

I'm trying to process some raster data using ogr/gdal and I can't seem to get full utilization of all the cores on my machine. When I only run the process on a single core, I get 100% utilization of ...
13
votes
3answers
915 views

Increase Tiles Caching Speed (TileStache)

I am serving vector tiles using TileStache, I have everything set up like I want. My data is stored in Postgres and I am using the VecTiles provider to serve GeoJSON tiles. I want to cache all my ...
13
votes
1answer
13k 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 ...
13
votes
1answer
426 views

Open QGIS project files in exclusive mode / alert if project file already in use

I have QGIS-Project-Files saved to a network drive and was wondering if it is possible to warn users that a project file is already opened by an other user to prevent concurrent editing of the same ...
13
votes
1answer
1k views

Counting features into intersections of Shapely Polygons

I have a geopandas GeoDataFrame containing hundreds of shapely Polygon and MultiPolygon geometries. The polygons overlap in lots of places. I'd like to make a new geometry that contains a count of how ...
12
votes
5answers
5k views

how can i convert a shapefile to lat and lon boundaries?

i have a shapefile of country subdivisions and i would like to extract an array of bounding lat and lon for each division.. is it possible to do?
12
votes
2answers
12k views

Reading Excel sheet in ArcPy script?

I'm writing a python code to convert X,Y points in excel to shapefile. In this process i have toread xy points from shhet1. What is the step i have to include in my process to read data from sheet1 of ...
12
votes
3answers
8k 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 ...