Questions tagged [python-2.7]
Version 2.7 of the Python programming language
99
questions
28
votes
4
answers
16k
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 ...
33
votes
4
answers
48k
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-...
23
votes
1
answer
47k
views
Getting coordinate system name from SpatialReference using GDAL/Python
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"...
70
votes
2
answers
227k
views
Reading shapefile in Python [closed]
My question is an extension of Vertical lines in a polygon shapefile.
There you will see a method of generating vertical lines with respect to the bounding box, at user-defined spacing. I understand ...
9
votes
3
answers
20k
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 ...
17
votes
1
answer
23k
views
how to take cell size from raster using python or GDAL or RASTERIO
How to take cell size per X,Y using simple python or GDAL or RASTERIO?
and hot to count how many pixels have my raster with some packages..
I have find some code but is pyqgis and I don't need this ...
11
votes
11
answers
15k
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 Python, GDAL and/or numpy. The classes are represented as integers. I have tried following the ...
10
votes
1
answer
4k
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
1
answer
3k
views
Unable to install plugins in QGIS 3.10 for Mac. No python support detected
I'm aware this question has already been asked numerous times in various forms, but I'm not finding any solutions that work for me. "No python support detected" in QGIS.
Issue:
Tried:
1. Updating ...
4
votes
2
answers
5k
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 ...
2
votes
1
answer
2k
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://...
7
votes
1
answer
3k
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 ...
7
votes
3
answers
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 ...
1
vote
1
answer
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 ...
0
votes
2
answers
4k
views
Vertical lines in a polygon shapefile [closed]
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 ...
22
votes
3
answers
33k
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 containing counties in the US. I have seen this previous answer: GDAL RasterizeLayer ...
7
votes
1
answer
4k
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 =...
6
votes
2
answers
1k
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 ...
6
votes
3
answers
7k
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 ‘...
5
votes
1
answer
5k
views
Setting up 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
2
answers
8k
views
Finding the pixel coordinates using GDAL/numpy
Is there a way to get the XY cordinates of a pixel based on the array index using numpy/gdal?
I have a new set of extents for a raster and, based on these newer extents, want to determine the ...
5
votes
1
answer
8k
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 ...
5
votes
3
answers
4k
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.
...
4
votes
2
answers
3k
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 ...
4
votes
1
answer
2k
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 ...
4
votes
4
answers
3k
views
Downloading Sentinel-2 data from Google Cloud Storage with Python?
I'm trying to download Sentinel-2 data from the Google Cloud Storage and basically adapted the FeLS-module (great work, by the way!). As it is done in the module, I also download the index.csv first (...
4
votes
2
answers
7k
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
3
answers
3k
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 ...
3
votes
2
answers
3k
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(...
3
votes
2
answers
5k
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
1
answer
3k
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
1
answer
1k
views
gdal.VectorTranslate returns empty object [duplicate]
Having the following GeoJSON:
{"geometry": {"coordinates": [[[0.0, -89.9999999999], [0.0, -87.5], [120.0, -87.5], [120.0, -89.9999999999], [0.0, -89.9999999999]]], "type": "Polygon"}, "properties": {"...
2
votes
4
answers
19k
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
1
answer
462
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 ...
1
vote
1
answer
760
views
Running 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 ...
0
votes
2
answers
1k
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 ...
32
votes
4
answers
74k
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 ...
24
votes
7
answers
23k
views
Import error: no module named _gdal_array
I am using python 2.7 and have gdal installed. I want to read an entire .jpg image at once and so I used statement
import gdal
from gdalconst import *
driver = gdal.GetDriverByName('JPEG')
driver....
9
votes
3
answers
6k
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:
...
8
votes
2
answers
4k
views
Defining PyCharm to understand PyQGIS and GDAL
I use PyQGIS in standalone apps and I have defined paths in Windows and Python paths to take Python API from outside QGIS.
I have created some simple tools using PyQGIS and GDAL in standalone script ...
8
votes
3
answers
6k
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 ...
7
votes
3
answers
6k
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 ...
7
votes
2
answers
3k
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 ...
7
votes
1
answer
2k
views
Python - Correct way of closing ogr.DataSource() objects
I learned that I need to close objects that I open, usually using a with open(): statement that does the closing for you after leaving it. With GDAL/OGR, this does not work and objects must be closed ...
6
votes
1
answer
3k
views
Saving python Rtree spatial index to file?
I would like to save an Rtree spatial index to file. I tried using pickle.dump, but when I loaded the .p file using pickle.load, the bounds were way off. Here's an example:
import rtree, pickle
from ...
6
votes
2
answers
1k
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?
6
votes
2
answers
6k
views
Reading/writing utf-8 encoded data using Fiona?
So I have a 'cpg' file with my 'in_file' shapefile data (definitely
set to 'utf-8'). I was using 'meta' to create the same schema/crs as
'in_file'...though it runs, my text fields are borked on ...
6
votes
1
answer
2k
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 = ...
5
votes
4
answers
5k
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 ...
5
votes
1
answer
10k
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 ...