1

I'm trying to add a new vector layer in QGIS from a REST API endpoint. This endpoint actually returns a JSON array containing individual GeoJSON features, e.g.: https://api.sharedmobility.ch/v1/sharedmobility/identify?filters=ch.bfe.sharedmobility.provider.id=donkey_ge&offset=0&geometryFormat=geojson

but QGIS says that this is not a valid data source when I try to load it using the "Protocol: HTTP(S) , cloud, etc..." Source Type in the Data Source Manager.

I know I had this same problem some time ago, but it seems that the provided solution is not working with this particular API.

Do you know how I can load that type of data into QGIS (3.26)?

API doc: https://api.sharedmobility.ch/documentation

1 Answer 1

1

The endpoint of your API is sending an array of Geojson Feature Objects, while QGIS needs a FeatureCollection which is a container of multiple Feature Objects. See this pastebin which already converted your data as a FeatureCollection. You can add it as a Protocol Layer to QGIS.

enter image description here

enter image description here

The best way to solve the problem would be to ask the maintainer of the API to return the data as a FeatureCollection additionally. Another way would be to proxy and transform the data through some custom service on the fly.

Here is some sample code how I created the pastebin using NodeJs and the awesome TurfJS library. If you use a proxy as a generic solution, an ExpressJS service using TurfJS could be one solution.

const { featureCollection } = require("@turf/helpers");
const data = require("./data.json");
const fs = require("fs");

const fc = featureCollection(data);
fs.writeFileSync("./fc.json", JSON.stringify(fc));

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

Not the answer you're looking for? Browse other questions tagged or ask your own question.