1

I'm simply trying to import this feature directly into QGIS 3.16.3-Hannover as a new vector layer:

https://api3.geo.admin.ch/rest/services/api/MapServer/find?layer=ch.swisstopo.swissboundaries3d-land-flaeche.fill&searchText=ch&searchField=id&returnGeometry=true&geometryFormat=geojson

When loading it into a web browser, it shows the GeoJSON object as follows:

geojson object

Well, it's not directly a GeoJSON as it's "encapsulated" as the first (and only) element of the JSON array called results.
Which is probably the source of the following problem...

Because when trying to load it in QGIS*, I first get this message:

Download with "Protocol" source type has failed, do you want to try the "File" source type?

and if I click "No", it then shows this error:

Invalid Data Source: /vsicurl/https://api3.geo.admin.ch/rest/services/api/MapServer/find?layer=ch.swisstopo.swissboundaries3d-land-flaeche.fill&searchText=ch&searchField=id&returnGeometry=true&geometryFormat=geojson is not a valid or recognized data source.

How could I tell QGIS to first unpack the first element of the results array so that it can (hopefully) read the GeoJSON feature?

Changing the protocol type from HTTP/HTTPS/FTP to GeoJSON does help, but then the feature is not properly loaded on the table of content (it has no geometry):

no geometry feature loaded


*I'm trying to load it through the Data Source Manager > Vector > Source Type: "Protocol: HTTP(S), cloud, etc..." and by simply pasting the URL into, well, the URI field.

This is the API doc: https://api3.geo.admin.ch/services/sdiservices.html#find

2

3 Answers 3

3

It may be convenient to use a VRT file if you often use the same remote layer in different QGIS projects instead of copying/pasting it in each of them.

Put in file myvrt_demo.vrt the following content and drag and drop the vrt file within QGIS

<OGRVRTDataSource>
    <OGRVRTLayer name="swissboundaries3d_land_flaeche_fill">
        <SrcDataSource>https://api3.geo.admin.ch/rest/services/api/MapServer/ch.swisstopo.swissboundaries3d-land-flaeche.fill/CH?geometryFormat=geojson&sr=4326</SrcDataSource>
        <SrcLayer>feature</SrcLayer>
        <LayerSRS>EPSG:4326</LayerSRS>
    </OGRVRTLayer>
</OGRVRTDataSource>
1
  • Thanks for sharing this very nice hint which will for sure be helpful for saving complex requests. Commented Oct 5, 2021 at 16:35
1

Looks like GeoJSON is a little confusing for QGIS.

Using "geometryFormat" rather than Type

https://api3.geo.admin.ch/rest/services/api/MapServer/ch.swisstopo.swissboundaries3d-land-flaeche.fill/CH?geometryFormat=geojson&sr=4326

Is working for certain urls

Example:

enter image description here

1
  • Hmm, ok then, so it's the /find endpoint which seems to encapsulate the results in a so called results array here. Without that endpoint, it's indeed working well. I also fix my post, it was a typo from my side when writing geometryType as a parameter instead of geometryFormat. Commented Oct 4, 2021 at 22:01
1

QGIS may have some problem with connecting to services but in this case I fear that the result would be failure in any case. GDAL does not find geometry nor attributes from this JSON.

ogrinfo "https://api3.geo.admin.ch/rest/services/api/MapServer/find?layer=ch.swisstopo.swissboundaries3d-land-flaeche.fill&searchText=ch&searchField=id&returnGeometry=true&geometryType=geojson" -al
INFO: Open of `https://api3.geo.admin.ch/rest/services/api/MapServer/find?layer=ch.swisstopo.swissboundaries3d-land-flaeche.fill&searchText=ch&searchField=id&returnGeometry=true&geometryType=geojson'
      using driver `GeoJSONSeq' successful.

Layer name: GeoJSONSeq
Geometry: Unknown (any)
Feature Count: 1
Layer SRS WKT:
GEOGCRS["WGS 84",
    DATUM["World Geodetic System 1984",
        ELLIPSOID["WGS 84",6378137,298.257223563,
            LENGTHUNIT["metre",1]]],
    PRIMEM["Greenwich",0,
        ANGLEUNIT["degree",0.0174532925199433]],
    CS[ellipsoidal,2],
        AXIS["geodetic latitude (Lat)",north,
            ORDER[1],
            ANGLEUNIT["degree",0.0174532925199433]],
        AXIS["geodetic longitude (Lon)",east,
            ORDER[2],
            ANGLEUNIT["degree",0.0174532925199433]],
    ID["EPSG",4326]]
Data axis to CRS axis mapping: 2,1

Test in geojsonlint.com returns result "Invalid GeoJSON Line 1: "type" member required".

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.