<div dir="ltr"><div>Hi,</div><div><br></div><div>I have two GDAL questions that are Mapserver adjacent (or perhaps vice-versa?).   </div><div><br></div><div>1.  Does OGRVRTDataSource allow Python code similar to raster VRT Python Pixel Functions?</div><div>2.  Is there a reasonable way to pass custom arguments to a VRT?</div><div><br></div><div></div><div>I have a VRT that executes some SQL:</div><div><br></div><div>    <!-- file.vrt --></div>    <OGRVRTDataSource><br>      <OGRVRTLayer name="0"><br>        <SrcDataSource>PG:host=db user=me dbname=datastore password=abc</SrcDataSource><br>        <SrcSQL><br>          SELECT some_table.location, <a href="http://some_table.id">some_table.id</a>, some_table.geom FROM some_table<br>        </SrcSQL><br>      </OGRVRTLayer><br>    </OGRVRTDataSource><div><br></div><div>Is there a reasonable way to pass some argument to filter the VRT?  For example, a condition like `WHERE <a href="http://some_table.id">some_table.id</a> = 123`.  Imagine the query has a very large number of records. I dont want to process the filter "client side":  Ideally the condition gets executed in SQL before OGR gets any results.  I am aware of ogr2ogr's -sql statement <a href="https://gdal.org/en/stable/programs/ogr2ogr.html#cmdoption-ogr2ogr-sql">https://gdal.org/en/stable/programs/ogr2ogr.html#cmdoption-ogr2ogr-sql</a></div><div><br></div><div>Ultimately this will happen via MapServer, which is referencing the VRT layer.  I would like the client to pass a QUERYSTRING argument `foo_id=123` to perform a filter on the data in the VRT.  Usually I do this via MapServer Runtime substitution.  This works if I embed the contents of file.vrt directly in my Mapfile </div><div><br></div><div>    LAYER<br>        NAME my_layer<br>        TYPE POLYGON<br>        EXTENT -180 -90 180 90<br>        PROJECTION<br>            "init=epsg:4326"<br>        END<br>        CONNECTIONTYPE OGR<br>        TILEITEM 'location'<br>        TILEINDEX "<OGRVRTDataSource>...WHERE <a href="http://some_table.id">some_table.id</a> = %foo_id%</SrcSQL></OGRVRTLayer></OGRVRTDataSource>"</div><div><br></div><div>        VALIDATION<br>            'foo_id' "^[0-9]+$"<br>            'default_foo_id' "-1"<br>        END</div><div>    END</div><div><br></div><div>However, my actual OGRVRTDataSource file is large.  If I inline a large VRT Mapserver complains "msBuildPath(): Unable to access file. Path is too long.  Check server logs.".  I could use a Mapserver FILTER <a href="https://mapserver.org/mapfile/layer.html#filter">https://mapserver.org/mapfile/layer.html#filter</a>, but I think that occurs AFTER the VRT is evaluated. . . so if there are millions of rows, that data gets filtered by the client (Mapserver) and not by SQL, so there's a lot of data moving around and very slow performance.</div><div><br></div><div>Thanks!</div><div>Pete</div></div>