Hi,

that doesn't look valid GeoJSON to me, you have no other options than
transforming  the JSON to valid GeoJSON (or to any other format recognized
by QGIS ogr provider), or you can create a vector layer from scratches and
and add the individual features in a loop, it largely depends on what you
need to do next with those data.

Both approaches require a bit of programming.



On Mon, Nov 25, 2019 at 6:10 PM Cliff Patterson <cpatter...@psdrcs.com>
wrote:

> I have a JSON endpoint that I want to load into a QGIS project as a flat
> table (no geometry). There are lat/ling coordinates in JSON (see below),
> but those coords are not important for my purpose since I want to
> eventually join the table with a spatial layer using a common ID. I can
> load the data into the console with:
>
> import urllib.request, json, csv
> with urllib.request.urlopen("https://my_json_endpoint";) as url:
>     data = json.loads(url.read().decode())
>     print(data)
>
> And I can load the table into QGIS as a GeoJSON with:
>
> import urllib.request, json
> uri = 'https://my_json_endpoint'
> iface.addVectorLayer(uri, 'Asset Data', 'ogr')
>
> but the table loads without attribute data and no rows.
>
> The JSON file looks like this (but with 20+ rows of data)
>
> {
>     "Assets": [
>         {
>             "adjusted_cost": 1940993,
>             "adjusted_eul": 240,
>             "adjusted_quantity": 1,
>             "amort_date": "2039-11-01",
>             "attributes": [],
>             "classifications": {
>                 "Acc. Amort. Code": "No Acc. Amort. Code",
>                 "Amort. Exp. Code": "No Amort. Exp. Code",
>                 "Capital Code": "No Capital Code",
>                 "Category": "Roads",
>                 "Class": "Infrastructure",
>                 "Department": "No Department",
>                 "Function": "No Function",
>                 "Schedule 51B Code": "No Schedule 51B Code",
>                 "Schedule 75C Code": "No Schedule 75C Code",
>                 "Segment": "Surface",
>                 "Sub-Function": "No Sub-Function"
>             },
>             "condition": 100,
>             "condition_assessment_date": "Age-based",
>             "condition_ratio": 1,
>             "description": null,
>             "eul": 240,
>             "gis_feature_id": "roads.1",
>             "historical_cost": 1940993,
>             "id": 1,
>             "import_id": "PATCH-1",
>             "initial_quantity": 1,
>             "is_fully_disposed": false,
>             "is_fully_transferred": false,
>             "is_lifecycle_excluded": true,
>             "lat": 42.985708676898,
>             "lifecycle_eul": 240,
>             "lifecycle_eul_events": 240,
>             "location": null,
>             "lon": -81.254337208244,
>             "name": "Road name 1",
>             "profile": "Default Profile",
>             "replacement_cost": 0,
>             "replacement_date": "2039-11-01",
>             "risk_consequence": 5,
>             "risk_probability": 1,
>             "risk_rating": 5,
>             "service_date": "2019-11-12",
>             "unit_of_measure": "Area (m2)"
>         },
>
>          ...
>
> }
>
>
> I could write a script to load the data into a DB table dynamically, but it 
> would be much better to load the data dynamically in QGIS. The ultimate 
> objective would be to create a tool that loads the data for the user.
>
> Any ideas how I can achieve this?
>
> Thanks!
>
> Cliff
>
> _______________________________________________
> Qgis-user mailing list
> Qgis-user@lists.osgeo.org
> List info: https://lists.osgeo.org/mailman/listinfo/qgis-user
> Unsubscribe: https://lists.osgeo.org/mailman/listinfo/qgis-user



-- 
Alessandro Pasotti
w3:   www.itopen.it
_______________________________________________
Qgis-user mailing list
Qgis-user@lists.osgeo.org
List info: https://lists.osgeo.org/mailman/listinfo/qgis-user
Unsubscribe: https://lists.osgeo.org/mailman/listinfo/qgis-user

Reply via email to