Skip to main content
better formatting
Source Link
Spacedman
  • 66.5k
  • 6
  • 83
  • 121

I have an sfc Multipolygon data.frame with roughly 7000 polygons. Now I want to extract the mean cell values for each polygon that overlaps a raster file with a resolution of 2x2m (many many cells) and only 1 band. I found this question and adapted the bottom answer to my data. Here is the approach from the other question:

r1 <- raster p1 <- polygon feature

p1$mean_val <- raster::extract(x = r1, y = p1, FUN=mean)

r1 <- raster
p1 <- polygon feature

p1$mean_val <- raster::extract(x = r1, y = p1, FUN=mean)

When I try this, I get an error message saying

"invekos_shp$mean_SOC_gkg <- raster::extract(x=SOC_raster_2x2, y=invekos_shp, FUN=mean, na.rm=TRUE) Error in [[<-.data.frame(*tmp*, i, value = list(ID = c(1, 1, 1, 1, : Substitution has 161486089 lines, Data has 7077"

invekos_shp$mean_SOC_gkg <- raster::extract(x=SOC_raster_2x2,
y=invekos_shp,FUN=mean, na.rm=TRUE) 
Error in `[[<-.data.frame`(`*tmp*`, i, value = list(ID = c(1, 1, 1, 1,
 :    Substitution has 161486089 lines, Data has 7077

Is this because my data frame is a multipolygon data frame or did I not adapt the function correctly? Can I read the shape file in a different format to be able to use this function or would I loose information by that?

I have an sfc Multipolygon data.frame with roughly 7000 polygons. Now I want to extract the mean cell values for each polygon that overlaps a raster file with a resolution of 2x2m (many many cells) and only 1 band. I found this question and adapted the bottom answer to my data. Here is the approach from the other question:

r1 <- raster p1 <- polygon feature

p1$mean_val <- raster::extract(x = r1, y = p1, FUN=mean)

When I try this, I get an error message saying

"invekos_shp$mean_SOC_gkg <- raster::extract(x=SOC_raster_2x2, y=invekos_shp, FUN=mean, na.rm=TRUE) Error in [[<-.data.frame(*tmp*, i, value = list(ID = c(1, 1, 1, 1, : Substitution has 161486089 lines, Data has 7077"

Is this because my data frame is a multipolygon data frame or did I not adapt the function correctly? Can I read the shape file in a different format to be able to use this function or would I loose information by that?

I have an sfc Multipolygon data.frame with roughly 7000 polygons. Now I want to extract the mean cell values for each polygon that overlaps a raster file with a resolution of 2x2m (many many cells) and only 1 band. I found this question and adapted the bottom answer to my data. Here is the approach from the other question:

r1 <- raster
p1 <- polygon feature

p1$mean_val <- raster::extract(x = r1, y = p1, FUN=mean)

When I try this, I get an error message saying

invekos_shp$mean_SOC_gkg <- raster::extract(x=SOC_raster_2x2,
y=invekos_shp,FUN=mean, na.rm=TRUE) 
Error in `[[<-.data.frame`(`*tmp*`, i, value = list(ID = c(1, 1, 1, 1,
 :    Substitution has 161486089 lines, Data has 7077

Is this because my data frame is a multipolygon data frame or did I not adapt the function correctly? Can I read the shape file in a different format to be able to use this function or would I loose information by that?

deleted 12 characters in body
Source Link
GforGIS
  • 3.3k
  • 4
  • 22
  • 39

I have an sfc Multipolygon data.frame with roughly 7000 polygons. Now I want to extract the mean cell values for each polygon that overlaps a raster file with a resolution of 2x2m (many many cells) and only 1 band. I found this question and adapted the bottom answer to my data. Here is the approach from the other question:

r1 <- raster
p1 <- polygon feature

p1$mean_val <- raster::extract(x = r1, y = p1, FUN=mean) 

r1 <- raster p1 <- polygon feature

p1$mean_val <- raster::extract(x = r1, y = p1, FUN=mean)

When I try this, I get an error message saying "invekos_shp$mean_SOC_gkg <- raster::extract(x=SOC_raster_2x2, y=invekos_shp, FUN=mean, na.rm=TRUE) Error in [[<-.data.frame(*tmp*, i, value = list(ID = c(1, 1, 1, 1, : Substitution has 161486089 lines, Data has 7077"

"invekos_shp$mean_SOC_gkg <- raster::extract(x=SOC_raster_2x2, y=invekos_shp, FUN=mean, na.rm=TRUE) Error in [[<-.data.frame(*tmp*, i, value = list(ID = c(1, 1, 1, 1, : Substitution has 161486089 lines, Data has 7077"

Is this because my data frame is a multipolygon data frame or did I not adapt the function correctly? Can I read the shape file in a different format to be able to use this function or would I loose information by that?

Thanks for your help :)

I have an sfc Multipolygon data.frame with roughly 7000 polygons. Now I want to extract the mean cell values for each polygon that overlaps a raster file with a resolution of 2x2m (many many cells) and only 1 band. I found this question and adapted the bottom answer to my data. Here is the approach from the other question:

r1 <- raster
p1 <- polygon feature

p1$mean_val <- raster::extract(x = r1, y = p1, FUN=mean) 

When I try this, I get an error message saying "invekos_shp$mean_SOC_gkg <- raster::extract(x=SOC_raster_2x2, y=invekos_shp, FUN=mean, na.rm=TRUE) Error in [[<-.data.frame(*tmp*, i, value = list(ID = c(1, 1, 1, 1, : Substitution has 161486089 lines, Data has 7077"

Is this because my data frame is a multipolygon data frame or did I not adapt the function correctly? Can I read the shape file in a different format to be able to use this function or would I loose information by that?

Thanks for your help :)

I have an sfc Multipolygon data.frame with roughly 7000 polygons. Now I want to extract the mean cell values for each polygon that overlaps a raster file with a resolution of 2x2m (many many cells) and only 1 band. I found this question and adapted the bottom answer to my data. Here is the approach from the other question:

r1 <- raster p1 <- polygon feature

p1$mean_val <- raster::extract(x = r1, y = p1, FUN=mean)

When I try this, I get an error message saying

"invekos_shp$mean_SOC_gkg <- raster::extract(x=SOC_raster_2x2, y=invekos_shp, FUN=mean, na.rm=TRUE) Error in [[<-.data.frame(*tmp*, i, value = list(ID = c(1, 1, 1, 1, : Substitution has 161486089 lines, Data has 7077"

Is this because my data frame is a multipolygon data frame or did I not adapt the function correctly? Can I read the shape file in a different format to be able to use this function or would I loose information by that?

added 2 characters in body
Source Link

I have an sfc Multipolygon data.frame with roughly 7000 polygons. Now I want to extract the mean cell values for each polygon that overlaps a raster file with a resolution of 2x2m (many many cells) and only 1 band. I found this question and adapted the bottom answer to my data. Here is the approach from the other question:

p1 <- polygon feature

p1$mean_val <- raster::extract(x = r1, y = p1, FUN=mean) 
r1 <- raster
p1 <- polygon feature

p1$mean_val <- raster::extract(x = r1, y = p1, FUN=mean) 

When I try this, I get an error message saying "invekos_shp$mean_SOC_gkg <- raster::extract(x=SOC_raster_2x2, y=invekos_shp, FUN=mean, na.rm=TRUE) Error in [[<-.data.frame(*tmp*, i, value = list(ID = c(1, 1, 1, 1, : Substitution has 161486089 lines, Data has 7077"

Is this because my data frame is a multipolygon data frame or did I not adapt the function correctly? Can I read the shape file in a different format to be able to use this function or would I loose information by that?

Thanks for your help :)

I have an sfc Multipolygon data.frame with roughly 7000 polygons. Now I want to extract the mean cell values for each polygon that overlaps a raster file with a resolution of 2x2m (many many cells) and only 1 band. I found this question and adapted the bottom answer to my data. Here is the approach from the other question:

p1 <- polygon feature

p1$mean_val <- raster::extract(x = r1, y = p1, FUN=mean) 

When I try this, I get an error message saying "invekos_shp$mean_SOC_gkg <- raster::extract(x=SOC_raster_2x2, y=invekos_shp, FUN=mean, na.rm=TRUE) Error in [[<-.data.frame(*tmp*, i, value = list(ID = c(1, 1, 1, 1, : Substitution has 161486089 lines, Data has 7077"

Is this because my data frame is a multipolygon data frame or did I not adapt the function correctly? Can I read the shape file in a different format to be able to use this function or would I loose information by that?

Thanks for your help :)

I have an sfc Multipolygon data.frame with roughly 7000 polygons. Now I want to extract the mean cell values for each polygon that overlaps a raster file with a resolution of 2x2m (many many cells) and only 1 band. I found this question and adapted the bottom answer to my data. Here is the approach from the other question:

r1 <- raster
p1 <- polygon feature

p1$mean_val <- raster::extract(x = r1, y = p1, FUN=mean) 

When I try this, I get an error message saying "invekos_shp$mean_SOC_gkg <- raster::extract(x=SOC_raster_2x2, y=invekos_shp, FUN=mean, na.rm=TRUE) Error in [[<-.data.frame(*tmp*, i, value = list(ID = c(1, 1, 1, 1, : Substitution has 161486089 lines, Data has 7077"

Is this because my data frame is a multipolygon data frame or did I not adapt the function correctly? Can I read the shape file in a different format to be able to use this function or would I loose information by that?

Thanks for your help :)

added 27 characters in body
Source Link
Loading
Source Link
Loading