Questions tagged [numpy]

NumPy is a Python module, adding support for large, multi-dimensional arrays and matrices, along with a large library of high-level mathematical functions to operate on these arrays.

Filter by
Sorted by
Tagged with
1 vote
2 answers
67 views

Modify cells in a raster, that intersect or are inside a polygon without modify the other cells

I have a raster of a DEM (Digital Elevation Model with values in meters above sea level) in .tiff format, and I need to subtract the value of 10 from the elevation values of cells located within a ...
El Memo de Mileto's user avatar
1 vote
0 answers
110 views

Calculating directionalDistanceTransform in Python

I would like to re-create Google Earth Engine's directionalDistanceTransform function in Python, mainly for learning and understanding purposes. There seems to be no equivalent function in Python, ...
TheBackwardsman's user avatar
0 votes
2 answers
49 views

Enlarge numpy array to fill/pad bounds in rasterio whilst keeping existing data intact

I'm looking to do what this question and answer is doing using gdal_translate / gdal_warp, but in Rasterio. Does anyone know of a way? I can't find anything in the rasterio.warp.reproject module that ...
Stev_k's user avatar
  • 6,689
1 vote
1 answer
58 views

Find coordinates corresponding to max and min values using Python

I'm using GDAL and numpy so far in my Python program. I am able to get the max and min values of a band within a .grib2 file with: def getDataStats(grib2Filepath, bandNr): local_minimum = None ...
interwebjill's user avatar
0 votes
0 answers
28 views

Vectorised distance function for non-continuous lines

I have a function that works out the distance for two countries' shared border, it works fine for any border that is continuous, but (I think) it also adds up empty space between the end of one line ...
George.M's user avatar
0 votes
0 answers
27 views

Change dtype of coordinates NetCDF

I was wondering how to change the dtype from float32 to float64 of coordinates. I can run the following code in the terminal ncap2 -s 'lat=double(lat); lon=double(lon)' infile.nc outfile.nc How ever ...
sss's user avatar
  • 1
0 votes
0 answers
92 views

Dissolve lines that intersect after attending some dataframe (atributte table) conditions

I need to dissolve all Linestrings from a geodataframe that intersects each other after attending some tabular conditions: 1)have the same ID and 2) have the same opening year. I am working with ...
Marlon's user avatar
  • 21
0 votes
2 answers
110 views

NumPy error when importing ArcPy in virtual environment with ArcGIS Desktop 10.8.2

In many projects I use a Python virtual environment with ArcPy. I always use the same method to for setup: Create a virtual environment In the site-packages directory, add a file named Desktop10.X....
isshp's user avatar
  • 418
1 vote
1 answer
66 views

Percentile values of a raster file are nan

I am trying to extract some statistics from all rasters in a directory and saving them into a CSV file using Python. The script works, but the results for all percentile values are always nan. Any ...
Isa's user avatar
  • 185
0 votes
1 answer
49 views

SetNoDataValue produce a non supported file when transform a numpy array in to GeoTIFF using GDAL

I'm currently working with GDAL and numpy in Python to stitch 2 parts of different GeoTIFF files and produce a new GeoTIFF with the result. I'm able to retrieve the files, transform it in numpy arrays ...
Eduardo's user avatar
  • 13
1 vote
2 answers
254 views

How to mask bands of an image based on values of one of the bands using numpy and gdal

I have a raster with two bands, and I want to mask both bands to get data where band "yod" has a value of 2011 and export a new tif file with the same two bands masked. The following script ...
Isa's user avatar
  • 185
3 votes
1 answer
212 views

Downloading Sentinel 2 Float32 Image as NPY array in GEE Python API

I am trying to download an Sentinel 2 image with 12 bands. The 'Precision Type' of the Image is 'Float'. When I try to download the image in Int format it is downloaded perfectly. However, when trying ...
Kazi Jahidur Rahaman's user avatar
0 votes
1 answer
232 views

Problem with NaN values in a zonal_statistic Python script

I want to create a script to extract zonal statistics from all bands of tif files in a directory using each feature contained in a shapefile. I use the nodata value of the image to avoid using those ...
Isa's user avatar
  • 185
3 votes
2 answers
362 views

Writing raster statistics in Python as fast as ArcGIS

I am trying to run a Zonal Statistics in Python. My zone raster has about 300,000 different zones, and in each zone I want to calculate several statistics (mean, median, stdev, count, etc.). I've used ...
Jacob Mardian's user avatar
0 votes
1 answer
71 views

Import folder of raster files as a numpy array

I'm attempting to run a CNN model with raster files for environmental observations and I'm trying to import a folder of tiff files as the input for the model. I'm relatively new to python and ML and ...
witheringwhispers's user avatar
2 votes
1 answer
722 views

Numpy is not setting properly nan values: arr[arr== 0] = np.nan

I am creating a script to normalize a satellite scene. My input image is of type float32, and no NoData value is assigned. However, during the normalization, I want to avoid using pixels with a value ...
Isa's user avatar
  • 185
0 votes
1 answer
470 views

Saving plot from .nc file without showing the plot

