Inverse spatial filtering


I am using spatial layers to intersect the point data that I would like to keep:

→ select({orig_geom: exposure.the_geom, exposure: layer_intersection(exposure, bookmark(‘WGN_census’), {SA12018_V1: ‘SA12018_V1’, REGC2023_2: ‘REGC2023_2’, REGC2023_3: ‘REGC2023_3’}, false)})
→ unnest(exposure, ‘segmentID’)
→ select({{exposure.*, segmentID} as exposure, measure(exposure.the_geom) / measure(orig_geom) as scale_factor})

However, I would also like to inversely filter from another spatial layer - removing the data that falls within a different area block. I wonder how this would vary from the pipeline above?

Any advice greatly appreciated.


Hi Abby

It sounds like you need to filter your input data first. Using riskscape wizard is often a useful first step.

To get something close to what you are after I ran the wizard with the getting-started tutorial data given these answers:

  • configure exposure layer for:
    • Buildings
    • Add geoprocessing to:
      • filter
      • by-feature-in-layer
        • Samoa constituencies
        • NAME_1 = A’ana

I then exited the wizard saving that as the following pipeline. (note I added the last line)

input(relation: 'Building SE Upolu (exposure-layer)', name: 'exposure') as exposures_input
 -> select({*}) as "geoprocess_exposure"
 -> join(on: true) as exposure_filter_layer_join
 -> filter(length(sample(exposure, coverage: exposure_filter_coverage)) > 0)
 -> select({exposure}) as exposures
input(relation: 'Samoa constituencies (area-layer)') as filter_layer_exposure
 -> filter(NAME_1 = 'A\'ana')
 -> group({to_coverage(*) as exposure_filter_coverage})
 -> exposure_filter_layer_join.rhs

exposures -> <your_pipeline_code>

This pipeline will filter the exposures to only include the ones that intersect with the area layer
which is the opposite to what you want. To exclude that area change the filter on line 4 to be
= 0 (no intersections) instead of > 0.

You could amend that pipeline snippet to use your own data, or run the wizard to build it for you.

I hope this helps


1 Like

Hi Glenn

It worked a treat - Thank you!

As an extension to this - I was hoping also to join two polygon layers that do not share any features (empty polygons) nor do they share any coverage - they are the same crs and puzzle piece together.

I have been trying to join them following a similar pipeline to that of joining multi-hazards via the wizard but am having no luck! My point data will then join to the new area layer (combination of two polygon shpfiles) - so the geoprocessed output will be in polygon form - rather than points.

Thank you again for your time!

Hi Abby,

It sounds like you want to use the union step, but this isn’t available as an option in the wizard. To make use of this you’ll need to follow a similar process as Glenn mentioned before and edit the generated pipeline code.

Have a read of the docs and then see if you can make sense of my example below. Assuming your layers are area_layers, area1 and area2, you can do something like:

-> union() as all_polys
-> all_polys

# this is your new area layer - you can now join it up to the
# exposure filter as before
-> group(to_coverage(*) as exposure_filter_coverage)
-> exposure_filter_layer_join.rhs

Note that the two area layers will need to have the same shape, that is the attributes need to match across both layers, or you’ll get a weird mix of attributes from both tables, where some will be set in some tuples (rows), but not in others.