SSA-Statistical-Team-Projects / GeoLink

GeoLink package
1 stars 1 forks source link

geolink_buildings() #51

Closed dasalm20 closed 1 month ago

dasalm20 commented 2 months ago

Hi Diana,

When I ran this : test_dt <- geolink_buildings(version = "v1.1", iso_code = "NGA", shp_dt = shp_dt[shp_dt$ADM1_PCODE == "NG001",])

I got the following error, could you please rerun the code and check the output?

Error in UseMethod("st_as_sf") : no applicable method for 'st_as_sf' applied to an object of class "NULL" In addition: Warning messages: 1: attribute variables are assumed to be spatially constant throughout all geometries 2: In st_collection_extract.sf(add_dt) : x contains no geometries of specified type

DianaJaganjac commented 2 months ago

Hi Daylan, I just ran this and it works, could you try again?

Best wishes, Diana

dasalm20 commented 1 month ago

Dear @DianaJaganjac ,

I tried running the code the past days and I get the same error. Did you move your code to the R folder?

image
dasalm20 commented 1 month ago

Dear @DianaJaganjac ,

The function seems to work only for a shapefile. One thing to note is that in your function, you are reading the tiff with terra and then reading them again with raster. We need to fix that. In the testings, using raster is fine because it is a small area, but when trying to a whole country the terra package is way faster. That is when we see a big difference.

@ifeanyi588,

The function for buildings is breaking when using a survey. In line 237 of the zonalstats_plugin.R in the postdownload_processor(), there is an else if statement:

else if (!missing(shp_dt)){ shp_dt <- zonalstats_prepshp(shp_dt = shp_dt, grid_size = grid_size) }

When passing a survey, the shp_dt is NULL, and for some reason it is still running:

shp_dt <- zonalstats_prepshp(shp_dt = shp_dt, grid_size = grid_size)

Rather than computing the zonal prep to the survey.

I did not go ahead a made any changes because I was not a 100% sure, and I did not want to mess any of your code.

This is the code that reproduces the error with the survey:

test_dt <- geolink_buildings(version = "v1.1", iso_code = "NGA", survey_dt = st_as_sf(hhgeo_dt[1:50], crs = 4326))

Best regards, Daylan

ifeanyi588 commented 1 month ago

@dasalm20 Do you get that error in other functions when extracting into a survey? If not, the building function itself will need to be fixed.

dasalm20 commented 1 month ago

Dear @ifeanyi588,

I think the issue is with the building function. Let me explain, see image below ( from the chirps function).

Screenshot 2024-09-22 at 12 00 11

When passing a survey:

Could you run the following on debug mode to make sure I am not the only one getting this error?

test_dt <- geolink_buildings(version = "v1.1", iso_code = "NGA", survey_dt = st_as_sf(hhgeo_dt[1:50], crs = 4326))

Let me know if you have any questions.

Best, Daylan