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

Questions tagged [python-2.7]

Version 2.7 of the Python programming language

Filter by
Sorted by
Tagged with
27
votes
4answers
13k views

Making separate Python installation that can call ArcPy?

I see a lot of Q&As asking how you can create a separate Python installation (e.g. the Anaconda or Python XY distribution) that can use arcpy, while not 'breaking' the original ArcGIS python ...
18
votes
1answer
25k 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"...
5
votes
1answer
8k views

Rasterizing shapefiles with GDAL and Python?

I am trying to rasterize a shapefile, and write values from a specific column of the shapefile into the resulting GTiff. Here is what I've done so far, but that only creates a GTiff of zeros. from ...
13
votes
2answers
11k views

How to polygonize raster to shapely polygons

I am seeking an open-source python solution to convert raster to polygon (no ArcPy). I did know the GDAL function to convert raster to polygon, and here is the manual: http://pcjericks.github.io/py-...
3
votes
2answers
4k views

Getting all results from Selection made by Attribute or Location using ArcPy?

Using arcpy I'm trying to get the results of a selection, or what is currently selected as a list. Basically I'm attempting to build an addin which on click will either perform an operation where I ...
20
votes
2answers
64k views

How to read a shapefile in Python?

My question is an extension of Vertical lines in a polygon shapefile. Kindly refer to that question first. What you will see is a method of generating vertical lines with respect to the bounding box,...
7
votes
3answers
2k views

Can a folder connection in ArcMap Catalog window be added using Python?

I have created a set of general scripting tools for map automation, etc. In one of my tools a geodatabase is created in the workspace folder the script points to. Just out of curiosity, is there any ...
7
votes
1answer
2k views

Import functions in python Add-In logic script

I am running into an error. I have a set of functions which I want to import in the python Add-In script at the time of execution, but when I built Add-In with "import stats" line then tools are ...
9
votes
1answer
3k views

How to style a layer from console?

I am new to the QGIS python console. I am trying to load a raster layer from the console, set the crs and a specific style from a qml file. layerPath = os.path.join(raster_dir,raster_name) fileInfo = ...
5
votes
3answers
2k views

Getting attribute value from vector layer after mouse click in PyQGIS?

I am trying to write a piece of PyQGIS code that runs after a mouse click to collect the Map Coordinate position, and the value of a polygon vector layer within the project under the cursor position. ...
1
vote
2answers
2k views

Vertical lines in a polygon shapefile

I am working with a GIS problem using a single input of a polygon shapefile. Consider an irregular polygon. I want to draw vertical lines across the extent of the polygon at equal spacing. How I ...
1
vote
1answer
2k views

QGIS python location problem

It seems that MacPorts installs Python27 in /opt/local, but that MacPorts QGIS updates and uses the Apple Python27 in /Library. The result is that MacPorts additions to Python27 such as OpenCV don't ...
8
votes
6answers
5k views

Raster reclassify using python, gdal and numpy

I would like to reclassify a raster file from a raster with 10 classes to a raster with 8 classes using pyhton, gdal and/or numpy. The classes are represented as integers. I have tried following the ...
4
votes
2answers
2k views

PIP no longer works with QGIS 2.18.x Python (TLS version no longer supported)

We've run into a problem installing Python packages (using pip) for use with QGIS 2.18.x (error messages copied below) Our diagnosis is that: Pypi now requires TLSv1.2 support (http using TLSv1.0 ...
7
votes
1answer
5k views

How to use QGIS field calculator in python?

I would like to use QGIS Field Calculator in Python to update the existing column based on certain conditions? How can I do this?
5
votes
1answer
2k views

How to add vertex to an existing polyline programatically?

I have a Polyline and would like to add new vertex to before start point or end point or at any part of the polyline using python in qgis. How can i do that?
6
votes
1answer
5k views

How can I Setup Python to recognize QGIS

I want to use QGIS and work with Python out of the console, but I'm having troubles letting the system recognize the paths of some DLLs. Since I couldn't find a good answer on the web, I wonder if I ...
5
votes
1answer
4k views

