Skip to main content

New answers tagged

0 votes

How does one resample a 20m resolution satellite image to 10m resolution, such that it matches a native 10m resolution image?

Take a look at the up and downsampling example. I'm resampling a 20 m image to 10 m: import rasterio from rasterio.enums import Resampling file_10m = r"/home/bera/Drives/data1/gisdata/Sentinel2/...
BERA's user avatar
  • 73.8k
0 votes

Remove OGR_STYLE field while/after writing

It is possible to drop OGR_STYLES as an attribute by using the GDAL ExecuteSQL() method https://gdal.org/doxygen/classGDALDataset.html#a5b65948b1e15fa63e96c0640eb6c5d7c but I do not know if it is ...
user30184's user avatar
  • 66.3k
0 votes

GDAL (Python) open/load raster with offsets

I see that this has many views, and I've faced this problem a few times (and usually forget the solution afterwards). The actual solution is in the comments above, but is written with incorrect ...
AlecZ's user avatar
  • 2,633
0 votes

Import GDAL Error

I had the same problem in installing GDAL package on Conda. Finally this strange solution worked. I installed a fresh anaconda. I created a new environment on the default python. Finally, I installed ...
milad's user avatar
  • 719
3 votes

Export Feature as GPX from Virtual Layer Using Right-Click in QGIS

This turned out to be much more than a barebones answer. It includes a few things that aren't strictly necessary, but make the tool much easier to use. Such as, highlighting the clicked feature, a ...
Matt's user avatar
  • 17.3k
3 votes
Accepted

Integrating an External Python Script into a QGIS Project Macro

You can run external .py script with a command like this: exec(open('filename.py').read()) But I'm not sure if this is a good practice, since the location of the file may change. In addition, it ...
Comrade Che's user avatar
  • 7,206
0 votes

Problem downloading images via landsatxplore.api

In https://github.com/orgs/community/discussions/58961#discussioncomment-6267642 says that the Landsat Explorer is NOT support downloading data after 2023... so, you can download data only between 01/...
CruelBrutalMan's user avatar
0 votes

How to upsert LineString in ArcGIS python via CSV (or other suggestion?)