I am trying to save the sequence of plots of 24 hours of ERA5 data from .nc file without plotting them. I am using xarray for reading .nc data. Here is my code: import xarray as xr import matplotlib....
pwnkit's user avatar
  • 17
0 votes
1 answer
68 views

Merge raster data whilst keeping min value and their layer name [closed]

Using numpy and arcpy I can’t figure out a method to do the following: Merge two rasters which have identical cell alignment keeping the minimum value (e.g compare the pixel values and keep minimum) ...
spk578's user avatar
  • 1,516
2 votes
2 answers
149 views

TypeError when saving tif with rasterio using "rasterio.open"

I have image as ndarray with 20 bands with the following shape: (20, 2227, 3676) . I'm trying to save it using rasterio with the following script: savedir=pathlib.Path('myfolder/') savedir.mkdir(...
ReutKeller's user avatar
  • 2,117
1 vote
4 answers
1k views

Get a numpy array out of a GeoDataFrame of shapely Points in shapely >=2.0

I had the following code in shapely 1.8.5.post1 which was working but was throwing a warning: import os os.environ['USE_PYGEOS'] = '0' import numpy as np import geopandas as gpd from shapely.geometry ...
swiss_knight's user avatar
  • 10.2k
1 vote
1 answer
707 views

shapely | Binary mask of Polygons' intersection

Goal: Create a binary 2d-array, that represents Points of intersection of a square Polygon with a MultiPolygon. from typing import List, Tuple import numpy.typing as npt from shapely.geometry import ...
StressedBoi_69420's user avatar
0 votes
2 answers
199 views

Iterate through multiple arrays from several folders and perform calculations

Iterate through multiple arrays, each having multiple arrays I have three folders, each containing 675 NumPy arrays. I want to iterate over each array in each folder. My first folder is “Barleyarea,” ...
Endalkachew Kebede's user avatar
0 votes
1 answer
2k views

Using gdal warp to clip raster

I am trying to clip a raster data with GDAL warp. I want data values of raster within the buffer. import rasterio as rio import shapely as shp import geopandas as gp import numpy as np raster=rio....
SVpk's user avatar
  • 1
0 votes
1 answer
99 views

Reclassify Raster array using new values from a list array - shape mismatch error

I am trying to reclassify some raster values using new values stored in an array. Below is my code: import rasterio import numpy as np # path to the raster data in_img = "...\raster.tif" # ...
ShaworoIde's user avatar
1 vote
1 answer
95 views

Call shapefile from a folder and extract each x,y coordinate system

I am curious about the script that calls multiple shapefiles from a folder and extracts each x,y coordinate system. (I have completed calling the shapefile from the folder so far.) import glob import ...
gudsv's user avatar
  • 11
1 vote
2 answers
1k views

Prevent rasterio to read nodata value as nan?

When reading a raster dataset with rasterio 1.3.3, nodata values are replaced by nan. How to read the raster dataset so that nodata cells are having their true value in the resulting numpy array from ...
swiss_knight's user avatar
  • 10.2k
2 votes
1 answer
88 views

Make an Esri shapefile from a numpy array using ArcPy

I have an Esri shapefile that I have dropped duplicates from and turned into a numpy array using the following code: loc_ID_fld_names = ["LocIDNmbr", "Lat", "Long"] ...
Tara's user avatar
  • 21
0 votes
1 answer
112 views

GeoPandas in ArcGIS Pro not updating operation performed

I am new in the programming area. I have done some code making use of sources on the web. That is why I am having trouble. In my query I have used GeoPandas, Pandas and numpy library to make ...
Daniel León's user avatar
0 votes
1 answer
2k 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 ...
SpatialAnalyst's user avatar
1 vote
1 answer
67 views

Convert an array of metadata to GeoTIFF, when the array was synthesized by smaller arrays, that correspond to same size tiles of a bigger image

I wanted to process the metadata of an image from Google Earth Engine (python) and the image was huge, which means I could not download. For this reason and since I know the boundaries, I thought it ...
Newbielp's user avatar
  • 111
3 votes
2 answers
549 views

Adding CSV file by Python to QGIS throws #Line20 got ...columns instead of... error

I am struggling with the following code: import numpy as np c = np.genfromtxt('C:/path/to/file.csv', delimiter=',') # check delimiter lats = c[:,0][1:] lons = -c[0][1:] # remove minus if you get ...
Geographos's user avatar
  • 4,077
0 votes
1 answer
230 views

ArcPy TableToNumPyArray TypeError

I have a geodatabase table that I want to convert to a numpy array to create a Pandas dataframe. Using the arcpy TableToNumPyArray function on the table object fails. import arcpy, numpy # `tbls` is ...
champezius's user avatar
2 votes
1 answer
88 views

Pandas column renaming according to day of year

I have a remote-sensed time series data stored in a Pandas data frame. The original name of the columns are 2 strings res_final 001...res_final 365. I would like to rename them keeping only the DOY ...
Daniel_P_GEO's user avatar
0 votes
1 answer
73 views

Reshaping numpy array created using RasterToNumPyArray in ArcPy

