TransWikia.com

Accessing CSV data directly from website

Geographic Information Systems Asked by Keith Raymond on March 14, 2021

I want to do what this person has asked here. I am using QGIS 3.16

I have copied what was suggested and what seemed to work for the OP, however I am not getting any information displayed. The data is a CSV file with Ontario COVID data as well as lat and long info. Excel reads no problem and putting that URL into a web browser will download the CSV file. Ideally I would like to read it directly as it changes daily.

Also, is there a way to debug this in QGIS? I would expect to get some kind of error but it just loads the feature name based on filename with no data. It does append the layer name from the VRT so it must be reading something.

Here is my VRT file:

<OGRVRTDataSource>
<OGRVRTLayer name="COVID Cases">
    <SrcDataSource relativeToVRT="0">"/vsicurl/https://data.ontario.ca/dataset/f4112442-bdc8-45d2-be3c-12efae72fb27/resource/455fd63b-603d-4608-8216-7d8647f43350/download/conposcovidloc.csv"</SrcDataSource>
    <GeometryType>wkbPoint</GeometryType>
    <LayerSRS>WGS84</LayerSRS>
    <GeometryField encoding="PointFromColumns" x="Reporting_PHU_Longitude" y="Reporting_PHU_Latitude"/>
</OGRVRTLayer></OGRVRTDataSource>

2 Answers

At least I managed to read data with ogrinfo with a little modified VRT file.

<OGRVRTDataSource>
<OGRVRTLayer name="conposcovidloc">
    <SrcDataSource relativeToVRT="0">/vsicurl_streaming/https://data.ontario.ca/dataset/f4112442-bdc8-45d2-be3c-12efae72fb27/resource/455fd63b-603d-4608-8216-7d8647f43350/download/conposcovidloc.csv</SrcDataSource>
    <GeometryType>wkbPoint</GeometryType>
    <LayerSRS>WGS84</LayerSRS>
    <GeometryField encoding="PointFromColumns" x="Reporting_PHU_Longitude" y="Reporting_PHU_Latitude"/>
</OGRVRTLayer></OGRVRTDataSource>

Test with

ogrinfo test.vrt -al
...
OGRFeature(conposcovidloc):1
  Row_ID (String) = 1
  Accurate_Episode_Date (String) = 2020-01-22
  Case_Reported_Date (String) = 2020-01-23
  Test_Reported_Date (String) =
  Specimen_Date (String) = 2020-01-25
  Age_Group (String) = 50s
  Client_Gender (String) = FEMALE
  Case_AcquisitionInfo (String) = TRAVEL
  Outcome1 (String) = Resolved
  Outbreak_Related (String) =
  Reporting_PHU_ID (String) = 3895
  Reporting_PHU (String) = Toronto Public Health
  Reporting_PHU_Address (String) = 277 Victoria Street, 5th Floor
  Reporting_PHU_City (String) = Toronto
  Reporting_PHU_Postal_Code (String) = M5B 1W2
  Reporting_PHU_Website (String) = www.toronto.ca/community-people/health-wellness-care/
  Reporting_PHU_Latitude (String) = 43.65659125
  Reporting_PHU_Longitude (String) = -79.37935801
  POINT (-79.37935801 43.65659125)

Correct answer by user30184 on March 14, 2021

The documentation says "SrcLayer is optional". But without it I couldn't add the CSV file as vector layer to QGIS.

I've added <SrcLayer>conposcovidloc</SrcLayer> and changed vsicurl to vsicurl_streaming, then it worked.

<OGRVRTDataSource>
    <OGRVRTLayer name="COVID Cases">
        <SrcDataSource relativeToVRT="0">/vsicurl_streaming/https://data.ontario.ca/dataset/f4112442-bdc8-45d2-be3c-12efae72fb27/resource/455fd63b-603d-4608-8216-7d8647f43350/download/conposcovidloc.csv</SrcDataSource>
        <SrcLayer>conposcovidloc</SrcLayer>
        <GeometryType>wkbPoint</GeometryType>
        <LayerSRS>WGS84</LayerSRS>
        <GeometryField encoding="PointFromColumns" x="Reporting_PHU_Longitude" y="Reporting_PHU_Latitude"/>
    </OGRVRTLayer>
</OGRVRTDataSource>

enter image description here

Answered by Kadir Şahbaz on March 14, 2021

Add your own answers!

Ask a Question

Get help from others!

© 2024 TransWikia.com. All rights reserved. Sites we Love: PCI Database, UKBizDB, Menu Kuliner, Sharing RPP