Skip to content

hotspot_clip() wrongly requires a point dataset #65

@mpjashby

Description

@mpjashby

Describe the bug
hotspot_clip() should be able to be used both before a dataset is transformed with one of the hotspot_*() family of functions (in which case the data argument will be a point dataset) or after (in which case the data argument should be a polygon dataset). At the moment it wrongly expects a point dataset only, so the second use-case fails.

To Reproduce

library(sfhotspot)

# This works as expected
hotspot_clip(memphis_robberies_jan, memphis_precincts)
#> Removed 0 rows (0.0% of original rows) from `data`
#> Simple feature collection with 206 features and 3 fields
#> Geometry type: POINT
#> Dimension:     XY
#> Bounding box:  xmin: -90.125 ymin: 34.996 xmax: -89.774 ymax: 35.252
#> Geodetic CRS:  WGS 84
#> # A tibble: 206 × 4
#>         uid offense_type     date                        geometry
#>  *    <int> <fct>            <dttm>                   <POINT [°]>
#>  1 15213800 personal robbery 2019-01-01 01:30:00 (-89.942 35.149)
#>  2 15214030 personal robbery 2019-01-01 20:00:00  (-89.86 35.059)
#>  3 15214042 personal robbery 2019-01-01 21:58:00 (-89.929 35.058)
#>  4 15214050 personal robbery 2019-01-01 22:30:00 (-90.018 35.201)
#>  5 15214118 personal robbery 2019-01-02 09:38:00   (-89.96 35.14)
#>  6 15214242 personal robbery 2019-01-02 18:50:00 (-89.953 35.159)
#>  7 15214290 personal robbery 2019-01-02 23:30:00  (-89.95 35.026)
#>  8 15214295 personal robbery 2019-01-03 00:00:00 (-89.932 35.076)
#>  9 15214319 personal robbery 2019-01-03 03:00:00 (-90.021 35.033)
#> 10 15214428 personal robbery 2019-01-03 14:45:00 (-90.032 35.165)
#> # ℹ 196 more rows

# This should, but does not
memphis_robberies_jan |> 
  hotspot_count() |> 
  hotspot_clip(memphis_precincts)
#> Cell size set to 0.00512 degrees automatically
#> Error in `hotspot_clip()`:
#> ! `data` must be an SF object with POINT geometry.
#> ✖ All rows have POLYGON geometry.

Created on 2025-07-30 with reprex v2.1.1

Metadata

Metadata

Assignees

Labels

bugSomething isn't working

Projects

No projects

Relationships

None yet

Development

No branches or pull requests

Issue actions