I was able to get GeoJSON to work without using a driver by using gdf.to_json() def upsert_records_via_geojson(logger, gis, layer_id, gdf): if gdf.empty: logger.info("No lines data to ...
Eric Davis's user avatar
0 votes

How to extract geometries with M-values from a feature layer in Python?

I was following this thread for a while and modified Felipe's code to fit my use case with GeoPandas and Shapely. WARNING this code works with my work at the moment, but I have not conducted any ...
wannabeengineer15's user avatar
1 vote

gdal.Translate producing error

Following directions from user2856 and Michael Stimson, I found out that the data directory in use had no write permission for the running user, thus producing the error. Calling gdal.UseExceptions() ...
Ubron Cinzento's user avatar
2 votes
Accepted

How could I set 8CONNECTED into gdal.Polygonize()

That function is not well documented. But looking at the C docs and the tests, I can see that it's a list of options and values as strings, i.e. ["option_name=value", "another_option=...
user2856's user avatar
  • 66.5k
1 vote

Pixel-based regression using xarray has incorrect P-value, but everything else is correct

There is a more recent implementation of the lag_linregress_3D function in this Stack Overflow answer here - it has recently been updated to include calculating p-values for different alternative ...
Robbi Bishop-Taylor's user avatar
4 votes
Accepted

Install GDAL into conda environment

When using conda it is in general a good idea to avoid mixing packages from different channels. Anaconda and miniconda use defaults as default channel, so when you use conda install -c conda-forge ...
Pieter's user avatar
  • 2,749
4 votes

Converting image data type from uint16 to uint8 using Python

Your data corruption is caused by integer overflow. Once a numpy integer goes outside the range of a datatype (0-255 for uint8), the value overflows and wraps around to 0 again. For example: np....
user2856's user avatar
  • 66.5k
0 votes

Adding CRS to shapefile in GeoPandas

I had the same problem you can solve it by creating a shp1.prj file defining the CRS of geographic coordinate WGS84 as follow: GEOGCS["GCS_WGS_1984",DATUM["D_WGS_1984",SPHEROID[&...
Mohamad Awad's user avatar
5 votes

Reasons of slow intersection of two GeoDataFrames using Python

1. Why is it so much slower The spatial index works as follows: it ~stores the bboxes of the geometries of a layer in an efficient tree structure so it can be very quickly determined if a given bbox ...
Pieter's user avatar
  • 2,749
3 votes
Accepted

Converting GeoPandas points to polygons and retaining column information

You need to turn your res GeoSeries object into a GeoDataFrame and convert the series index back to a column. In one line res = gpd.GeoDataFrame(gdf.dissolve("GroupName").convex_hull)....
user2856's user avatar
  • 66.5k
0 votes

Merging LineString with MultiLineString with Python

An approach that works for me, based on the answer of @hornbydd, is: merged = MultiLineString([linestring for linestring in multilinestring.geoms] + [candidate]) …where candidate is a LineString. But,...
Ideogram's user avatar
  • 101
0 votes
Accepted

Cumulative count cut min/max values in Python different from min/max values in QGIS

I have found the answer and it was quite easy.Considering that the min value was always 0, I tried to see if by ignoring the 0 values, the min_val would change. And it did! They are not exactly the ...
rrwork___'s user avatar
2 votes

Transforming ortho (.tiff) file from one epsg to other epsg

Re-projected image is typically rotated and somehow stretched exactly because the coordinate systems are different. Is is a common misbelief that the origin that gdalinfo reports for the original ...
user30184's user avatar
  • 66.3k
3 votes

Fastest way to clip millions of small polygons and storing results as JSON

I have similar workflows, and I recently did some testing to compare the performance of different python solutions to calculate "zonal statistics". Using exactextract or pyQGIS gives me the ...
Pieter's user avatar
  • 2,749
1 vote

Calling options/arguments of gdal_translate in Python

""" Create a TranslateOptions() object that can be passed to gdal.Translate() Keyword arguments are : options --- can be be an array of strings, a string or let empty and ...
Kiruahxh's user avatar
  • 111
0 votes

Find a geo coordinate lies on street or road with OSM map

You can use Overpass-API with a query like this: [out:json]; way[highway](around:15,47.54008,4.44047); (._;>;); out; This one looks around highways nearly 15 meters from the coordinates 47.54008,4....
divulgacheur's user avatar
0 votes

Averaging two rasters preserving the non-overlapping areas with python gdal

I solved with this import subprocess f1 = "/media/giacomo/VERDE/Brix/temp_GRD_afrisar_dlr_CH1-0_BIOMASS_ANN_BRIX2.tiff" f2 = "/media/giacomo/VERDE/Brix/temp_GRD_afrisar_dlr_CH2-...
ilFonta's user avatar
  • 1,057
0 votes

Averaging two rasters preserving the non-overlapping areas with python gdal

If they are not too big to fit in RAM/memory*, you could use rasterio.merge.merge with sum and count operators and calculate mean from sum/count. Example I have three partially overlapping test ...
user2856's user avatar
  • 66.5k
0 votes

Error in dissolving shapefile with ogr2ogr

These things needs to be changed to the first command in your question: At least on windows, you need to put double quotes around the SQL query, otherwise gdal doesn't interprete it as one parameter ...
Pieter's user avatar
  • 2,749
0 votes

Algorithm for point to polygon distance calculations in shapely

The broader goal for this question was clarified in a comment on my previous answer. This answer offers a possible solution for this broader goal. Probably it would be better/clearer if this would be ...
Pieter's user avatar
  • 2,749
1 vote
Accepted

Algorithm for point to polygon distance calculations in shapely

The second option you mentioned is the case, so not only points are taken in account, also any position on any line segment. For illustration: both the distance of the green point and the red point to ...
Pieter's user avatar
  • 2,749
0 votes

Create geospatial PDF in Python

You can find GDAL Python examples from https://github.com/OSGeo/gdal/blob/master/autotest/gdrivers/pdf.py. See how SetProjection and SetGeoTransform are used. For example around line #741 ds = gdal....
user30184's user avatar
  • 66.3k
3 votes

What Python libraries are installed with ArcGIS Desktop 10.x

I don't believe there is a documented comprehensive list, because simply, the Python requirements for ArcMap 10.8 were: Python 2.7.16 NumPy 1.9.3 matplotlib 1.5.2** (might only be a server ...
KHibma's user avatar
  • 16.8k
4 votes

What Python libraries are installed with ArcGIS Desktop 10.x

Open IDLE either by typing idle at the Windows start menu or by clicking here: "C:\Python27\ArcGIS10.8\Lib\idlelib\idle.py" or open a Python window in ArcGIS 10.x Then enter >>>...
GBG's user avatar
  • 9,930
0 votes

Show marker moving live along an ipyleaflet map?

This happens because the display is within the for loop. Removing it outside the loop solves the issue.
tash Njenga's user avatar
1 vote
Accepted

Writing COPC is not supported - Laspy

I made a test with this COPC file https://media.githubusercontent.com/media/PDAL/data/master/autzen/autzen-classified.copc.laz?download=true by using a modified COPC example code from the laspy ...
user30184's user avatar
  • 66.3k
0 votes

How to set default_lon, default_lat for admin page using GISModelAdmin

This works fine for me in Django 4.2: gis_widget_kwargs = {'attrs': { 'default_lon': 70, 'default_lat': 30, 'default_zoom': 5} }
usama rehan's user avatar
2 votes

Identify outer wall of the floorplan or building

You can handle that directly in PostGIS, where you store those. The outer wall of a shape is ST_ExteriorRing(). As pointed out by geozelot, you can combine the rooms into one big shape with ST_Union() ...
Zegarek's user avatar
  • 572
0 votes

Identify outer wall of the floorplan or building

In python, using shapely, the union_all function will do the trick. Sample code: from matplotlib import pyplot as plt from shapely import box import shapely import shapely.plotting as plot room1 = ...
Pieter's user avatar
  • 2,749
0 votes

Extending raster after rasterizing geodataframe using geocube

Yes, the geom argument for make_geocube does what you're looking for. All you need to do is pass a Shapely geometry with the global extent: from geocube.api.core import make_geocube from shapely....
Aaron Zuspan's user avatar
0 votes

QGIS / SCP plugin / Aster function / hdf file / Error 37 Unable to calculate. Metadata error

solved by granting administrator rights to the file and uploading it from local disk only
user242590's user avatar
0 votes

gdalwarp on large rasters in S3

You didn't say what format your input file is, but here are a couple of things which might help: if it's a GeoTIFF, you should use the tiled mode (i.e. gdal_translate -co TILED=YES) or COG, which ...
GrayShade's user avatar
1 vote
Accepted

How to convert Sentinel-2 RGB bands to [0, 255]

Hello and thank you @JeffreyEvans. I was using an old method to get TOA reflectance images, but thanks to the page you sent me, I realised that what I was really looking for was surface reflectance. ...
Guzmán R's user avatar
0 votes

Splitting MultiLine or LineString into equal segments of particular length using GeoPandas and shapely

Building on @ljaniec's comment using Shapely >= 2.0.1 and shapely.segmentize. My environment information Python 3.11.8 | packaged by conda-forge | (main, Feb 16 2024, 20:40:50) [MSC v.1937 64 ...
Cooper Goodman's user avatar
1 vote

Calculating the least-squares fit of two Sentinel 2 rasters in python

So based on this github jupyter notebook I found an answer. #https://github.com/aws/amazon-sagemaker-examples/blob/main/sagemaker-geospatial/methane-emission-monitoring/...
Zelcon01's user avatar
0 votes

Shapely polygons crossing the antimeridian

For polygons that falls on the edge, vis around 180 degree longitude, I came with a solution that covers all those cases: from shapely.geometry import Polygon, MultiPolygon, LineString from ...
Anupam Das's user avatar
0 votes

Python GDAL: Convert JPEG to GeoTIFF, given location information

GDAL supports having a world file alongside the image, which is very easy to create. Sample code: from pathlib import Path image_path = Path("c:/temp/image.jpg") bbox = (0, 0, 100, 100) ...
Pieter's user avatar
  • 2,749
1 vote
Accepted

Does MODIS dataset (MOD09GQ) require atmospheric correction to calculate NDVI?

No, you are misunderstanding the QA bits. You don't need to correct anything, all data that was of good enough quality to be corrected, has been corrected. Any data that wasn't corrected you should ...
user2856's user avatar
  • 66.5k
0 votes

How can I alter the result of libpysal.weights.W to remove connections based on shared edge length?

I've figured it out at least if you go along the networkx route I've described in my question. To convert a sparse matrix to a libpysal.weights.W object you need to do the following: from libpysal....
Phil's user avatar
  • 161

Top 50 recent answers are included