As of May 31, 2023, we have updated our Code of Conduct.

New answers tagged

0 votes

Python - Extract raster values at point locations

A bit late to the party, but based on the accepted answer I wrote a simple function for extracting raster values at point locations. Contrary to the accepted answer, it automatically closes the raster ...
JohanB's user avatar
  • 11
2 votes
Accepted

Converting datatype of a .png image and exporting it as float image

There should be no problem if you convert the image into some format that supports float datatype. TIFF is such a format while png is not. As a proof of concept how it goes with gdal_translate. Source ...
user30184's user avatar
  • 60.3k
0 votes

Opening Raster Stack without 'No Data Values' in GDAL with Python

The most efficient way to do this is with numpy and masked arrays: import numpy as np import rasterio as rio src = rio.open(file.tif) arr = src.read(1) masked_arr = np.where(arr==128, np.nan, arr) ...
GeoMonkey's user avatar
  • 1,337
0 votes
Accepted

Calculating minimum river width for a route within the river in PostGIS/Python

I found a solution, thanks to @robin loche's comment! I post my solution here in case others have similar questions. The solution uses ST_ApproximateMedialAxis - it is part of the postgis_sfcgal ...
ronix75's user avatar
  • 41
3 votes

Calculating minimum river width for a route within the river in PostGIS/Python

Difficult question, the holes are tricky. One idea would be to start by getting the lines of the polygon. The difficulty is that you need to separate them to be sure to don't have both sides in the ...
robin loche's user avatar
  • 2,377
0 votes

Isolating the intersecting polygon where all polygons intersect in Python with the shapely library

Here is my answer from this question. Should work the same for you. import os os.environ['USE_PYGEOS'] = '0' # this is required by shapely when using python 3.10 import geopandas file = geopandas....
Binx's user avatar
  • 1,250
0 votes

Difference in calculating areas between Apache Sedona and GeoPandas

The main distinction between Apache Sedona and GeoPandas lies in the standard format of geographical coordinates. In Sedona, the ST_Transform function follows the lat/lon order, whereas GeoPandas ...
Lucas Corbanez's user avatar
2 votes

Calculating minimum river width for a route within the river in PostGIS/Python

Edit: I just realized you want the minimum river width - this answer can't help you with that, but I leave it here in case someone needs it. Get the line length of the ST_ShortestLine between your ...
geozelot's user avatar
  • 28.1k
1 vote
Accepted

Close plot window in rasterio using command line

first, rast is the file-handle... rast.close() will only release the file and has nothing to do with the plot. plt.close() will close the most recent figure plt.close("all") will close all ...
raphael's user avatar
  • 361
0 votes

Merging of multiple Geo PDF's

Using pdftk in Linux: pdftk pdf1.pdf pdf2.pdf pdf3.pdf cat output merged123.pdf
TimG's user avatar
  • 1
0 votes

Error occurring when converting to dB during the python-based classification

Adjust your code this way: HHdB = numpy.where(HHPow>0, 10 * numpy.log10(HHPow, where=HHPow>0), 0) Option where in log10 is used to prevent such warning or ...
mins's user avatar
  • 162
2 votes
Accepted

Spatially joining only features by largest overlap with sjoin in GeoPandas

