How to get GeoJson file from REST JSON API?

63 views
Skip to first unread message

Adriano Ellero

unread,
Feb 4, 2024, 5:19:23 PMFeb 4
to OpenAIP - Aviation Data Platform
Hi all.
Actually I am loading GeoJson file on google maps map from static files which are saved on my web site.

How can I use the REST JSON API to get a GeoJson file?
It would make my google maps map dynamically updated. 

thx

webmaster

unread,
Feb 5, 2024, 1:45:54 AMFeb 5
to OpenAIP - Aviation Data Platform
Hi,

this is not possible with the current REST API. You can create a full GeoJSON file for a single country on the fly from the API but this will increase page load and response time of you app dramatically. But if you do this work beforehand, you can download the file, then deploy and run the app. 

Cheers,

Stephan

Adriano Ellero

unread,
Feb 5, 2024, 2:38:43 AMFeb 5
to webmaster, OpenAIP - Aviation Data Platform
Thank you Stefphan, this is what I do nowadays.

Maybe I could work on a procedure that fetch the json data from REST API and generates a geoJson object to be passed to google maps data class.

In case of success I share with you the code, maybe it could be a common need for someone else.

Best regards
 
Dr. Adriano Ellero

FI SPL - TMG IT.SFCL.22573
FI VDS Avanzato 00077089
HT IT.DTO.060





--
You received this message because you are subscribed to a topic in the Google Groups "OpenAIP - Aviation Data Platform" group.
To unsubscribe from this topic, visit https://groups.google.com/d/topic/openaip/bZFXmwdDVK0/unsubscribe.
To unsubscribe from this group and all its topics, send an email to openaip+u...@googlegroups.com.
To view this discussion on the web visit https://groups.google.com/d/msgid/openaip/b361ce50-5d37-43b0-89d1-80099a179c42n%40googlegroups.com.

OpenAIP - Webmaster

unread,
Feb 5, 2024, 3:33:41 AMFeb 5
to Adriano Ellero, OpenAIP - Aviation Data Platform
The conversion JSON -> GeoJSON is actually pretty easy and can be done on the fly when fetching the data - wherever this happens. Although I think that getting a complete GeoJSON upfront and even have it behind a CDN/browser cache is more performant. 

Have fun and share the code. Others may find it helpful! Cheers!

Adriano Ellero

unread,
Feb 5, 2024, 6:09:24 AMFeb 5
to OpenAIP - Webmaster, OpenAIP - Aviation Data Platform
Other options if possible. How to download the latest version of geoJson files by server to server on a daily basis or to download when there are updated versions?

Dr. Adriano Ellero

FI SPL - TMG IT.SFCL.22573
FI VDS Avanzato 00077089
HT IT.DTO.060




OpenAIP - Webmaster

unread,
Feb 5, 2024, 6:27:43 AMFeb 5
to Adriano Ellero, OpenAIP - Aviation Data Platform
If you want to download on a day to day basis, I would advise to use the export bucket. A script that either downloads all GeoJSON files (only a subset) from the bucket is straight forward.

Adriano Ellero

unread,
Feb 5, 2024, 6:54:02 AMFeb 5
to OpenAIP - Webmaster, OpenAIP - Aviation Data Platform
I will check how it works.

in the meantime, the json to geoJson rough code in JS (quite in a rush therefore not really professional):

            function jsonToGeoJson() {


                fetch(api, {
                    method: "GET",
                    headers: { 'x-openaip-client-id': 'xyz...' }
                })
                    .then(response => response.json())
                    .then(json => {
                        const jsonItem = json.items;
                        // for each json.item add features
                        let features = [];
                        jsonItem.forEach((item, index, itemArray) => {
                            const feature = {
                                "type": "Feature",
                                "properties": item,
                                "geometry": item.geometry
                            }
                            features.push(feature);
                        });
                        const geoJson = { "type": "FeatureCollection", "features": features };
                        console.log(geoJson); // final result
                    })
                    .catch(error => console.log(error));
            }

 
Dr. Adriano Ellero

FI SPL - TMG IT.SFCL.22573
FI VDS Avanzato 00077089
HT IT.DTO.060




Reply all
Reply to author
Forward
0 new messages