I'm having trouble with one SQL query I'm using on a shapefile in my VRT layer. My goal is to import several shapefiles to a PDF using OGR, GDAL and Python.
My shapefile has follwing structure: shapefile1.shp: {FID: integer, Type: string, Name: string, Show: integer ...}
. Nothing out of the usual, no spaces, no underscores, no points.
If I call ogrinfo
on a OSGeo Shell, the shapefile behaves nominally and all attributes are shown, i.e:
> ogrinfo -sql "SELECT Type AS foo FROM shapefile1" shapefile1.shp
Layer name: shapefile1
Geometry: Point
Feature Count: 19
[...]
foo: String (150.0)
OGRFeature(shapefile1):1
foo (String) = correctString
POINT (coordinates)
[...]
But if I use the same SQL query on my VRT file, I get following error:
ERROR 1: Unrecognized field name Type.
ERROR 1: SQL statement failed, or returned no layer result:
SELECT Type AS foo FROM shapefile1
ERROR 1: Invalid geometry field index : 0
This is my VRT file:
<OGRVRTDataSource>
<OGRVRTLayer name="points">
<SrcDataSource relativeToVRT="1">shapefile1.shp</SrcDataSource>
<SrcSQL>SELECT Type AS foo FROM shapefile1</SrcSQL>
<LayerSRS>WGS84</LayerSRS>
<GeometryType>wkbPoint</GeometryType>
</OGRVRTLayer>
</OGRVRTDataSource>
First I thought that OGR doens't like attribute names as "FID", "Type", "Name" and so on. But even if i change the SQL query to SELECT Show AS foo FROM shapefile1
the error keeps appearing. Even on an attribute called Azimuth
, which should definetly not be a problem.
Any ideas on what I might be doing wrong?
SELECT "Type" AS foo FROM shapefile1
throws the same error. I even tried with up to 4 quote marks on each side.