dimitri-justeau / rflsgen

Neutral landscape generator that allows users to set targets on landscape indices.
https://dimitri-justeau.github.io/rflsgen/
11 stars 0 forks source link

Need help: flsgen_generate() not working #3

Closed mingatgithub closed 4 months ago

mingatgithub commented 4 months ago

Dear Dr. Dimitri,

Thank you for your excellent work on this super helpful R package. I am new to rflsgen and learnt to use it by following your use cases. In Use Case 3, I was not able to recreate a neutral landscape based on the terrain.

I got

r <- flsgen_generate(struct, terrain_file = dem_path, terrain_dependency = 0.9,
                     epsg = "EPSG:3163", connectivity=8,
                     resolution_x = 105.4308639672429422,
                     resolution_y = 105.4037645741556588,
                     x = 159615, y = 467655)

# Error in .jcall(terrain, "V", "loadFromData", terrain_data, nb_rows, nb_cols) : 
 # method loadFromData with signature ([IDD)V not found

I've tried the script on both Mac M3 and Windows 11 but got the same outcome. my environment: rflsgen 1.2.1 rJava 1.0-11 jdk-16.0.2.jdk (Mac)

Thank you so much in advance, Ming

mingatgithub commented 4 months ago

and I'm using R 4.3.1, for your information

dimitri-justeau commented 3 months ago

Hi, thank you for highlighting this bug ! It has been fixed in the new master version, I just uploaded the patch (version 1.2.2) to CRAN. I'll let you know when it is online.

mingatgithub commented 3 months ago

Hi, thank you for highlighting this bug ! It has been fixed in the new master version, I just uploaded the patch (version 1.2.2) to CRAN. I'll let you know when it is online.

Thank you so much for your prompt responses!

mingatgithub commented 3 months ago

I am sorry for bothering you again. The debugged version worked fine with Use Case 3, however, it stopped running when I substituted it with my own tif. It threw:

struct <- flsgen_extract_structure_from_raster(raster_file=path, 
                                               focal_classes=c(1),
                                               connectivity = 8)
dem_path <- "./00_rawdata/dem_20m.tif"
terrain_dem <- terra::rast(dem_path)

r <- flsgen_generate(struct, terrain_file = terrain_dem, 
                     epsg = "EPSG:32611", connectivity=8,
                     resolution_x = 20,
                     resolution_y = 20,
                     x = 344207.2, y = 5565088,
                     verbose=FALSE)

#  Error in .jcall(generator, "Z", "generate", terrain_dependency, as.integer(max_try),  : 
#  java.lang.NullPointerException

I have checked the input rasters have identical projection (EPSG:32611) and resolution. Still can't figure out the reseason. For your information, I attached the two input rasters in the following. Archive.zip

Best regards, Ming

mingatgithub commented 3 months ago

I'm following up with my solution: the extent of terrain raster should be 100% identical with the corresponding landscape raster.

Thank you all the same! Ming

dimitri-justeau commented 3 months ago

Hi, so it was a raster dimension problem ? Thank you again for pointing this out, I will add a input check to ensure that other users get a more informative error message !

mingatgithub commented 3 months ago

Hi, so it was a raster dimension problem ? Thank you again for pointing this out, I will add a input check to ensure that other users get a more informative error message !

Yes, I bet that the xmin, xmax, ymax, and ymin of terrain rasters should be totally same as the landscape raster's. I re-clipped the terrain raster and it worked. Hope it helps!

Thank you, Ming