How to efficiently determine which of thousands of polygons intersect with a linestring [duplicate]

I have a shapefile that contains several thousand Polygons/MultiPolygons and another shapefile that has a variable number of LineStrings. In the example below the blue Polygons are those that ...
4
votes
3answers
2k views

Adding group layer, renaming it from folder name, then adding layers to it from that folder, using ArcPy/Python?

I am trying to use os.walk to go through a directory tree, pull out all the .shp files in it, create a grouplayer in the mxd, rename the grouplayer the folder name, then add the layers from that ...
4
votes
1answer
2k views

SQL queries in shapefiles using python/gdal return none result

I want try use Python and GDAL to create some SQL queries in my shapefiles. I try something and it looks good, but doesn't work. I get a none result. Here is the code : from osgeo import ogr ogr_ds =...
4
votes
1answer
745 views

Setting different context menu actions for each layer type with PyQGIS

I want to set different actions(context menu) for vectors,rasters,etc . class MyMenuProvider(QgsLayerTreeViewMenuProvider): def __init__(self, view): QgsLayerTreeViewMenuProvider.__init__(self) ...
6
votes
2answers
668 views

Making ArcPy interactive?

I'm developing an interface with arcgis and python. When I have only python, I can make my script interactive using: S = float(raw_input( 'Please enter the value: ')) I can open and run my script ...
4
votes
2answers
4k views

Calculate area in square meters from degrees?

I have a polygon shapefile in geographic coordinate system, I would like to calculate area in square meters in QGIS using Python. Is there any formula or equation to do this?
4
votes
1answer
504 views

Changing legend item text with pyQGIS?

Using code I found at Go through items in a composer legend (QGIS 2.6) I can access the the layers in my legend fine. However, I have layers that are styled by category and I can't figure out how to ...
3
votes
2answers
4k views

How to count point shp inside polygon shp using Python?

This is my first time here, so I'll try to be as specific as I can. What I'm trying to do is found out which polygon contains the most points and write the result in a text file. Here is my script : ...
3
votes
2answers
922 views

Loading non-spatial data via CSV using PyQGIS for standalone script?

