All Questions
62 questions
0
votes
0
answers
48
views
I have muiltiple polygons in a shapefile, and want to extract each polygon from a rasterfile and save as separate files
I have 80 polygons in a shapefile, and one complete raster file, I want to extract each polygon from a raster file and save it as a different raster files.
numPolygons <- length(shapefile)
...
-1
votes
1
answer
129
views
Using land cover shp to extract another category raster for each type in R
For example,
I have a land cover shp which has 5 types( 'forest','crop','desert','grass','city' ).
And I have a classfied temperature tif whose values are 1:4, which means 'very high','high','low','...
3
votes
2
answers
408
views
Overlay raster (h5 files) with shape files to get night light data in R
I am trying to combine ".h5" nightlight data files of Hawaii with zipcode-shapefile from Hawaii, but I am getting the following error:
#Error: [crop] extents do not overlap
The R codes are ...
1
vote
1
answer
4k
views
How to produce a gridded map in R where each grid cell represents the sum of points occurring in the grid?
I want to produce a gridded map where each grid cell represents the sum of points falling within the grid using R. I have seen similar questions for R here, here, and here for Phyton. But could not ...
1
vote
0
answers
52
views
Proportional allocation method for translating vector to raster format in R [closed]
My data consists of a shapefile of polygons representing municipalities in a given country. Each polygon has a population value in the shapefile's attribute table. I would like to disaggregate these ...
1
vote
1
answer
3k
views
Transform CRS of Shapfile (sf) and Raster( raster)
I'm working with R. And to have a Rasterfile and a Shapefile. Now I want to fit their CRS/ EPSG so I can plot them together. Several approaches I've tried won't work.
Someone may help?
THE CRS/EPSG:
...
0
votes
1
answer
2k
views
Select and save as shapefile feature in R using sf
How can I select the shapefile feature there is, "D3" in "New.Code" columns using sf packages in R
Here is the attribute table of my shapefile:
1
vote
2
answers
4k
views
sf::st_read() and terra::vect() reading in different extents from the same shapefile
I am currently working with multiple shapefiles in R and working towards rasterizing them using a combination of functions from sf,terra and stars. However, I noticed while reading in a shapefile that ...
2
votes
2
answers
678
views
Clip several rasters with multipolygon and save them as separate rasters using R
I'm trying to replicate this [example][1] but I'm not getting separate raster as an output. In my example, I have a multipolygon which has 2 polygons and 2 raster. My output I want to be 4 raster ...
1
vote
1
answer
716
views
How to extract raster values from a shapefile vector mask in R
I have a raster with integer values graded from 0 to 32. I also have a shapefile of this area subdivided into three basins A, B and C.
I would like to calculate the area (or the number of pixels, then ...
1
vote
1
answer
238
views
Loop for cropping, cloud masking Sentinel 2 L2A images
I have 6 stacks Sentinel 2 images (10m resolution) that I want to crop to my AOI and cloud masking. After which I want to calculate NDVI in R. The stacks are 3 from different months of 2016 and 3 from ...
1
vote
0
answers
359
views
Calculating area of each county that has specific land cover value [closed]
I need to calculate the area of each U.S. county that is covered by a specific type of land cover.
I am using a county shapefile (polygons) and the land cover data is a raster that comes from the NLCD ...
2
votes
1
answer
1k
views
Converting a component of a shapefile into a GeoTIFF file in R
I'm trying to obtain a GeoTIFF map of the WWF biomes, using their shapefile download:
https://www.worldwildlife.org/publications/terrestrial-ecoregions-of-the-world
The purpose of this is to ...
1
vote
0
answers
458
views
Distance between two points within a polygon (or raster value) in R
I'm trying to get the shortest distance between each point in a a set of coordinates (lat/long) within a body of water. However, straight line distances don't work because the points represent the ...
0
votes
1
answer
203
views
Save multiple raster files as shapefiles
I am trying to reproject multiple raster layers and then save the resultant images as shapefiles. I seem to be getting an error this error - inherits(obj, "Spatial") is not TRUE. Below is ...
-1
votes
1
answer
565
views
How to plot shapefile in R
I am trying to plot a shapefile on top of a raster using the command readOGR. My current code is:
CEZ <- readOGR(".", "Shapefile/CEZ1")
This is followed by the error code
...
2
votes
2
answers
6k
views
R raster extract() and keep the original shapefile attributes
I use the R function extract() in order to extract the values from a raster dataset. The shapefile that I use with the extract() function has some columns/attributes -for example the unique ID and a ...
1
vote
2
answers
256
views
When trying to rasterize a SpatialLine .shp, I get a raster with points instead of lines?
EDIT:
I've solved the problem, the resolution was simply not high enough to properly show the lines in the plot. My code now looks like this and works fine:
r <- raster(ncol=1000, nrow=1000, ...
1
vote
0
answers
155
views
Assign matrix values to raster when values do not align with raster rectangle? R
I'm trying to create a raster of distance to a single line feature (a 25 m contour line derived from an elevation raster). Since I want to run this in a loop and I have a ~15 million cells, I ...
2
votes
1
answer
619
views
Crop raster list to a shapefile
I am very new to R, so please bear with my explanation. I have a raster list made up of 671 objects that I am hoping to clip to a shapefile.
At this link I explain how I uploaded the original .bin ...
4
votes
2
answers
606
views
Extract pixel values in raster stack using shp
I am using the following code to extract mean pixel values over an area represented by a polygon:
mean<-lapply(S2_stack, FUN=function (S2_stack) {data.frame(mean=extract(S2_stack, polygons2, fun=...
3
votes
0
answers
82
views
Difference in raster pixels between Windows x86 and Windows x64
I have a huge problem and I can not find a reason for it. I have two PCa, one in my house and the other in my workplace. The first one is an old notebook with Windows x86 and the other is Windows x64. ...
2
votes
2
answers
2k
views
extract() while keeping polygon ID in output
im trying to extract the mean from a satellite imagery. The point is, that when Im using this code (simplified for this example):
> semana21 <- raster("Semana21.tif")
> poly <- ...
1
vote
0
answers
183
views
Create grid with a prespecified number of cells inside a shapefile with R
I need to create a grid inside a shapefile with a fixed the number of cells n (inside the shapefile). I tried a few stuff see bellow but nothing worked so far. Any ideas?
The data shapefile can be ...
0
votes
0
answers
372
views
How to use the R function: raster::extract with polygon which partly covers raster?
I have a raster file which is only partly covered by a shapefile with polygons.
Now I want to apply raster::extract in order to get the mean value for each polygon based on the rasterfile - But some ...
2
votes
1
answer
1k
views
Remove empty polygons from shapefile in R
I have a shapefile witch contains several empty polygons. I´m extracting values from raster file based in some polygons of this shapefile. But my loop stops at every empty polygon.
Simple solution ...
4
votes
1
answer
12k
views
R raster to shapefile
I created a raster with the function rasterFromXYZ() in R using a dataframe with coordinates and the value of a variable, the result was this:
plot(raster1)
which is exactly what I need. Now I just ...
1
vote
1
answer
1k
views
Creating raster that contains gradients given contour shapefile using R?
Using R I'd like to create a raster from a set of contour shape files, where each cell in the raster contains a value for the derived gradient.
I am using OS Terrain 50 contour lines which is open ...
2
votes
1
answer
508
views
Extract areas with certain pixel values from raster
I have land cover data from GEE (https://developers.google.com/earth-engine/datasets/catalog/ESA_GLOBCOVER_L4_200901_200912_V2_3) for specific countries. I would like to extract the values from the ...
2
votes
1
answer
203
views
I want to plot point shapefile on a raster to know if they are at the right place in R
I have one raster and a shapefile of points. I want to check them if they are in the same coordinate system by plotting them together on a map (like in a classical GIS), here the R script :
# raster ...
3
votes
1
answer
9k
views
Reading shapefile in R with shapefile function?
I want to read a shapefile(polyline) into R, using rgdal and raster packages.
The code looks like:
d<-file("/Volumes/Environment_layers/original/WaterRoad/Road.shp")
o<-shapefile(d)
but I got ...
0
votes
1
answer
622
views
Rasterize shapefile according to another big raster using gdal_rasterize
I want to rasterize a shapefile into a raster according to another raster (97284, 154208, 15001971072 (nrow, ncol, ncell)).
Since the raster is very big, I am using gdal_rasterize following the ...
1
vote
1
answer
679
views
Multiple histogram from a raster image in R
I need to get multiple histograms from a tif image. I have the following data:
A big raster tif image:
tif1 <- raster("myRaster.tif")
hist(tif1, breaks= 10) # gives the entire histogram
A ...
1
vote
2
answers
2k
views
How to get feature values from multiple polygons of shapefile while using extract function on raster
I have a shapefile which contains arround 800 circular polygons with diameter of 60 meters each. Raster is 20 meter resolution so I would have multiple cell values extracted for each polygon. I am ...
2
votes
2
answers
2k
views
Merge two rasters with different resolutions caused by masking of areas
I've analyzed multiple regions separately using rasters. All those regions are neighbours. That means every pixel from one region has a neighbour from another region, like the picture below implies. ...
3
votes
0
answers
2k
views
Draw shapefile over PNG image in R
I have a satellite image as a PNG with known coordinates (bottom, left, top, right). I want to draw a shapefile on it (the limits of a county) in R.
My first thought was to convert the PNG (it's read ...
4
votes
1
answer
566
views
How to reassign small polygons to its nearest neighbor in R (similar to gdal_sieve.py function)?
I created a spatial polygon file from a classified gridded dataset using the grid2polygons function in R. I would now like to take that polygon file and merge any polygons containing less than 6 ...
1
vote
1
answer
4k
views
Finding distance between raster pixels and line features in R
I have a raster file and a SpatialLinesDataFrame in R. I need to find the distance between each pixel (at the center) and the nearest point in the line file. I believe this is the functional ...
3
votes
1
answer
371
views
How many polygons does a single polygon intersect with?
I currently possess a shapefile that consists of >5000 polygons. I would like to know, for each polygon, how many other polygons it intersects with and the names of each polygon it intersects with?
...
2
votes
1
answer
2k
views
Rescaling coordinates of rasters, shapefiles and spatial objects from meters to km in R?
All my shapefiles, rasters and Spatial objects were projected to UTM NAD83. However, I need to convert them from meters to km for calculation reason. For rasters I can easily convert the "values" by ...
3
votes
1
answer
2k
views
How to 'fill' a region in a raster layer specified by a shape with a value
I have a shapefile for a country, made up of a shape per province. I want to create a raster layer in the shape of the country and for each pixel in the area covered by province 1 set the value to ...
5
votes
1
answer
843
views
raster::rasterize set wrong values with enclosed polygons
Similarly to this post
rasterize (R package raster) fail to rasterize island polygons?
the rasterize function in the raster package is giving me problems with enclosed polygons. In my case, some ...
1
vote
1
answer
7k
views
Crop Raster from using Polygon shapefile in R
I am trying to crop a raster by a polygon in R to the state of Sergipe-Brazil. My raster is a raster brick criated by 7 .tif files which are EVI (vegetation index) time series. Since the EVI archives ...
5
votes
1
answer
1k
views
Interpolate temperature data (shapefile) using R
The answer below solved my fist question, so I edit my question as follows:
I have a shapefile given with the attributes lat, lon, elevation and temperature.
So far I have a script that interpolates ...
1
vote
0
answers
233
views
Rasterize (R package raster) fails to rasterize island polygons? [duplicate]
I am having problem in rasterizing a polygon shapefile: "island" polygons (I mean polygons which are totally included into a larger one) are ignored and do not appear in the raster. My code is:
seg &...
1
vote
1
answer
285
views
Clipping raster objects in PostGIS
I'm trying to cutting a raster object (from a PostGIS table) using a shapefile with reference, extracting raster data from a polygon area. My objective to work with the clipping raster into R.
I'm ...
2
votes
1
answer
5k
views
R: Convert Extent Object to Shapefile
I want to convert R 'library:raster' 'extent' object to a shapefile. I have the CRS available too.
e= c(4304916, 4305325, 365216, 365439)#xmin, xmax, ymin, ymax
proj4string(e) = CRS("+proj=utm +...
1
vote
1
answer
2k
views
Overlaying grids with a polygon to determine the average value of the overlapping grids for that polygon
I would like to add the average, minimum and maximum value of, let’s say soil moisture (variable "value" in my case), to each NUTS3 region (= a NUTS3 region is a polygon of a certain small area in ...
19
votes
1
answer
32k
views
Reprojecting raster from lat/lon to UTM in R?
i have to turn it into a UTM in order to make the buffer functional.
wets<-readOGR(dsn=".",layer="shapefile")
r.raster <- raster()
extent(r.raster) <- extent(wets)
res(r.raster) <- 100
...
2
votes
2
answers
11k
views
How to rasterize a vector dataset in R?
I would like to compare vector vs raster data. So i try to fix a problem using both ways.
I made it in vector first :
coastline<-readShapeSpatial("shp")
wets<-readShapeSpatial("shp")
wetb<-...