Skip to main content
This gem runs in .

Overview

Use the SpatialMatch gem to find relationships between geometries from two different datasets. Common use cases include:
  • Finding which stores are located within specific delivery zones
  • Identifying roads that intersect with flood zones
  • Matching customer locations to their nearest service areas
The gem uses spatial joins to compare geometries and returns only the pairs that have the spatial relationship you specify, such as shapes overlapping or shapes touching. It works with points, lines, and polygons in Well-Known Text (WKT) format.
The gem has a corresponding interactive gem example. See Interactive gem examples to learn how to run sample pipelines for this and other gems.

Prerequisites

  • Add ProphecyDatabricksSqlSpatial version 0.0.3 or higher to your project.

Input and Output

The SpatialMatch gem accepts the following inputs and output. You can use the same source for both in0 and in1 if you want to match geometries from the same dataset (self-join).
Use the following gems to create correctly formatted geometries in a dataset:

Parameters

Configure the SpatialMatch gem using the following parameters.

Match types

Review the following to understand the criteria to satisfy different match types. The SpatialMatch gem returns a row for each match condition that is met.

Match types diagram

The following diagram includes visualizations for each match type. Match types diagram

Example: Find stores within delivery zones

Assume you have two datasets:
  • store_locations contains store locations as points.
  • delivery_zones contains delivery zones as polygons.
To find which delivery zones correspond to each store:
  1. Add a SpatialMatch gem to your pipeline canvas.
  2. Attach store_locations to the in0 port of the gem.
  3. Attach delivery_zones to the in1 port of the gem.
  4. Open the gem configuration interface.
  5. For the Source field, select the store_location column from the store_locations table.
  6. For the Target field, select the zone_polygon column from the delivery_zones table.
  7. Under Select Match Type, select Source Within Target.
  8. Save and run the gem.

Result

The SpatialMatch gem will return only the pairs of geometries that satisfy the selected match type. As a result:
  • Downtown Electronics matches the MANHATTAN_SOUTH zone.
  • Queens Pharmacy matches the QUEENS_CENTRAL zone.
  • Upper East Side Boutique matches the MANHATTAN_NORTH zone.
  • Midtown Cafe does not match any zone. This means that it is not in any delivery zone.