I am trying to load a .shp file, and a non-spatial data table .csv file. Then join the table to the shapefile. Both files have a primary key. Here is my code: countyLayer = QgsVectorLayer(...
2
votes
1answer
988 views

Connecting Python script external to Grass GIS 7 program in Windows 10?

I've tried to find resources online to link and run my Python script externally from Grass GIS 7, however, I have not been successful. I found resources here that provide instructions (e.g., https://...
2
votes
4answers
9k views

GetRasterBand() method for gdal in Python

I was going through a tutorial book called Python Geospatial Development. On the chapter on using working with geospatial data in python there is an example of a script meant to handle and analysis ...
1
vote
1answer
321 views

How do I get utm data converted into wgs84 all within Python27?

How do I get utm data converted into wgs84 all within Python27? Does anyone know how to import the QGIS Lyon 'reproject' tool I to Python27? I have a Python script that writes utm Into a text file ...
0
votes
2answers
982 views

zonal histogram fails to create output table when looping

Using python I'm having problems when trying to attempt a FOR LOOP with the ZonalHistogram function of ArcGIS 10.1. It works fine if I use it only for one image but it gives me this error while for ...
8
votes
3answers
4k views

Increasing speed of Python scripts using arcpy

Update 4/11/2014 It looks like the script was getting hung up on the Delete Features tool, so I switched to Truncate Table, as suggested in the answer below. I also removed the unused variables from ...
5
votes
1answer
1k views

how to open second window in my plugin for QGIS?

I create a Mainwindow for my plugin, but if I want to open a second window from this Mainwindow, with click on push button. How can I do? I tried the following function in my Main Class: dialog = ...
26
votes
4answers
45k views

Shapely not installing correctly

I am trying to run Shapely on a new machine, and tried both installing it from source, using the installer on its webpage, and using pip install shapely. Every reference I try to make from the library ...
8
votes
1answer
8k views

Rasterize a shapefile with Geopandas or fiona - python

I need to rasterize a really simple shapefile a bit like this http://tinyurl.com/odfbanu. Which is just a shapefile coutaining counties in the US.I have seen this previous answer : GDAL RasterizeLayer ...
7
votes
2answers
2k views

How can I create a form so the user has to be authenticated to access a project?

I have a login form in QGIS and when it is loaded, python gives me an error for, apparently, not recognizing the findchild part. This is due to the fact that the form isn't loaded before the script is ...
4
votes
3answers
3k views

How to setup a debugger for QGIS Plugin development?

As the title of the question implies, I wish to know how to set up a QGIS Python Plugin Debugger so that I can develop plugins more efficiently. Any information regarding this would be much ...
4
votes
1answer
5k views

Reclassify a raster value to -9999 and set it to the nodata value using python and or gdal

I modified a script which reclassifies a raster. It is based on the script by Roger in his blog (the second script) and it works pretty well.The problem I am facing is as follows: I would like to ...
4
votes
2answers
3k views

Permanently add a python toolbox to ArcToolbox

I've written a python toolbox for my company containing several scripts to speed up various repetitive tasks. Each time we want to use it we have to open ArcToolbox, right click and select "Add ...
8
votes
3answers
3k views

RTree spatial index does not result in faster intersection computation

I have some code that I am using to determine which Shapely Polygon/MultiPolygons intersect with a number of Shapely LineStrings. Through the answers to this question the code has gone from this: ...
5
votes
2answers
682 views

Rotating geometry to specific angle using pyqgis?

I do not know how to rotate a geometry using pyqgis. Is there any sample/example code available to show me how?
5
votes
3answers
4k views

-9999 (no data value) becomes 0 when writing array to GDAL memory file

I am trying to reproject and resample (1000m ->> 30m) a raster image (shape 238X406) using gdal.ReprojectImage() function in Python. The input file has -9999 cells as no data value. The result is an ...
4
votes
1answer
511 views

Personal shell launcher for PyQGIS

I have changed a shell launcher found at http://inasafe.linfiniti.com/html/id/developer-docs/platform_windows.html as to fit my wish: setting the system environment variables to be able to use PyQGIS ...
4
votes
3answers
3k views

No Module named qgis

I installed QGIS through OSGeo4W, and I am trying to write a standalone PyQGIS script, however, I am unable to import the qgis, qgis.core, processing ect… modules, as shown in the picture, I get the ‘...
4
votes
2answers
446 views

Comparing projections of two datasets when SRID not available

Similar to this question: How to test if two GDAL datasets are in the same projection? However, the above does not cover cases where an SRID is not available. It can often be the case that an SRID is ...
4
votes
2answers
2k views

Gdal Python Bindings and File Geodatabase API

I'm trying to get python 2.7 to work with GDAL/OGR and an ESRI file geodatabase. There have been a few similar questions asked but the answers don't fully resolve my situation. I have installed the ...
3
votes
2answers
2k views

ArcPy 10.0 iterate through shapefile1 clip shapefile2 to shapefile1's polygons

I know that this question has been answered several times before, but for some reason I can't get this script to run... So I was hoping someone could point out where I'm going wrong. I have two ...
2
votes
1answer
1k views

Calling Gdal contour from python/ipython

Hello I am trying to patch process a folder full of ASCs to contours using Gdal from python. here is my code; import os import glob PATH1 = raw_input("folder containing ASCs path please:") ...
2
votes
3answers
915 views

Buffer and union of large shapefile?

I want to create a buffer of 5km around the coastline, and save that as a separate shapefile. I have a shapefile with almost 180,000 features. It's a line shapefile, representing the coastlines of ...
2
votes
1answer
874 views

PyQGIS in standalone script, vector loading error

I am trying to use the QGIS functions in a stand alone Python script. I'm running Mountain Lion OS, 2.7 Python & the QQGISis 2.0.1 Dufour. My main problem is that I cannot get started - I cannot ...
1
vote
1answer
465 views

Is it possible to run qgis through python?

I need to build an app to analyze some raster layers in qgis. I thought it was possible to just write code in python (2.7.6) (IDLE) and let it automatically open QGIS, load some layers, do a distance ...