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

**URL:** <https://scilab.discourse.group/t/gadm-https-gadm-org-data-html/134>\
**Category:** General usage\
**Created:** [August 14, 2023, 5:51am UTC](https://scilab.discourse.group/t/gadm-https-gadm-org-data-html/134 "2023-08-14T05:51:58Z")\
**Posts on this page:** 15\
**Page:** 1

<div class="post-metadata">

**Author:** ![pascal](https://yyz2.discourse-cdn.com/free1/user_avatar/scilab.discourse.group/pascal/32/40_2.png) [@pascal](https://scilab.discourse.group/u/pascal)\
**Post date:** [August 14, 2023, 5:51am UTC](https://scilab.discourse.group/t/gadm-https-gadm-org-data-html/134/1 "2023-08-14T05:51:58Z")

</div>

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](https://geodata.ucdavis.edu/gadm/gadm4.1/json/gadm41_CHE_1.json.zip%22,%22C:%5CUsers%5Cbuehlpas%5CDocuments%5CScilab%5Cgadm41_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](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);

---

<div class="post-metadata">

**Author:** ![cfuttrup](https://avatars.discourse-cdn.com/v4/letter/c/3ec8ea/32.png) [@cfuttrup](https://scilab.discourse.group/u/cfuttrup)\
**Post date:** [August 16, 2023, 6:51pm UTC](https://scilab.discourse.group/t/gadm-https-gadm-org-data-html/134/2 "2023-08-16T18:51:14Z")

</div>

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](https://geodata.ucdavis.edu/gadm/gadm4.1/json/gadm41_CHE_0.json.zip','D:%5CUserdata%5CClaus%5CDocuments%5CScilab%5Cgadm41_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).

---

<div class="post-metadata">

**Author:** ![pascal](https://yyz2.discourse-cdn.com/free1/user_avatar/scilab.discourse.group/pascal/32/40_2.png) [@pascal](https://scilab.discourse.group/u/pascal)\
**Post date:** [August 17, 2023, 5:37am UTC](https://scilab.discourse.group/t/gadm-https-gadm-org-data-html/134/3 "2023-08-17T05:37:14Z")

</div>

Cannot upload ZIP or JSON data? Have to do it this way  
[gadm41\_CHE\_1.json.zip.sod](https://scilab.discourse.group/uploads/short-url/8XUYzIkunP6EEP2KRLMxuyV8coX.sod) (40.0 KB)

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

Thanks 🙂

---

<div class="post-metadata">

**Author:** ![pascal](https://yyz2.discourse-cdn.com/free1/user_avatar/scilab.discourse.group/pascal/32/40_2.png) [@pascal](https://scilab.discourse.group/u/pascal)\
**Post date:** [October 25, 2023, 11:44am UTC](https://scilab.discourse.group/t/gadm-https-gadm-org-data-html/134/4 "2023-10-25T11:44:36Z")

</div>

Tried with Scilab 2024.0 following code:

```plaintext
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?

---

<div class="post-metadata">

**Author:** ![mottelet](https://yyz2.discourse-cdn.com/free1/user_avatar/scilab.discourse.group/mottelet/32/13_2.png) [@mottelet](https://scilab.discourse.group/u/mottelet)\
**Post date:** [October 25, 2023, 1:33pm UTC](https://scilab.discourse.group/t/gadm-https-gadm-org-data-html/134/6 "2023-10-25T13:33:17Z")

</div>

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](https://gitlab.com/scilab/scilab/-/issues)? Please include your code above as modified (I have changed the path of the file so that anybody can copy/paste it).

S.

---

<div class="post-metadata">

**Author:** ![pascal](https://yyz2.discourse-cdn.com/free1/user_avatar/scilab.discourse.group/pascal/32/40_2.png) [@pascal](https://scilab.discourse.group/u/pascal)\
**Post date:** [June 13, 2024, 1:49pm UTC](https://scilab.discourse.group/t/gadm-https-gadm-org-data-html/134/7 "2024-06-13T13:49:20Z")

</div>

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?

---

<div class="post-metadata">

**Author:** ![mottelet](https://yyz2.discourse-cdn.com/free1/user_avatar/scilab.discourse.group/mottelet/32/13_2.png) [@mottelet](https://scilab.discourse.group/u/mottelet)\
**Post date:** [June 13, 2024, 2:31pm UTC](https://scilab.discourse.group/t/gadm-https-gadm-org-data-html/134/8 "2024-06-13T14:31:46Z")

</div>

> [@pascal](#):
>
> coordinates: --1 (sub --1 ,–2) --2, --3 and --4.

Hello, when Scilab displays

```auto
--> 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

```auto
CHF_0.features.geometry.coordinates(4)

```

and the [1806x2 double] at the begining with

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

```

S.

---

<div class="post-metadata">

**Author:** ![pascal](https://yyz2.discourse-cdn.com/free1/user_avatar/scilab.discourse.group/pascal/32/40_2.png) [@pascal](https://scilab.discourse.group/u/pascal)\
**Post date:** [June 14, 2024, 5:12am UTC](https://scilab.discourse.group/t/gadm-https-gadm-org-data-html/134/9 "2024-06-14T05:12:18Z")

</div>

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](https://global.discourse-cdn.com/free1/uploads/utc/original/1X/60a5563ac8309971f5adc3fbc6142dd8d68d047b.png)

---

<div class="post-metadata">

**Author:** ![pascal](https://yyz2.discourse-cdn.com/free1/user_avatar/scilab.discourse.group/pascal/32/40_2.png) [@pascal](https://scilab.discourse.group/u/pascal)\
**Post date:** [June 14, 2024, 2:17pm UTC](https://scilab.discourse.group/t/gadm-https-gadm-org-data-html/134/10 "2024-06-14T14:17:10Z")

</div>

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

---

<div class="post-metadata">

**Author:** ![mottelet](https://yyz2.discourse-cdn.com/free1/user_avatar/scilab.discourse.group/mottelet/32/13_2.png) [@mottelet](https://scilab.discourse.group/u/mottelet)\
**Post date:** [June 14, 2024, 2:35pm UTC](https://scilab.discourse.group/t/gadm-https-gadm-org-data-html/134/11 "2024-06-14T14:35:37Z")

</div>

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

S.

---

<div class="post-metadata">

**Author:** ![pascal](https://yyz2.discourse-cdn.com/free1/user_avatar/scilab.discourse.group/pascal/32/40_2.png) [@pascal](https://scilab.discourse.group/u/pascal)\
**Post date:** [June 17, 2024, 6:55am UTC](https://scilab.discourse.group/t/gadm-https-gadm-org-data-html/134/12 "2024-06-17T06:55:11Z")

</div>

Ok, if it’s so, it’s so. Thanks 🙂

---

<div class="post-metadata">

**Author:** ![mottelet](https://yyz2.discourse-cdn.com/free1/user_avatar/scilab.discourse.group/mottelet/32/13_2.png) [@mottelet](https://scilab.discourse.group/u/mottelet)\
**Post date:** [June 17, 2024, 7:13am UTC](https://scilab.discourse.group/t/gadm-https-gadm-org-data-html/134/13 "2024-06-17T07:13:32Z")

</div>

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.:

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

```

which yields

```scilab
--> 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](https://help.scilab.org/fieldnames), [cat - Stacks vectors matrices or arrays into an hypermatrix or hyperarray](https://help.scilab.org/cat)

S.

---

<div class="post-metadata">

**Author:** ![pascal](https://yyz2.discourse-cdn.com/free1/user_avatar/scilab.discourse.group/pascal/32/40_2.png) [@pascal](https://scilab.discourse.group/u/pascal)\
**Post date:** [June 17, 2024, 7:25am UTC](https://scilab.discourse.group/t/gadm-https-gadm-org-data-html/134/14 "2024-06-17T07:25:26Z")

</div>

I will try this, thanks 🙂

M.f.G. Pascal

---

<div class="post-metadata">

**Author:** ![pascal](https://yyz2.discourse-cdn.com/free1/user_avatar/scilab.discourse.group/pascal/32/40_2.png) [@pascal](https://scilab.discourse.group/u/pascal)\
**Post date:** [June 20, 2024, 12:40pm UTC](https://scilab.discourse.group/t/gadm-https-gadm-org-data-html/134/15 "2024-06-20T12:40:10Z")

</div>

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?

---

<div class="post-metadata">

**Author:** ![mottelet](https://yyz2.discourse-cdn.com/free1/user_avatar/scilab.discourse.group/mottelet/32/13_2.png) [@mottelet](https://scilab.discourse.group/u/mottelet)\
**Post date:** [June 20, 2024, 3:52pm UTC](https://scilab.discourse.group/t/gadm-https-gadm-org-data-html/134/16 "2024-06-20T15:52:27Z")

</div>

> [@pascal](#):
>
> MQTT an WS

Not to my knowledge…

S.