I have generated a numpy array from an existing raster in ArcGIS using RasterToNumPyArray, but when it is imported the array shape is (bands,rows,columns) and I need to convert to (rows,columns,bands)....
user44796's user avatar
  • 1,905
3 votes
1 answer
2k views

Converting column with LineString geometries to np.array

I have a GeoDataFrame of a street network with the geometry of each row as a LineString. Say something like: type id tags geometry lanes bridge name highway 0 way 34953479 {'...
arkriger's user avatar
  • 327
1 vote
1 answer
692 views

Changing band datatype to uint64 using rasterio

I have a raster, input.tif. It has 4 layers, and uint8 datatype, as shown in the metadata: import rasterio with rasterio.open('input.tif') as src: print(src.meta) Output: {'driver': 'GTiff', '...
zabop's user avatar
  • 1,821
0 votes
1 answer
2k views

Python: how to filter a point cloud according to the color of the points

I have a point cloud with XYZRGB data which was derived from images. Is there any way I can filter the point cloud based on colour data? This is possible in images maybe using OpenCV or some other ...
sarada's user avatar
  • 11
1 vote
0 answers
110 views

Ideas to cluster lanes using color information

My point cloud consists of XYZ values and for each xyz there is corresponding color (RGB) value. I don't have any other information in my data eg:intensity, classification etc., as this point cloud ...
sarada's user avatar
  • 11
1 vote
2 answers
188 views

Raster to Numpy array for aspecified area, search maximum value using ArcPy and numpy

I want to filter the maximum value within a given area using the fastest method possible. I don't want to load the input files (several 100s of full size, classified Sentinel 2 images, integer) ...
GisT's user avatar
  • 91
1 vote
1 answer
2k views

Converting ee.Image to numpy array in Earth Engine Python API takes too much time [closed]

I am using Earth Engine's Python API to convert ee.Image() to Python plots. I am currently using the ee.sampleRectangle() function to convert ee.Image() to a NumPy array and then using matplotlib's ...
Shidharth Routh's user avatar
2 votes
0 answers
106 views

Error Showing With Python-"ee.ee_exception.EEException: Image.select: Pattern 'B4' did not match any bands."

I'm working on estimation chlorophyll-a using a Landsat 8 image woth python code and then I’m trying to build an web-app which is using streamlit and geemap library. But my map doesn’t showing when I ...
Martanti Aji Pangestu _'s user avatar
0 votes
1 answer
28 views

Vegetative index calculation yields Inf instead of value

I am calculating a the Green Leaf Index (GLI) from an orthomosaic and am somehow getting inf values for certain pixels instead of actual values. When calculated manually, I am getting an expected ...
nburner's user avatar
  • 61
1 vote
1 answer
1k views

Turning TIFF numpy array into a .jpeg

I am trying to convert a numpy array - containing the Red, Green, and Blue band obtained from the .TIFF file of the satellite image - into a simple .jpeg. The issue at hand is that the colours on the ....
Meki21's user avatar
  • 73
1 vote
2 answers
854 views

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

When I open a raster stack with GDAL and call it as a numpy array, lines with 'no data values' also appear. Since I do not want to include these 'no data values' (mine is 128) in the calculations I ...
volkan's user avatar
  • 153
0 votes
1 answer
60 views

How do you reclassify a single integer band raster to keep only the last digit for each cell value?

I need to reclassify a raster with values in the form xxxxx1, xxxxx2, or xxxxx3. Each digit of cells values encodes a categorical information (e.g. first digit is the land cover, second digit the ...
Dim''s user avatar
  • 313
0 votes
1 answer
730 views

How to determine the order of shapely's intersection function between two LineStrings

I want to find all the Point intersections between two shapely LineStrings. It is possible that there are multiple intersections and hence the output can be a MultiPoint. How do I know that the output ...
jlcv's user avatar
  • 345
2 votes
0 answers
412 views

Compute the distance from a point to polygon given the point and direction

I want to compute the distance from a point to a polygon given the point and direction. Currently I am using shapely and defining a "somewhat" infinite line string. This is not ideal as I ...
jlcv's user avatar
  • 345
1 vote
0 answers
261 views

Label coordinates that fall in a specific shapefile

I have a dataframe for individuals, each individual has X and Y coordinates, and I have a .shp file that has a number of polygons. individuals dataframe look like: ind_ID x_coordinates y_coordinates ...
Nora S's user avatar
  • 11
2 votes
2 answers
2k views

GDAL geographic coordinate to pixel coordinate

I've got a function that converts x,y of raster to geographic coordinates in given transformation (where gt is GetGeoTransform() from GDAL): def p(col, row, gt): # p: pixel coords to map coords c, ...
Flash Thunder's user avatar
5 votes
2 answers
2k views

Converting multiple x,y coordinates to new coordinate system using GeoPandas

I have a Python script to convert the x, y coordinates in a csv file from EPSG:29902 to EPSG:2157 based on their naming Easting and Northing import geopandas as gpd import numpy as np EPSG_ITM = 2157 ...
guest_826464501's user avatar

1
2 3 4 5
10