GADM (https://gadm.org/data.html)

Hi, i wanted do load the swissmap JSON file from GADM into Scilab 2023.1. Level 0 works with 34kb. But Level 1 with unzipped 134kb crashes Scilab on windows 11. Could anyone confirm this, before making a Bug.

M.f.G. Pascal

[res, status] = http_get(“https://geodata.ucdavis.edu/gadm/gadm4.1/json/gadm41_CHE_1.json.zip","C:\Users\buehlpas\Documents\Scilab\gadm41_CHE_1.json.zip”);

[output,bOK]=dos(“cd C:\Users\buehlpas\Documents\Scilab\ && tar -xf gadm41_CHE_1.json.zip”);

result = fromJSON(“C:\Users\buehlpas\Documents\Scilab\gadm41_CHE_1.json”, “file”);

//[result, status] = http_get(“https://geodata.ucdavis.edu/gadm/gadm4.1/json/gadm41_CHE_0.json”, format=“JSON”);
//scale=3;
//coord_x=result.features.geometry.coordinates(1)(1)(:,1);
//coord_y=result.features.geometry.coordinates(1)(1)(:,2);

Hi Pascal
I can make these commands run fine, if I change to single-quotes (changing path to my user space):

→ [res, status] = http_get(‘https://geodata.ucdavis.edu/gadm/gadm4.1/json/gadm41_CHE_0.json.zip’,'D:\Userdata\Claus\Documents\Scilab\gadm41_CHE_1.json.zip’);

→ [output,bOK]=dos(‘cd D:\Userdata\Claus\Documents\Scilab && tar -xf gadm41_CHE_1.json.zip’);

result = fromJSON(‘D:\Userdata\Claus\Documents\Scilab\gadm41_CHE_0.json’, ‘file’);

Note how CHE_1 changes name to CHE_0 (not sure why, looks confusing, but that’s what is inside the ZIP file).

Cannot upload ZIP or JSON data? Have to do it this way
gadm41_CHE_1.json.zip.sod (40.0 KB)

but just remove sod, unzip the file and you have the JSON File from GADM

Thanks :slight_smile:

Tried with Scilab 2024.0 following code:

countries=["CHE"];
depth=["0","1","2","3"];
URL=["https://geodata.ucdavis.edu/gadm/gadm4.1/json/gadm41"];
path=fullfile(TMPDIR,"Messungen");
ending=[".csv",".svg",".json",".zip"];

[CHF_0, status]=http_get(URL(1)+"_"+countries(1)+"_"+depth(1)+ending(3), format="JSON");

[res, status]=http_get(URL(1)+"_"+countries(1)+"_"+depth(2)+ending(3)+ending(4),path(1)+"GADM");
files=decompress(res,path(1));
CHF_1=fromJSON(files, "file");

works, but fromJSON crashes?

Hello,

You are right, there is a crash (tested on Scilab 2024.0.0 macOS version). Can you take the time to create a Gitlab account and create an issue at Issues · scilab / scilab · GitLab? Please include your code above as modified (I have changed the path of the file so that anybody can copy/paste it).

S.

1 Like

Thank You, now CADM works perfectly in Scilab.

I made my plots with extracting the Datas out of the structs.

Now i have another question in the struct there is this structure at the end:
coordinates: --1 (sub --1 ,–2) --2, --3 and --4.
So how do i parse this elegantly in one for loop, to obtain all values in a row, i tried many ways, (try-catch 7 index i,j) etc, but none of them was satisfying. Any Ideas or suggestions?

Hello, when Scilab displays

--> CHF_0.features.geometry.coordinates

 ans = (4-elements list)

  (1): (2-elements list)
      (1): [1806x2 double]
      (2): [33x2 double]
  (2): [5x2 double]
  (3): [5x2 double]
  (4): [5x2 double]

you don’t need to parse anything, I mean, for example you get the last [5x2 double] with

CHF_0.features.geometry.coordinates(4)

and the [1806x2 double] at the begining with

CHF_0.features.geometry.coordinates(1)(1)

S.

I could not directly make a picture, but here it is.

maybe this helps.

Parentally Julia does this. Actually, I found Julia and Scilab quite similar on the surface.

M.f.G. Pascal

13-06-2024_15-42-05.png

thats the point, i wanna parse anythig with one loop. :grin:

Structs are structs… there is no way to automatically serialize this type of object.

S.

Ok, if it’s so, it’s so. Thanks :slight_smile:

For very special cases, you can serialize structs, typically when the fields are on the same level, of array type, and can be concatenated along a given dimension, e.g.:

clear a
a.x=1:3
a.y=sin(1:3)
cat(1,a(fieldnames(a)))

which yields

--> a.x=1:3

 a = [struct] with fields:

  x = [1,2,3]

--> a.y=sin(1:3)

 a = [struct] with fields:

  x = [1,2,3]
  y = [0.841471,0.9092974,0.14112]

--> cat(1,a(fieldnames(a)))

 ans = [2x3 double]

   1.         2.          3.     
   0.841471   0.9092974   0.14112

see the respective help pages fieldnames - Get a tlist, mlist or struct fields names, cat - Stacks vectors matrices or arrays into an hypermatrix or hyperarray

S.

I will try this, thanks :slight_smile:

M.f.G. Pascal

Na, not really what i want.
I’ve tried something else like if error “Invalid index” then continue else take the datas, but it does not work. i somehow need to handle this “Invalid index”.

M.f.G. Pascal

PS: With CURL will there be also a toolbox for MQTT an WS?

Not to my knowledge…

S.