Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

OGRVRTLayer layer level SrcRegion clip not implemented #11519

Closed
tcommandeur opened this issue Dec 19, 2024 · 3 comments · Fixed by #11543
Closed

OGRVRTLayer layer level SrcRegion clip not implemented #11519

tcommandeur opened this issue Dec 19, 2024 · 3 comments · Fixed by #11543
Assignees

Comments

@tcommandeur
Copy link

What is the bug?

According to the documentation of VRT the SrcRegion on OGRVRTLayer should have a clip attribute.

SrcRegion (optional) : This element is used to define an initial spatial filter for the source features. This spatial filter will be combined with any spatial filter explicitly set on the VRT layer with the SetSpatialFilter() method. The value of the element must be a valid WKT string defining a polygon. An optional clip attribute can be set to "TRUE" to clip the geometries to the source region, otherwise the source geometries are not modified.

For the GeometryField the SrcRegion clip="true" is working but looking at the source code its not implemented for OGRVRTLayer.

Steps to reproduce the issue

Not working VRT for SrcRegion clip on VRTLayer

<OGRVRTDataSource>
    <OGRVRTLayer name="pand">
        <SrcDataSource>bag-light.gpkg</SrcDataSource>
        <SrcLayer>pand</SrcLayer>
        <LayerSRS>EPSG:28992</LayerSRS>
        <SrcRegion clip="true">POLYGON((120000 435000, 155000 435000, 155000 470000, 120000 470000, 120000 435000))</SrcRegion>
    </OGRVRTLayer>
</OGRVRTDataSource>

Working VRT for GeometryField

<OGRVRTDataSource>
    <OGRVRTLayer name="pand">
        <SrcDataSource>bag-light.gpkg</SrcDataSource>
        <SrcLayer>pand</SrcLayer>
        <LayerSRS>EPSG:28992</LayerSRS>
        <GeometryField>
            <!-- Clip is only implemented at GeometryField level and not at OGRVRTLayer level -->
            <SrcRegion clip="true">POLYGON((120000 435000, 155000 435000, 155000 470000, 120000 470000, 120000 435000))</SrcRegion>
        </GeometryField>
    </OGRVRTLayer>
</OGRVRTDataSource>

Versions and provenance

GDAL 3.6, 3.9.3, 3.10.0 self-built from binaries.

Additional context

No response

@jratike80
Copy link
Collaborator

jratike80 commented Dec 19, 2024

The documentation has this DataSource level example https://github.com/OSGeo/gdal/blob/42ca02ce9397ec3f37dcc46eace97011f1aa0d53/doc/source/drivers/vector/vrt.rst#example-transparent-spatial-filtering. Does it work?

<OGRVRTDataSource>
    <OGRVRTLayer name="source">
        <SrcDataSource>source.shp</SrcDataSource>
        <SrcRegion clip="true">POLYGON((0 40,10 40,10 50,0 50,0 40))</SrcRegion>
    </OGRVRTLayer>
</OGRVRTDataSource>

@jratike80
Copy link
Collaborator

I made a test with a geopackage, and SrcRegion really does work inside GeometryField, but outside that ogrinfo -al -so gives an error:

Feature Count: 152770
ERROR 1: Invalid geometry field index : -1
ERROR 1: Invalid geometry field index : -1


<OGRVRTDataSource>
  <OGRVRTLayer name="jarvi">
    <SrcDataSource relativeToVRT="1" shared="1">mtkmaasto.gpkg</SrcDataSource>
    <SrcLayer>jarvi</SrcLayer>
    <GeometryField>
    <SrcRegion clip="true">POLYGON (( 436151 6926630, 436151 6946458, 464022 6946458, 464022 6926630, 436151 6926630 ))</SrcRegion>
    </geometryField>
    ...

@tcommandeur
Copy link
Author

tcommandeur commented Dec 23, 2024

I clipped the geopackage and made a clip region that overlaps with the testdata.

Minimal geopackage with sample data:
bag-light.zip

Tested VRT:

<OGRVRTDataSource>
    <OGRVRTLayer name="pand">
        <SrcDataSource>/srv/datasets/bag-v2/2024-12/bag-light.gpkg</SrcDataSource>
        <SrcLayer>pand</SrcLayer>
        <GeometryField>
            <!-- Clip works only at GeometryField level and not at OGRVRTLayer level -->
            <SrcRegion clip="true">POLYGON((124115 435000, 155000 435000, 155000 470025, 124115 470025, 124115 435000))</SrcRegion>
        </GeometryField>
    </OGRVRTLayer>
    <OGRVRTLayer name="pand_clip_not_working">
        <SrcDataSource>/srv/datasets/bag-v2/2024-12/bag-light.gpkg</SrcDataSource>
        <SrcLayer>pand</SrcLayer>
        <SrcRegion clip="true">POLYGON((124115 435000, 155000 435000, 155000 470025, 124115 470025, 124115 435000))</SrcRegion>
    </OGRVRTLayer>
</OGRVRTDataSource>

Result shows that the clip on layer level is not applied
image

@rouault rouault self-assigned this Dec 24, 2024
boxerab pushed a commit to GrokImageCompression/gdal that referenced this issue Jan 7, 2025
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

Successfully merging a pull request may close this issue.

3 participants