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

learn more… | top users | synonyms

2
votes
2answers
1k views

Moving all shapefiles (SHP) in MXD to new File Geodatabase (*. gdb) using ArcGIS Desktop?

What I need to do is to move all the shapefiles in an mxd into a newly created gdb, checking prj, and update mxd reference. I have ArcGIS 10 SP4, license ArcView. I studied a bit of Python and get ...
2
votes
2answers
995 views

r.mapcalculator and python again

I've been trying to write a script creating binary maps: a=raw_input ("enter a threshold") b=float(a) grass.run_command('r.mapcalculator', formula="**'base_map'>=b**", outfile='map'+str(a), ...
2
votes
3answers
3k views

Using QGIS with a pre-existing installation of Python 3.2 and matching GDAL

I need to have GDAL/OGR working with Python 3.2 because of another dependency. However, I also want to have QGIS for convenience. However, QGIS - FWTools in particular is built against Python 2.5, ...
2
votes
2answers
3k views

How to find nearest line to point using ArcGIS Desktop (ArcObjects/Python)?

I am new to building custom ArcObjects, and am looking for a custom python script for arcgis version 10 that will loop through a point shapefile to find the nearest line segment of a line shapefile (...
2
votes
1answer
562 views

Calculating beta-diversity w raster data [renamed]

Using ArcGIS 10, it is not possible to generate a raster attribute table for 32-bit float values. Instead, I have tried the RasterToNumPyArray method, which crashes since the file input raster is so ...
2
votes
2answers
2k views

GDAL tools for QGIS on OSX - what is the exact directory for gdal binaries?

When I try to use the gdal raster tools, eg clipper, I get the message "The process failed to start. Either the invoked program is missing, or you may have insufficient permissions to invoke the ...
2
votes
2answers
61 views

GRASS 7 environment setup for Python

I would like to use some GRASS functionality from a Python programme. With GRASS 6 this required the set up of various environment variables, as detailed in the GRASS Wiki. I am trying a similar ...
2
votes
1answer
47 views

PostGIS query to get a list of points

I have a PostGIS road network layer (all features are linestrings) which I am accessing in Python and would like to get the geometry for each feature as a list of points. Something like [(lat1,lon1),(...
2
votes
1answer
90 views

Python Geocoder w3w

I am trying to use w3w API with this python geocoder correctly. http://geocoder.readthedocs.io/index.html It works fine when I use it with google and bing maps import geocoder g=geocoder.google('...
2
votes
1answer
102 views

How can I get a map image from an ArcGIS mapserver centered on a single feature?

I have a Python program that is not using arcpy. I need to get an image from a mapservice centered on a single feature using the REST api. I can call the export method to get a map image: http://<...
2
votes
1answer
89 views

Quantile in QGIS python Plugin

QGIS is very powerful when it comes to styling Vector Data. When it comes to Raster data, ArcGIS still has some advantages including Styling based on Quantiles. See my earlier post: For this I want ...
2
votes
2answers
128 views

How to convert the CSV to point shape file using python

import csv,sys import osgeo.ogr, osgeo.osr #we will need some packages from osgeo import ogr from osgeo import * import osgeo.osr as osr def test(): boolValue = True canvas = qgis.utils.iface....
2
votes
1answer
102 views

Selecting features based on similar name

I am building a script to integrate into a model that iterates through data. I've been able to get two submodels to iterate through the original data and create large numbers of features in file ...
2
votes
2answers
63 views

How to use a raster dataset to store and retrieve “vectors” using Python?

For a rectangular area of about 10 by 10 km, I have to generate "displacement vectors" with a 1 meter resolution (i.e. a delta-x and delta-y value for every cell of 1 by 1 meter). I will end up with ...
2
votes
2answers
224 views

Convert SHP to MIF/MID

I am new to GIS and QGIS software. is there a batch convert function to convert shape files to mif/mid files? I can do this individually but is time consuming? I have seen similar functions on here ...
2
votes
1answer
89 views

geopandas error “minimums more than maximums”

I posted this question on stackoverflow here, but it seems that gis.stackexchange is the more appropriate platform. I am trying to merge two geodataframes in geopandas (want to see which polygon each ...
2
votes
1answer
674 views

Calculate area of polygons using OGR in python script

I have a shapefile of many thousands of polygons. I'm trying to append an area field to the attribute table and calculate the area of each polygon (in sq. meters) driver = ogr.GetDriverByName("ESRI ...
2
votes
1answer
338 views

Connecting QGIS, SpatiaLite and Python?

I am trying to connect with python code, QGIS and Spatialite, to do SQL query. I have read some tips and I tried with this code, but no add anything. Any Idea? uri=QgsDataSourceURI() uri....
2
votes
2answers
152 views

How to add temporary PostGIS table to canvas?

I'm working with PostGIS database. I would like to create temporary table with geometry and add it as a layer to QGIS. There is no problem with regular tables, but I can't figure out how to add ...
2
votes
2answers
252 views

Find country from GPS coordinates, offline using python

I'm aware that there are several similar questions already but I have been searching for days and not been able to solve my problem: All solutions I've found require GDAL, which I have not been able ...
2
votes
1answer
116 views

What compression algorithms or image formats are supported in the gdal_retile.py -co “COMPRESS=” argument?

Running Ubuntu 14.04 with GeoServer 2.7.2. I've got gdal-bin 1.10.1 libgdal1h 1.10.1 and python-gdal 1.10.1 installed from the default repository. I'm using gdal_retile.py to create an image pyramid ...
2
votes
1answer
125 views

Creating subfolders in ArcPy's 'in_memory'

Is there a way to create a subfolder in memory in ArcPy? For example, instead of temporarily saving a dataset under: r'in_memory/bufferOne' I would like to save it under: r'in_memory/buffers/...
2
votes
2answers
281 views

QgisInterface.addVectorLayer Error

I am Esri-trained, trying to move into QGIS using Python. Simply trying to add a vector layer in Qgis returns the below error: TypeError: QgisInterface.addVectorLayer(QString, QString, QString): ...
2
votes
1answer
424 views

Unable to add attachment to ArcGIS Online feature service using Python and REST API

I am attempting to use Python to add attachments to an ArcGIS Online hosted feature service, but I'm getting an 'Unable to add attachment to the feature.' message when I run the following code: ...
2
votes
2answers
234 views

Controlling default value of arcpy.AddField_management

I have a large collection of shapefiles that use text fields to hold numerical values. I have created new fields, and populated them with the numerical equivalent of the text field. When adding the ...
2
votes
2answers
161 views

How to add multiple python expressions in field calculator

How would I add multiple python expressions in the ArcMap Field Calculator if possible? I tried separating each expression on a new line and also separating with a semi-colon but neither worked. ...
2
votes
1answer
388 views

How to merge multiple overlapping lines using python?

I have a shape file with different line features, some of which overlap. Is there a way to easily merge all overlapping lines into one, new feature using python? I've seen some solutions for ...
2
votes
1answer
249 views

How to add multiple attributes to a newly created feature with PyQGIS

I am creating a form for updating the attribute values of the newly created feature. But when i am updating the values only one attribute field is getting updated. So if i want to update the multiple ...
2
votes
1answer
395 views

ArcGIS Python syntax error using nested if else

I am trying to use the field calculator in ArcMap 10.2 to fill an empty field based on the contents of two exiting fields usint this python script in the Pre-Logic Script Code. def myfunc(legend,...
2
votes
1answer
183 views

Difference between osgeo gdal/ogr python module and GDAL C++ library

I am developing application in python and I use the osgeo gdal/ogr python bindings for gdal, but its not clear to me what exactly is the difference between the gdal/ogr in python and the gdal library ...
2
votes
2answers
661 views

How to load a data table as a 'vector layer' using PyQGIS?

This might be a simple problem, but how does one load a simple two column CSV with no associated geometric data? I have given a couple go's via QgsVectorlayer[delimited text, spatialite] types - but ...
2
votes
2answers
366 views

MultiLine field-name label referencing

A labeling routing (which is updated often) is being implemented via pyqgis and a QComboBox. The attached code below worked great, that is until needs for narrowed column headers spawned the use of ...
2
votes
2answers
558 views

Find the first occurrence of any letter in an alphanumeric string [closed]

Working in arcgis desktop 10.2, I use python scripts to split some strings, found in an attribute table. Most of them were quite easy to split, but here is one that i could't manage to break. ...
2
votes
2answers
545 views

How to add 2 layers in qgis and display them at the same time

I added 2 layers in qgis using python but only one layer is shown on canvas. After clicking (anywhere on the canvas) both layers are displayed. layer = QgsVectorLayer("Point?field=gid:integer","...
2
votes
2answers
626 views

QComboBox nested within a Qmenu?

Is it possible to nest a QComboBox inside of a Qmenu within QGIS? Below is my current code and an associated screenshot with the unexpected results. (orange = current incorrect placement, green = ...
2
votes
2answers
547 views

In ESRI ArcGIS, is there an equivalent to the RStudio Console Windows?

UPDATED I know ESRI provides scripting capacity, via the Python window, but I've had a hard time with it. Making the jump from the Field calculator to the Python window was too much to me. Trying to ...
2
votes
1answer
884 views

How to set the spatial reference to a OGR layer using the Python API?

I create new a Ogr Layer with the Datasource.GetLayer() method: driver = ogr.Open(input_file).GetDriver() datasource = driver.Open(input_file, 0) input_layer = datasource.GetLayer() If the input ...
2
votes
1answer
194 views

ArcMap Python Question: Trying to Field Calculate Slope Percent in to Text

I have a layer of polygons that I spatially joined to a raster to point layer of slope percents. My polygons now have the percent of slope in a field called Avg_point. I want to use the field ...
2
votes
1answer
215 views

QGIS crash when I try print geometry

I do (it works): from osgeo import ogr inputds = ogr.Open(r'c:\temp.shp') inputlyr = inputds.GetLayer() for i,feature in enumerate(inputlyr): print i, feature.GetGeometryRef() Output: 0 ...
2
votes
1answer
348 views

How to query values from a list in Python?

I have a list like this... list = ['1','2','3','4'] how can I use arcpy.Select_analysis to select features that have the attributes in the list. qry = '"SECDIVNO" IN ' + str(tuple(list)) ...
2
votes
4answers
977 views

Summarising all fields in attribute table using ArcPy? [closed]

I was hoping to run a script that will iterate through all fields in an attribute table, SUM each field and produce the result in a table. The script below will essentially do what I want with one ...
2
votes
1answer
856 views

Installing libspatialindex on Windows 8

I need to use Rtrees to make some code I'm running faster. However, in order to use Rtree, I need to install libspatialindex. When I've installed packages in the past I've been able to either download ...
2
votes
1answer
952 views

ArcGIS 10.0, Field Calculator Nested “if” statement with strings

I need to assign a value depending on other two columns "FNP" and "Teilort". I wrote this script in phyton for field calculator. It actually works (no error messages) but the results in every cell is ...
2
votes
1answer
264 views

How to delete features/records in ArcGIS Server using Python

How can I use python to delete records from a table, or features from a featureclass, when they are stored in ArcGIS Server? using REST "delete features" in arcgis api for javascript shows ...
2
votes
2answers
129 views

Rename las files with Python [closed]

I have a bunch of LAS files that have been delivered with different naming conventions. I want to rename the files to all have the same uniform naming - based on the easting and northing coordinates ...
2
votes
1answer
293 views

Why is feature.geometry() None in my user-defined expression function?

I'm trying the user-defined expression functions for QGIS, as listed on Nathans blog: http://nathanw.net/2012/11/10/user-defined-expression-functions-for-qgis/ I always get the feature.geometry() as ...
2
votes
2answers
85 views

Performing a Python scripted tool based on whether a field is populated or not

My question is if I'm running the ArcMap Dissolve tool through a Python script, how can I tell it to check for attributes in one field, and if that field is empty, to perform the tool on another field....
2
votes
1answer
158 views

arcpy.AsShape function returning RecordSet not Geometry

I have the following code: feature_geometry = arcpy.AsShape(json_string, esri_json=True) print feature_geometry print type(feature_geometry) >>><geoprocessing record set object object at ...
2
votes
1answer
147 views

Naming directories in python?

Why is it that when I label my directories this way: arcpy.env.overwriteOutput = True arcpy.env.workspace = "C:\\Users\\Documents\\ArcGIS\\Testing" arcpy.env.scratchWorkspace = "C:\\Users\Documents\\...
2
votes
1answer
241 views

Adding a graphic line element to open mxd using python comtypes to access ArcObjects

I attended a pretty awesome demonstration from Jeffrey Barrette at the Esri UC a few weeks ago on creating dynamic tables in ArcMap. This functionality will greatly benefit the aviation department at ...