Questions tagged [python]
Python is an open source interpreted programming language used in many GIS programs.
11,117
questions
0
votes
0
answers
18
views
Issue calling a subprocess from ArcGIS Pro Toolbox [closed]
I am developing a toolbox that - at some point - has to process a large amount of data and apply a function to each row. For efficiency reasons I already use a pandas dataframe.
I am familiar with ...
0
votes
0
answers
27
views
Recreate heatmap with Python and GDAL
My goal is to recreate the below heatmap (I don't know how it was created).
The xyz values
x,y,z
5.5605,15.777,-0.7729
6.537,15.5544,-0.7125
5.5669,15.8049,-0.7571
6.6229,15.9312,-0.7611
5.4977,15....
-1
votes
2
answers
2k
views
Installation error of GeoPandas in PyCharm
How can I install GeoPandas in PyCharm?
I tried to install GDAL first and GeoPandas but nothing works I'm getting installation failed error.
The error is 'installation failed you need visual studio to ...
0
votes
0
answers
12
views
Python in ArcGIS Server using sys.path.append not finding module
I cloned the default Python environment installed with ArcGIS Server 10.9 so I could install jenkspy and use it in a script. I'm calling the script from a batch job so it can be scheduled. When I run ...
0
votes
0
answers
13
views
How to get polygons from a KML server using Google Colab and GeoPandas?
Essentially, I have a KML file that when put in Google Earth Pro works fine and update the layer every time that I make a zoom.
When inspect the KML file with Python I see:
from lxml import objectify,...
0
votes
1
answer
33
views
NetCDF file and shapefile in wildly different locations and of disproportionate sizes when projected with the same CRS on QGIS?
I am trying to map global greenhouse gas emissions data from the European Commission's Emissions Database for Global Atmospheric Research (EDGAR) and Northern Arizona University's Fossil Fuel Data ...
1
vote
1
answer
35
views
+100
Save scipy interpolations as a raster (GeoTIFF) format using Python
I am using scipy.interpolate (Python 3.9) to interpolate some data. However, after using a nearest neighbor interpolator, I need to save it as a raster (GeoTIFF) image, preserving the resolution of 0....
10
votes
2
answers
1k
views
Right-hand-rule in QGIS
It seems that there isn't a plugin to perform the right-hand-rule on a layer or selected features. Can this be done by using some Python code? Is there a function that works in the same way as ...
0
votes
1
answer
21
views
Adding color table with Python and GDAL
I am trying to embed a color table into a raster using Python and GDAL without success. I was trying to follow the example here
colors = gdal.ColorTable()
with open(color, 'r') as f:
lines = f....
1
vote
2
answers
49
views
Clip data using GeoPandas or PostGIS
I have two geodataframes - points. First gdf contains smaller number of points. I am trying to clip my second gdf (with higher number of points and therefore bigger area) to the extent of first gdf. ...
5
votes
3
answers
990
views
Using rasterio to show RGB image with nodata
This question is same as https://stackoverflow.com/questions/59132459/use-rasterio-show-rgb-image-with-nodata
I have a multiband image with nodata value (which is Landsat and been set nodata to 0). ...
0
votes
0
answers
28
views
iface as NoneType object in OSGeo4W shell
I'm trying to run a PyQGIS script in OSGeo4W shell. Previously, I imported all the necessary modules:
from qgis.core import *
from qgis.utils import *
QgsApplication.setPrefixPath("C:\\...
4
votes
1
answer
6k
views
Shapely multiline string to shapefile as single line
I am using shapely unary_union to dissolve multiple line strings to one line before exporting to a shapefile.
The output from unary_union is a multiline string (example below which you can paste into ...
19
votes
5
answers
27k
views
What is unit of Shapely length attribute?
I'm doing a very simple calculation of the length of a Polyline using shapely:
from shapely.geometry import LineString
...
xy_list = [map(float, e) for e in xy_intm]
line = LineString(xy_list)
s = '%...
0
votes
1
answer
24
views
How to get all unique raster values of intersecting vector in Python?
I have a tif-file containing categorical numerical land cover values and a gdf-file containing roads as linestrings. I'd like to create a new column to the road gdf that contains all unique ...
0
votes
2
answers
4k
views
Resample raster from one resolution to another with GDAL Python API
i have some trouble warping one raster to different resolution. My input is a one channel tiff with. I know the geo-coordinates of x_min and y_max. I also know that the pixel resolution is 5 meters. I ...
0
votes
1
answer
328
views
Calculate cell/pixel area with Rasterio in Python
The Situation
I have a tile spanning 10° north-south (n-s) and 10° east-west (e-w), e.g. from 10-20W and 10-20N. This tile contains multiple pixels, e.g. with a resolution of n-s and e-w of 100m at ...
0
votes
1
answer
20
views
Geodataframe to SHP in loop and name of the GDF
I am trying to export multiple gdf to shp and name these shp by the gdf name.
I have found this solution
here is my list:
maloobchod_list = [maloobchod2006_geom, maloobchod2011_geom, ...
3
votes
1
answer
351
views
QGIS Python Plugin - Prevent Dialog From Closing Immediately after OK Clicked
I've generated a QGIS plugin using the QGIS Plugin Builder v3.0.3. One issue I am encountering with it is - as soon as I click the "OK" button (that invokes the run method) - the dialog closes. Is ...
1
vote
1
answer
20
views
GDAL RasterizeLayer by attribute burns 0 when attribute is null
I am attempting to burn a shapefile onto a raster with an attribute. This works really well generally, but where the shapefile feature has null data for the selected attribute (itype_code in the ...
0
votes
0
answers
10
views
Masking a raster twice using a shapefiles in rasterio
I want to mask my raster using two different shapefiles using rasterio.mask.mask and providing the output of the first mask into the second mask like this:
cut_out = rasterio.mask.mask(...
0
votes
0
answers
12
views
Mosaicing for getting a specific area
I have two Sentinel-2 images that overlap for some region. We can merge both images so I have only one:
import rasterio as rio
from rasterio.merge import merge
filepath1 = "...
7
votes
1
answer
150
views
GIF freezes when QGIS plugin runs
I have a QGIS plugin and would like to put loading GIF (spinner) somewhere in the Dialog Window. The problem is when I run the spinner with the following code and call next function, the spinner ...
2
votes
1
answer
330
views
Predicting the whole image through trained classifier and visualize it as classified landuse and landcover image(LULC)
I am working on LULC classification of Sentinel-2 image(4-bands) using Machine Learning algorithms. I split the whole image into 64*64 patches and assigned class label (builtup, barren land, water and ...
0
votes
0
answers
30
views
Pandana not working with large dataset
I am trying to use "pandana" for network analysis instead of "networkx". With 400000 rows of my dataset works but with 500000 does not (numbers are not precise). I have my nodes ...
5
votes
1
answer
864
views
Merging many rasters with Python script within QGIS using GDAL?
I have many rasters that im trying to combine in order to produce contours. They are in the .bil format so I understand that i need to translate them using gdal first but none of my attempts have ...
0
votes
0
answers
21
views
Problem while decompressing the bz2 file [closed]
I am extracting the 38 .bz2 files containing MODIS data.
My code is:
inpath = '/Users/gulfcarbon2/Downloads/Modis/2002folder/2002_L1A_LAC'
outpath = '/Users/gulfcarbon2/Downloads/Modis/2002folder/...
7
votes
3
answers
2k
views
Unable to activate cloned ArcGIS Pro default Python environment due to missing packages
I am unable to activate cloned copies of the default ArcGIS Pro python environment, receiving an error message that required packages are missing.
I am using ArcGIS Pro 2.7.0.
I am trying to create a ...
0
votes
0
answers
5
views
What does the height and width properties of an AGOL WebMap object actually do?
The WebMap object has a height and a width property but what do they control? What is their purpose?
See the height property in the API Document
See the width property in the API Document.
from arcgis ...
1
vote
1
answer
417
views
Python Shapely crop / clip using 'intersection': cropped line is split at self-intersections
In using 'intersection' to crop / clip a single 'braided' line using a rectangle (actually a grown version of that rectangle using 'buffer'), the internal portion of the line gets split on self-...
1
vote
1
answer
447
views
Python GDAL: Convert JPEG to GeoTIFF, given location information
In a similar question, I read that one can create a GeoTIFF
image from a JPEG using the Python GDAL API. I created a small example here:
def translateIMG(path_in, path_out, in_format = "GTiff&...
0
votes
0
answers
30
views
Cannot read SHP polygon using Geopandas
I am trying to read ESRI SHP Polygon using geopandas:
polygon=gpd.read_file(r'Path.shp', encoding='utf-8', driver='ESRI Shapefile')
But I am getting this error:
NotImplementedError: A polygon does ...
0
votes
1
answer
21
views
Stacking Landsat images of different directories using Python
I have different folders containing Landsat 8 bands. I want to stack them into a single raster file. ArcPy can not be downloaded. Is there any other way to do that?
I have this snippet for the code
...
2
votes
1
answer
117
views
Correct image for each layer via print Layout
In the code, first I am merging the Cooling_Tower(vector layer) with each raster layer and I want the output as an image, so created a layout, add a map, gave extents and page properties, and exported ...
0
votes
1
answer
257
views
Get Census Tract given a Census Block OR Get Census Tract given Latitude/Longitude
I'm using Python and am looking to get the Census Tract of a location given either a latitude and longitude or a census block. I can get the census block given latitude/longitude from here: https://...
3
votes
1
answer
685
views
Cannot install GeoPandas on cloned arcgispro env in Anaconda
I have cloned my ArcGIS Pro env into my Anaconda 3 env. My goal was to have access to both the arcpy mod and GeoPandas mod. I tested it in a notebook to make sure arcpy is working and it is. But ...
1
vote
1
answer
587
views
Set red color to NaN values with matplotlibs with subplots
I need to plot four arrays arranged in subplots using Python and matplotlib.
I prefer grey scale colormap.
How to plot the NaN values that can be present in each array in red?
import matplotlib.pyplot ...
1
vote
1
answer
116
views
How to split large GeoJSON in small chunks
I am trying to split Microsoft building data for Pakistan. It's size is 6gb. I am trying to use geojsplit to split the large GeoJSON file into small chunks, but it giving me this erro:
File "C:\...
0
votes
0
answers
35
views
Creating MBTiles from GeoTiff raster with transparent background and all the zoom levels
I am trying to create MBTiles from GeoTIFF rasters that have a black background (RGB: 0,0,0).
In QGIS, I am able to generate MBTiles via the following steps:
Set Transparency pixel (0 0 0) to get a ...
3
votes
1
answer
376
views
Setup shadedrelief background in basemap using a cropped orthographic projection
I'm trying to plot a sector of the world in basemap using an orthographic projection and I would like to have a shadedrelief background.
If I don't use shadedrelief everything works fine:
import ...
0
votes
0
answers
11
views
Histogram with labels using earthpy
I got a few classified maps in tiff format that I'd like to generate a histogram of each one and compare the area for each classified region over a period of time. So far, I managed to plot the ...
1
vote
1
answer
52
views
WKTReadingError: Could not create geometry because of errors while reading input
I have a pandas DataFrame that I am trying to convert to geopandas. I tried a few different methods to convert and also attempted to fix the invalid geometries. Code below:
import pandas as pd
import ...
2
votes
1
answer
2k
views
AttributeError when converting DataFrame to GeoDataFrame with Polygon
I imported a shapefile in the form of a pandas.DataFrame and ran operations on it. But I can't convert the DataFrame to a GeoDataFrame. I tried with gpd.GeoDataFrame, and with wkt.loads. I think it's ...
0
votes
2
answers
168
views
Cannot use PROJ4 with gdal.Translate in Python
I'm trying to convert MCD12Q1 HDF5 product to GeoTiff. I extracted metadata from the file, and from this user guide I found the projection information as
PROJ4: '+proj=sinu +a=6371007.181 +b=6371007....
0
votes
0
answers
30
views
Python bulk downloading issue
Here is my code to download the Landsat data.
from landsatxplore.api import API
import json
username = 'username'
password = 'password'
api = API(username, password)
...
0
votes
0
answers
14
views
Distance from Point of interest to multiline [closed]
With Python and shapely, I am trying to find the closest river or lake shore from a given point.
I would like to avoid looping through every point of every line to find the closest and need a good ...
1
vote
1
answer
84
views
Create new column containing values of a xarray variable selected by point coordinates
I have a xarray and a geodataframe. I want to extract spi_1 values of xarray from point geometries of geodataframe by creating a new column spi_1 in geodataframe.
print(xr)
<xarray.DataArray '...
0
votes
1
answer
24
views
Converting Raster to Shapefile using filtered values of raster
I have multiple raster files (RGB, 255) and I want to convert those raster files to shapefiles but I want only that area as a polygon where there is data, which means I want to exclude the zero values
...
0
votes
0
answers
10
views
pymongo.errors.OperationFailure: Loop must have at least 3 different vertices
I am trying to do a geospatial query on a Mongo collection. I only have one document in my collection. Here is a brief look at the document:
_id: "-100299.874887816__204690.544534077__4004"
...
3
votes
3
answers
4k
views
How to translate (reposition) a raster in Python?
I tried to use QGIS GeoReferencer to translate a raster layer, but somehow failed. It just goes to somewhere unexpected.
Now I decide to do it myself, with python. I think some libraries like GDAL ...