orbisgis / geoclimate

Geospatial processing toolbox for environmental and climate studies
GNU Lesser General Public License v3.0
59 stars 15 forks source link

problem when asking for ["Senlis, Oise, Hauts-de-France, France métropolitaine, 60300, France"] #925

Closed balglave closed 3 months ago

balglave commented 7 months ago

Hi, I want to run the following groovy code with line

groovy geoclimate_with_urban_sprawl.groovy ["Senlis, Oise, Hauts-de-France, France métropolitaine, 60300, France"]

But I get a totally different area. Could you tell me how to solve the problem.

Groovy code

@GrabResolver(name='orbisgis', root='https://oss.sonatype.org/content/repositories/snapshots/') @Grab(group='org.orbisgis.geoclimate', module='geoclimate', version='0.0.2-SNAPSHOT')

/**

import org.orbisgis.geoclimate.osm.OSM import org.orbisgis.data.H2GIS

String location = args[0]

//Directory to store all the results String outputDirectory ="/home/balglave/Desktop/Research/geoclimate/res/"

if(!outputDirectory){ println "The output directory to store the result cannot be null or empty" }

File dirFile = new File(outputDirectory) if(!dirFile.exists()){ println "Create the output directory because it doesn't exist" dirFile.mkdir() }

//Compute the BBOX of the ICU layer

def local_database_name = "geoclimate_sprawl"

def h2gis_db_parameters = [ "folder": outputDirectory, "name" : "${local_database_name};AUTO_SERVER=TRUE".toString(), "delete": false ]

if(!location){ println("The location value cannot be null") }

//Create before the local H2GIS database that will be used to compute the BBOX of the area H2GIS h2GIS = H2GIS.open(h2gis_db_parameters.folder + File.separator + h2gis_db_parameters.name) if(h2GIS==null){ println("Cannot create the local H2GIS database") return }

def outputTableNames = runGeoclimate(h2gis_db_parameters, location, outputDirectory )

if(!outputTableNames){ println("Cannot compute the GeoClimate indicators") }

def rsu_lcz = outputTableNames.rsu_lcz

//Extract sprawl area String urbanSprawlH2GIS = computeUrbanSprawl(h2GIS, rsu_lcz )

if(!urbanSprawlH2GIS){ println("Cannot compute the urban sprawl") return }

//Save the data in a geojson file h2GIS.save(urbanSprawlH2GIS, outputDirectory+File.separator+"osm_"+location+ File.separator+"urban_sprawl.geojson", true)

/**

/*================================================================================

/*================================================================================

/*================================================================================

/**

//Create a grid to generalize the urban areas h2GIS.execute(""" DROP TABLE IF EXISTS grid; CREATE TABLE grid as select * from ST_MAKEGRID('$mergingLcz', 100,100); """.toString())

h2GIS.createSpatialIndex("grid")
h2GIS.createSpatialIndex(mergingLcz)

//Compute the percentage by grid h2GIS.execute(""" DROP TABLE IF EXISTS grid_lcz, grid_lcz_area, grid_raster; CREATE TABLE grid_lcz as select st_area(st_intersection(a.the_geom, b.the_geom)) as area, a.id from grid as a, $mergingLcz as b where a.the_geom && b.the_geom and st_intersects(a.the_geom, b.the_geom); CREATE TABLE grid_lcz_area as select sum(area) as sum_lcz, id from grid_lcz group by id; CREATE INDEX ON grid_lcz_area (ID); CREATE INDEX ON grid (ID); CREATE TABLE grid_raster as select a.id, a.the_geom from grid as a left join grid_lcz_area as b on a.id=b.id where sum_lcz/(100*100) > 0.4 """.toString())

def urban_sprawl = "urban_sprawl"

h2GIS.execute("""

DROP TABLE IF EXISTS $urban_sprawl; CREATE TABLE $urban_sprawl as select EXPLOD_ID as id_rsu, the_geom from ST_EXPLODE('( select st_removeholes(st_union(st_accum(the_geom))) as the_geom FROM grid_raster)') ; DROP TABLE IF EXISTS grid_lcz, grid_raster, grid, grid_lcz_area, mergingLcz; """.toString())

return urban_sprawl

}

j3r3m1 commented 7 months ago

Which area were you expecting to obtain ? You probably know that you can check what is the OSM area corresponding to your location using Nominatim. Here is what you get for your string location: https://nominatim.openstreetmap.org/ui/search.html?q=Senlis%2C+Oise%2C+Hauts-de-France%2C+France+m%C3%A9tropolitaine%2C+60300%2C+France

Note that the first geometry will be taken. When I use the GeoClimate workflow with the corresponding string I get the same area.

balglave commented 7 months ago

Just found the problem. I had to write the cities by hand in the groovy script. Asking the request from R with the full name of the city was not working.

Note that 3 cities did not run well (geoclimate return an error):

# ["Fresnes, L'Hay-les-Roses, Val-de-Marne, Île-de-France, France métropolitaine, 94260, France"]
# ["Héricourt, Lure, Haute-Saône, Bourgogne-Franche-Comté, France métropolitaine, 70400, Frances"]
# ["Saint-Raphaël, Draguignan, Var, Provence-Alpes-Côte d'Azur, France métropolitaine, France"]
j3r3m1 commented 7 months ago

"Fresnes, L'Hay-les-Roses, Val-de-Marne, Île-de-France, France métropolitaine, 94260, France"

Works with "Fresnes, l Hay-les-Roses"

Note that "Fresnes, l'Hay-les-Roses" does not work. Probably something wrong with the ' that should be converted into an other character in the tables. Here is the error log:

11:49:48.848 [main] INFO GeoClimate -- Downloading the Nominatim data. org.h2.jdbc.JdbcSQLSyntaxErrorException: Erreur de syntaxe dans l'instruction SQL "drop table if exists ZONE_e552d345_ca46_4d28_93cf_589a20d41624; \000a create table ZONE_e552d345_ca46_4d28_93cf_589a20d41624 (the_geom GEOMETRY(POLYGON, 32631), ID_ZONE VARCHAR);\000a INSERT INTO ZONE_e552d345_ca46_4d28_93cf_589a20d41624 VALUES (ST_GEOMFROMTEXT('POLYGON ((449186.4557039871 5400497.795920359, 449391.62213820015 5400374.786716336, 449347.2411722845 5400311.666218308, 449402.5147829519 5400227.390018793, 449382.0520492527 5400215.424192653, 449373.365141465 5400208.310103325, 449289.7820869955 5400138.129584635, 449449.17769221374 5400041.628601131, 449588.90189669153 5400040.969664565, 449781.72155676916 5399905.657753432, 449788.3192669595 5399907.699689557, 449797.79455972865 5399909.282286631, 449802.0824065698 5399909.510663566, 449851.17416013253 5399898.821227104, 449862.91108323843 5399893.546836732, 449889.2295173843 5399871.444531724, 449904.4114286064 5399862.559794336, 449931.5514036597 5399855.847152205, 449966.4072156549 5399838.904941164, 449984.56275697646 5399813.941170548, 450014.12801783613 5399778.281306279, 450064.9885117137 5399748.946195439, 450208.81999731966 5399675.295446384, 450240.79870048125 5399736.465055783, 450251.3104358172 5399752.09086982, 450254.42782192386 5399755.442697485, 450285.0968859348 5399788.4319402, 450305.8365158367 5399823.377049847, 450297.59176155215 5399827.085396069, 450315.9457852289 5399854.1698877085, 450313.88013467565 5399859.980070165, 450317.5015034741 5399865.461890176, 450345.67085818603 5399906.8223545225, 450370.71911004465 5399943.60824769, 450358.2543147486 5399959.693563908, 450352.16793090757 5399968.863295614, 450346.0369726136 5399982.124417871, 450343.46135523455 5399990.940651967, 450340.6340356206 5400001.21542197, 450337.5527181991 5400016.005873444, 450334.2411594892 5400028.041397983, 450326.9567083861 5400049.650385471, 450319.3780654909 5400068.749592389, 450315.54141661135 5400076.276358985, 450291.9213819262 5400118.39633624, 450282.85966299474 5400149.270356654, 450302.74532345595 5400123.736413458, 450320.2061602806 5400114.043284962, 450346.0483275113 5400104.476008742, 450411.7096209214 5400075.646482678, 450464.19579957303 5400049.01308289, 450469.6304902175 5400045.941249684, 450477.08250802796 5400040.728274289, 450508.0304291539 5400019.077109238, 450519.4457005715 5400011.47241065, 450538.2649184794 5399999.022123294, 450550.0635435568 5399988.201345399, 450566.37995391537 5399972.849530034, 450585.91297647654 5399954.623484186, 450604.1267361488 5399938.499102336, 450630.82322424476 5399908.948727972, 450645.6676010474 5399892.509562681, 450653.01337419596 5399884.374044671, 450656.16471332073 5399879.932912319, 450686.21192132286 5399837.624558547, 450732.06083290116 5399760.559658047, 450753.156532033 5399725.100555728, 450780.9110997884 5399686.91499798, 450785.51397563174 5399690.354116105, 450840.76005896047 5399751.422736568, 450884.10527507134 5399800.167645197, 450902.97118499986 5399821.390976154, 450981.26231898606 5399751.558871589, 450973.766229893 5399741.752759384, 451029.1221002607 5399692.899411759, 451051.0438494816 5399716.397697331, 451147.5374895178 5399630.167335436, 451154.5077633163 5399637.021195823, 451189.7631831443 5399604.630866334, 451268.493569632 5399689.333451691, 451281.1716330431 5399677.1170026595, 451356.8479360927 5399817.598025595, 451393.21312238893 5399911.4081540955, 451394.88669786055 5399917.896949993, 451399.57213893504 5399930.9185155975, 451400.6230732841 5399939.358152555, 451417.5829393398 5399974.184430427, 451462.46292355435 5400084.607446353, 451494.0567460812 5400128.656372755, 451551.53334324074 5400210.1896581445, 451579.7628309647 5400256.369230127, 451584.913372604 5400262.049849057, 451659.38607762626 5400388.3380081635, 451681.2013036461 5400428.225761281, 451683.69631598867 5400431.1501838565, 451690.80849549326 5400435.046406446, 451693.295798957 5400438.782424872, 451694.3532071167 5400440.363004495, 451697.13098988903 5400444.541190494, 451707.10239237314 5400459.507323827, 451734.3790599308 5400496.913612394, 451784.6618975564 5400565.882564621, 451623.80931509176 5400691.288601541, 451703.56226997665 5400808.427071376, 451622.94236017525 5400856.391556539, 451552.8174746513 5400898.174413748, 451546.4836625307 5400889.891618458, 451527.8253480534 5400902.148169473, 451500.82160263765 5400867.341838345, 451374.65886696195 5400935.85933252, 451363.6560580452 5400941.7800910445, 451349.0904750037 5400949.610564026, 451336.7341682323 5400957.933248651, 451323.2207677585 5400966.732925257, 451319.43354677677 5400969.033676163, 451267.51524406445 5400996.176719406, 451193.6785583853 5401067.800620206, 451147.074139126 5401114.152810196, 451180.27449202206 5401133.762337309, 451194.1280508516 5401142.979688819, 451206.8232227028 5401152.529555747, 451230.161614842 5401172.325371933, 451251.9645847387 5401193.05734612, 451272.3337670285 5401214.580057562, 451290.8813201387 5401237.085850526, 451364.6050507473 5401326.880220951, 451103.9578963922 5401471.467884557, 451091.3534910743 5401478.136901378, 451082.3741522047 5401483.340202955, 451030.884356604 5401510.904248382, 451013.2359019766 5401477.785989319, 450985.8439914474 5401493.567043223, 450958.71877107676 5401507.055832017, 450947.3005147614 5401496.417008284, 450757.3691186264 5401570.010196174, 450751.2323080121 5401565.79531274, 450717.32034636074 5401577.944270487, 450697.3937107239 5401585.078852554, 450648.3132664605 5401605.532705718, 450641.39386191184 5401608.417381745, 450601.10065171064 5401625.247919553, 450601.6443016831 5401631.890991451, 450533.47653977654 5401645.377304548, 450445.86427960586 5401680.514271669, 450392.09135372244 5401705.314157968, 450374.84814612404 5401713.304355933, 450275.3636843151 5401731.240344203, 450269.90077475726 5401704.463911433, 450274.1047717441 5401666.451413923, 450308.0878343536 5401487.768769119, 450311.1546641728 5401479.73742248, 450166.65804645116 5401490.048574932, 450166.414309474 5401601.374875592, 450166.8850756348 5401688.938122744, 450141.4899306539 5401693.37751868, 450142.56313472195 5401702.48378037, 450089.2661020437 5401709.606562388, 450090.221166638 5401716.168109033, 449943.32704070356 5401732.965400777, 449922.06053804467 5401739.670073882, 449922.2052387251 5401724.627667308, 449858.2330328927 5401709.036356529, 449859.0441744224 5401693.754523334, 449862.13513199886 5401688.501915539, 449861.0167004348 5401680.140935352, 449849.79232734995 5401670.836606609, 449792.79725252296 5401727.776656369, 449761.49255725235 5401737.784750452, 449738.34042740095 5401743.984554174, 449728.8442952533 5401747.104723617, 449716.96150079125 5401756.960933406, 449690.18527967884 5401678.794232634, 449684.0749835697 5401678.426705004, 449670.66332453693 5401636.758955985, 449673.88535850565 5401632.205426689, 449667.84975706623 5401615.628853145, 449697.5569404078 5401602.79979833, 449681.57255079754 5401550.449602158, 449682.626290807 5401536.043791938, 449680.21104114247 5401524.070402546, 449661.0846429676 5401477.051249656, 449654.18555568287 5401460.093365156, 449648.32149656356 5401439.735537075, 449610.23526727903 5401231.2479106225, 449558.1769191498 5401257.19650097, 449518.3738356796 5401179.970628139, 449527.9108431783 5401109.537147696, 449538.04784420197 5401020.833287049, 449491.7348752377 5400952.204018024, 449473.2887241349 5400920.676260591, 449446.5622783589 5400883.00898335, 449440.38763346703 5400873.170723848, 449435.62040328287 5400864.542617022, 449401.7596678065 5400819.0914686425, 449397.70609006553 5400812.991589213, 449393.9534158046 5400807.656056781, 449358.6250850182 5400756.860097959, 449342.9402350932 5400732.533747391, 449328.3243412077 5400711.821863853, 449309.0956120874 5400682.536202103, 449306.09948471916 5400677.160528363, 449186.4557039871 5400497.795920359))', 32631), 'Fresnes, l'Hay-les-Roses[*]');"

j3r3m1 commented 7 months ago

Héricourt, Lure, Haute-Saône, Bourgogne-Franche-Comté, France métropolitaine, 70400, Frances

Works if you put "Héricourt, Lure, Haute-Saône, Bourgogne-Franche-Comté" (I think the problem comes from the "s" at the end of France) --> always check the string in the Nominatim platform: https://nominatim.openstreetmap.org/ui/search.html?q=H%C3%A9ricourt%2C+Lure%2C+Haute-Sa%C3%B4ne%2C+Bourgogne-Franche-Comt%C3%A9

j3r3m1 commented 7 months ago

Saint-Raphaël, Draguignan, Var, Provence-Alpes-Côte d'Azur, France métropolitaine, France

Works with "Saint-Raphaël, Draguignan". I have no idea why the full adress does not work in this case and in the first case but in general a shorter name that works in Nominatim is a better option.

j3r3m1 commented 7 months ago

OK the problem comes from the '. @ebocher should we converted into an other character ? If yes into a space ? Or "_" ?