Closed rokoeh closed 1 year ago
Hello
So what should I update to fix this?
If I run the code as a batch through source it does not work. If I run manually line by line it works :
require(rgee)
require(mapview)
require(raster)
ee_Initialize(drive = TRUE)
shp<-ee$FeatureCollection("projects/ee-***********/assets/feat2")
sind<-shapefile("D:/temp/rgee_example/feat2.shp")
#var selectedFeature = fc.filter(ee.Filter.eq('id', 503883))
# shp_info <- shp$getInfo()
#
# features <- shp_info$features
# for(i in 1:length(features)) {
# feature_bounds <- features[[i]]$geometry
# sentinel2 <- sentinel2$filterBounds(feature_bounds)
# # do something with sentinel2
# }
# iterate over each feature in the feature collection
for(k in 1:length(sind)){
feature_bounds <- shp$select("text1", sind$text1[k])
sentinel2 <- ee$ImageCollection$Dataset$COPERNICUS_S2$
filterDate("2019-01-01","2019-01-07")$
filterBounds(feature_bounds)
# convert image collection to bands
sentBands<-sentinel2$toBands()
# clip bands to current feature
sentBands<-sentBands$clip(feature_bounds)
# get image info
info<-sentBands$getInfo()
b2Sele<-NULL
b3Sele<-NULL
b4Sele<-NULL
b5Sele<-NULL
b6Sele<-NULL
b7Sele<-NULL
b8Sele<-NULL
b8Asele<-NULL
b9Sele<-NULL
b10Sele<-NULL
b11Sele<-NULL
b11Sele<-NULL
b12Sele<-NULL
for(i in 1:length(info$bands)){
imId<-info$bands[[i]]$id
if(length(grep("_B2",imId))==1)b2Sele[length(b2Sele)+1]<-imId
if(length(grep("_B3",imId))==1)b3Sele[length(b3Sele)+1]<-imId
if(length(grep("_B4",imId))==1)b4Sele[length(b4Sele)+1]<-imId
if(length(grep("_B5",imId))==1)b5Sele[length(b5Sele)+1]<-imId
if(length(grep("_B6",imId))==1)b6Sele[length(b6Sele)+1]<-imId
if(length(grep("_B7",imId))==1)b7Sele[length(b7Sele)+1]<-imId
if(length(grep("_B8",imId))==1)b8Sele[length(b8Sele)+1]<-imId
if(length(grep("_B8A",imId))==1)b8Asele[length(b8Asele)+1]<-imId
if(length(grep("_B9",imId))==1)b9Sele[length(b9Sele)+1]<-imId
if(length(grep("_B10",imId))==1)b10Sele[length(b10Sele)+1]<-imId
if(length(grep("_B11",imId))==1)b11Sele[length(b11Sele)+1]<-imId
if(length(grep("_B12",imId))==1)b12Sele[length(b12Sele)+1]<-imId
}
sentB2 <- sentBands$select(c(b2Sele))
sentB3 <- sentBands$select(c(b3Sele))
sentB4 <- sentBands$select(c(b4Sele))
sentB5 <- sentBands$select(c(b5Sele))
sentB6 <- sentBands$select(c(b6Sele))
sentB7 <- sentBands$select(c(b7Sele))
sentB8 <- sentBands$select(c(b8Sele))
sentB8A <- sentBands$select(c(b8Asele))
sentB9 <- sentBands$select(c(b9Sele))
sentB10 <- sentBands$select(c(b10Sele))
sentB11 <- sentBands$select(c(b11Sele))
sentB12 <- sentBands$select(c(b12Sele))
# download image data for current feature
ee_raster <- ee_as_raster(
image = sentB2,
region = shp$geometry(),
dsn = paste0("D:/gee/sentinel2/date_stack/sentinel2_B2_",k,".tif"),
via = "drive"
)
ee_raster <- ee_as_raster(
image = sentB3,
region = shp$geometry(),
dsn = paste0("D:/gee/sentinel2/date_stack/sentinel2_B3_",k,".tif"),
via = "drive"
)
# repeat for other bands (B4-B12)
}
Does the error
"Error in py_get_attr_impl(x, name, silent) : OverflowError: Python int too large to convert to C long"
have anything about the band names being too long and failing to be converted or stores by some python library or package?
Sentinel-2 band names :
b2Sele [1] "20190103T133219_20190103T133222_T22KGD_B2" "20190105T132231_20190105T132228_T22KGD_B2"
rgee version: rgee 1.1.4 R version: 4.2.1 Operating System: Win 10
I'm trying to apply $select at a imageCollection object in rgee but I face the error when I source my script: Error in py_get_attr_impl(x, name, silent) : OverflowError: Python int too large to convert to C long
When I run every command individually,line by line, in console no problem happens.
shid<-shapefile("D:/temp/rgee_example/feat1.shp")
ids<-shid$text1
require(rgee) require(mapview)
ee_Initialize(drive = TRUE)
shp<-ee$FeatureCollection("users/****/feat1")
sentinel2 <- ee$ImageCollection$Dataset$COPERNICUS_S2$ filterDate("2021-08-01","2021-08-30")$ filterBounds(shp)
info<-sentinel2$getInfo()
sentBands<-sentinel2$toBands()
nshp<-shp$filter('text1 == "id1"') k=1
for(k in 1:length(ids)){
nshp<-shp$filter(paste0("'text1 == " ,'"', ids[k] ,'"', "'"))
sentBands<-sentBands$clip(nshp)
info<-sentBands$getInfo()
b2Sele<-NULL
for(i in 1:length(info$bands)){
}
sentB2 <- sentBands$select(c(b2Sele))
ee_raster <- ee_as_raster( image = sentB2, region = nshp$geometry(), dsn = paste0("D:/gee/sentinel2/date_stack/sentinel2B2",ids[k],".tif"), via = "drive" )
feat1.zip