Skip to content

Commit

Permalink
fix presence of GeometryCollection in nyc_historic_buildings
Browse files Browse the repository at this point in the history
we were doing `ST_UNION` on a geometry with mixed types due to the `COALESCE`. this generated GeometryCollection values which aren't handled well by any subsequent queries or export files.

This also led to use buffering the lots and points of a multi-point landmark when only some points joined to a lot. Now we don't use the extra points if there are any lots.
  • Loading branch information
damonmcc committed May 2, 2024
1 parent e03ad85 commit 0fbc1ab
Show file tree
Hide file tree
Showing 3 changed files with 32 additions and 14 deletions.
2 changes: 1 addition & 1 deletion products/green_fast_track/bash/export.sh
Original file line number Diff line number Diff line change
Expand Up @@ -87,7 +87,7 @@ mkdir -p output && (
export_source sources__natural_resources_buffer

# Historic
export_source sources__nyc_historic_buildings_points POINT
export_source sources__nyc_historic_buildings_points MULTIPOINT
export_source sources__nyc_historic_buildings_lots
export_source sources__nyc_historic_buildings_buffers
export_source sources__nyc_historic_districts
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -19,40 +19,57 @@ landmarks_with_pluto AS (
SELECT
variable_type,
variable_id,
raw_geom AS point_geom,
pluto.bbl,
pluto.geom,
COALESCE(pluto.geom, lpc_landmarks.raw_geom) AS coalesced_geom
pluto.geom AS lot_geom
FROM lpc_landmarks
-- If, for example, there's a lamppost in a park, we don't want to use the polygon for the entire park.
LEFT JOIN
pluto
ON ST_CONTAINS(pluto.geom, lpc_landmarks.raw_geom) AND variable_id != 'Historic Street Lampposts'
),

-- There are a few different cases for deduping.
-- There are landmarks that share a name, e.g. "Historic Lampposts" that won't match to a PLUTO bbl,
-- and should be combined into one geometry, because they lack a unique name for a variable_id.
-- Otherwise we should group by the PLUTO bbl, joining together the names of the individual landmarks
-- when there are multiple per BBL. e.g. The Brooklyn Navy Yard has two buildings within that are both
-- landmarks.
-- There are a few different cases for deduping:
-- A. landmarks that share a name, e.g. "Historic Lampposts" that should't match to a PLUTO bbl,
-- so should be combined into one geometry, because they lack a unique name for a variable_id
-- B. landmarks that share a name and all are not contained in any lots
-- so should use the point(s) to buffer
-- C. landmarks that share a name and all are contained in at least one lot
-- so should use the lot(s) to buffer
-- D. landmarks that share a name and some are contained in at least one lot
-- so should use only the lot(s) to buffer, not both the point(s) and lot(s)
grouped_landmarks AS (
SELECT
variable_type,
variable_id,
STRING_AGG(DISTINCT bbl, ', ') AS bbls,
ST_UNION(coalesced_geom) AS geom
ST_MULTI(ST_UNION(point_geom)) AS point_geom,
ST_MULTI(ST_UNION(lot_geom)) AS lot_geom
FROM landmarks_with_pluto
GROUP BY variable_type, variable_id
),

buffered_landmarks AS (
resolved_landmarks AS (
SELECT
variable_type,
variable_id,
bbls,
ST_MULTI(geom) AS raw_geom,
ST_BUFFER(geom, 90) AS buffer
point_geom,
lot_geom,
COALESCE(lot_geom, point_geom) AS raw_geom
FROM grouped_landmarks
),

buffered_landmarks AS (
SELECT
variable_type,
variable_id,
bbls,
point_geom,
lot_geom,
raw_geom,
ST_BUFFER(raw_geom, 90) AS buffer
FROM resolved_landmarks
)

SELECT * FROM buffered_landmarks
Original file line number Diff line number Diff line change
Expand Up @@ -2,4 +2,5 @@ SELECT
variable_type,
variable_id,
raw_geom
FROM {{ ref('stg__lpc_landmarks') }}
FROM {{ ref('int_buffers__lpc_landmarks') }}
WHERE ST_GEOMETRYTYPE(raw_geom) = 'ST_MultiPoint'

0 comments on commit 0fbc1ab

Please sign in to comment.