Bug report #9543

VRT vector file don't recognize relative path

Added by Regis Haubourg almost 11 years ago. Updated over 10 years ago.

Status:Closed
Priority:Normal
Assignee:-
Category:Data Provider/OGR
Affected QGIS version:2.0.1 Regression?:No
Operating System: Easy fix?:No
Pull Request or Patch supplied:No Resolution:up/downstream
Crashes QGIS or corrupts data:No Copied to github as #:18130

Description

Hi, I build here a vrt on a simple csv file, and QGIS opens it correctly only if I put a absolute file in datasource. Ogrinfo works correctly when using relative paths.. So it is probably related to QGIS method to call GDAL vrt.

<OGRVRTDataSource>
    <OGRVRTLayer name="cotieres">

        <SrcDataSource>V:\\temp_user\\cwbody.csv</SrcDataSource> -- OK
        <SrcDataSource>cwbody.csv</SrcDataSource> -- NOT WORKING

        <SrcSQL>select "EU_CD", CAST("LAT" as numeric(8,5)) AS "LAT", CAST("LON" as numeric(8,5)) AS "LON" from cwbody </SrcSQL> 
        <GeometryType>wkbPoint</GeometryType> 
        <LayerSRS>EPSG:4326</LayerSRS>
        <GeometryField encoding="PointFromColumns" x="LON" y="LAT"/> 
    </OGRVRTLayer>
</OGRVRTDataSource>

History

#1 Updated by Etienne Tourigny almost 11 years ago

I assume the .csv and .vrt file are in the same directory?

Perhaps you are missing the relativeToVRT tag in SrcDataSource?

[1] lists it as optional, but it might be necessary in this case to work in qgis?

[1] http://www.gdal.org/ogr/drv_vrt.html

#2 Updated by Etienne Tourigny almost 11 years ago

  • Status changed from Open to Feedback

Works for me using both relative and absolute path in linux using 2.0.1 and (mostly) recent master, with this .csv file

LAT,LON
0.1,0.2
0.4,0.8

what is the content of your csv file?

#3 Updated by Etienne Tourigny almost 11 years ago

  • Operating System set to windows
  • Status changed from Feedback to Open

I confirm the issue on windows with qgis-dev, using osgeo4w 32 bit installer. ogrinfo can read both datasets, but qgis does not identify the vrt file with relative path

#4 Updated by Regis Haubourg almost 11 years ago

Hi, explicitly setting datasource tag to <SrcDataSource relativeToVRT="1">cwbody.csv</SrcDataSource> does the trick.
Strange behaviour from a user point of view. If behaviour differs between linux and windows, this could be due to bad handling of UNC path in Windows?
Cheers.

#5 Updated by Etienne Tourigny almost 11 years ago

Perhaps the difference is that the current directory is not set to that of the .vrt file in windows, whereas it is in linux.

Sorry I cannot help implementing a fix, someone why works with windows builds should do that.

Anyway, there is a simple workaround.

#6 Updated by Etienne Tourigny almost 11 years ago

  • Operating System deleted (windows)

actually, I was wrong, issue also exists in Linux. I was running qgis from the directory where the .vrt and .csv files reside. If you open from other dir or application launcher, the problem manifests.

On a side note, when you use gdal_translate to create a vrt file, relativeToVRT is set to "1" so I guess the same should be applied to ogr vrt files.

So I'm not sure this should be fixed, but rather relativeToVRT should be set in your file.

#7 Updated by Jürgen Fischer over 10 years ago

  • Category set to Data Provider/OGR
  • Resolution set to up/downstream

#8 Updated by Regis Haubourg over 10 years ago

  • Status changed from Open to Closed

Workaround is sufficient.

Also available in: Atom PDF