Code based on BERA`s answer worked for me: df3 = gpd.overlay(df1, df2, how='intersection') df3['area'] = df3.geometry.area df3.sort_values(by='area', inplace=True) df3.drop_duplicates(subset='ogc_fid',...
Night bird's user avatar
1 vote

How to rasterize a single feature with the feature ID with `gdal.RasterizeLayer`?

You can filter the layer to create an in memory layer with the feature you want then use it instead to burn your feature geometry to raster. See below code to grasp the idea from osgeo import ogr, ...
ThomasG77's user avatar
  • 29.8k
0 votes

Using Python (in Colab), how to convert a multiband ee.Image into an ee.ImageCollection?

You can create a list of images by mapping over the band names and selecting each band, one by one. Then you create a collection from the list of images. collection = ee.ImageCollection( PastureBr....
Daniel Wiell's user avatar
  • 12.9k
3 votes
Accepted

Concatenate two geodataframes: CRS Adjustment

Try resetting the crs's to make sure they are the same: gdf1 = gdf1.to_crs("epsg:4326") gdf2 = gdf2.to_crs("epsg:4326") then concat
BERA's user avatar
  • 63.9k
0 votes

Python and GDAL. Missing a dimension when using .ReadAsArray()

You need to treat the file as a multidimensional dataset. Below is an example derived from the multidimensional API tutorial: from osgeo import gdal path = "MOD08_M3.A2023091.061.2023135084215....
user2856's user avatar
  • 60k
4 votes
Accepted

Symmetric difference using geopandas.sjoin in GeoPandas

You can inner join the dataframes, then select the rows that are not in the join. Find the features in df that are not intersecting df2: import geopandas as gpd df = gpd.read_file(r"C:/GIS/data/...
BERA's user avatar
  • 63.9k
2 votes
Accepted

How to speed up my PDAL pipeline script?

PDAL doesn't internally split your data. Some algorithms, especially those like filters.smrf require reading ALL of the data to start processing. It is the responsibility of the user to split files up ...
Howard Butler's user avatar
1 vote

Create multiband raster from .las file using PDAL

You can't do this by writing a single file in PDAL, but you can do it in a single pipeline. You'll need to write two files out and then merge them together. The following example pipeline uses the ...
Howard Butler's user avatar
2 votes
Accepted

How to extract polygon from multipolygon that has most positive point in Shapely?

You can use .bounds and max with a lambda function: import shapely poly1 = shapely.Polygon([(20, 20), (200, 20), (200, 180), (20, 180)]) poly2 = shapely.Polygon([(40, 20), (220, 20), (220, 180), (40, ...
BERA's user avatar
  • 63.9k
0 votes

Inserting geometry into spatialite - no geometry

In case anyone is trying the same, you can use geopandas with the to_file arguments to write to spatialite. import geopandas as gpd from shapely.geometry import Point gdf = gpd.GeoDafaFrame([(0,150....
SuaveIncompetence's user avatar
0 votes

Calling my Python file from the QGIS Python console?

Python 2 builtin function "execfile" was removed in Python 3.0, now you can use: exec(open(r"C:\Program Files\QGIS 2.18\PyPack\Hello.py".encode('utf-8')).read()) On this line, we ...
Pablo Manera's user avatar
1 vote
Accepted

Spatial Interpolation of Point Layer with Count and Associated P-Value

"with influence/preference given to count values associated with a lower p-value" I don't think there's a native interpolation tool with this functionality. So you may have to do some data ...
yeet_man's user avatar
1 vote

Reproject and resample raster1 to CRS and grid of raster2, but keeping the shape of the original raster

So I finally managed to find a solution for my Problem. I used "rasterio.warp.transform_bounds" to get the new bound for my target raster. The bounds (as Polygone) are then used to mask WK ...
KevinKo's user avatar
  • 21
0 votes

How to merge overlapping raster data sets in GDAL for Python to select maximum value at each pixel

I think the error comes in this part: pixelFunctionCode.text = etree.CDATA(""" import numpy as np def find_max(in_ar, out_ar, xoff, yoff, xsize, ysize, ...
UrbanDevelopementGIS's user avatar
0 votes

g.gui.rlisetup configuration file missing

In GRASS (GUI) use the Raster -> Landscape patch analysis -> Set up sampling and analysis framework menu:
user2856's user avatar
  • 60k
2 votes

How does Geopandas calculate distance between a point and a line?

geopandas uses shapely under the hood. Distance in shapely Returns the minimum distance (float) to the other geometric object. So it is the euclidean distance from the point to the nearest point on ...
Shawn's user avatar
  • 1,557
1 vote

Making polygon for every point in set using Voronoi diagram

Create a large rectangle surrounding the polygon. Then add many points along its boundary, concat these and the points inside and Voronoi. import geopandas as gpd import shapely import numpy as np ...
BERA's user avatar
  • 63.9k
1 vote

Creating empty MRF file with gdal

OK, this was maybe a bit embarrising. But unlike tif MRF needs some data in order to be initated correctly. So the improvements that i needed was. import numpy and setting the raster data of the band. ...
Simon Johansson's user avatar
1 vote

Access the assets list through GEE API

import ee ee.Initialize() folder = ee.data.getAssetRoots() file_list = [] for file in folder: file_list.append(file['id'])
Keiko_geo's user avatar
0 votes

g.gui.rlisetup configuration file missing

I also suggest that you do this directly in GRASS GIS. Run the g.gui.rlisetup module and it creates the the config file for you (based on your choice of sampling regime). See: the manpage for details....
Micha's user avatar
  • 15.3k
0 votes

What are mystery green lines in Layout View produced during ArcObjects script execution?

Just select both green lines with the mouse, then right click and select delete. That's all.
user224319's user avatar
1 vote
Accepted

Intersect a set polygons/multi-polygons at once and get the intersected polygon

This should work for a set of polygons: import os os.environ['USE_PYGEOS'] = '0' # this is required by shapely when using python 3.10 import geopandas file = geopandas.read_file("C:/Users/user/...
Binx's user avatar
  • 1,250
0 votes

How to save json returned by gdalinfo in python variable

I come from the future and bump this topic for next generations whom the subprocess solution didn't work like for me. Solution is to use gdal.Info with gdal.InfoOptions as a parameter or to pass ...
Maryla's user avatar
  • 102
1 vote
Accepted

Unexpected crsTransform after reducing an ImageCollection: nominal scale shows 111319.49079327357

The reason the image shows a nominal scale of 111319.49079327357 (meters) is because the image has the default crs EPSG:4326 and crsTransform [1,0,0,0,1,0] which corresponds to a grid of 1-degree ...
Oliver Lopez's user avatar
1 vote

Extract values from a raster image using point locations in Python

Still a bit confused about how affine works but I manage to invert the column index of the ndarray and finally got the correct results for extracting pixel values: def fp_arr_updn(arr): # ...
M八七's user avatar
  • 345
1 vote

Rasterio can't read 4 bands from PNG color image

Rasterio finds only 1 band because the second png file is a single band image with a color palette. Test with gdalinfo shows gdalinfo downloaded.png Driver: PNG/Portable Network Graphics Files: ...
user30184's user avatar
  • 60.3k

Top 50 recent answers are included