Wild and Crazy Polygons from a Chull Outline in a leaflet Map: Is it a scripting problem or does it have meaning?

Dear All,

My question is more about interpreting the output of a leaflet map rather than producing a leaflet map. I thought those of you who have a lot of mapping and map interpretation experience would have insight to share. Thanks in advance.

I'm trying to determine if the wild and crazy but pretty shapes of the southeastern red and purple non-polygons mean something about how the points are distributed geographically as opposed to being a problem in the code. (Per the code examples below, I deliberately have not included a reproducible example because I'm not having any issues other than the shape of these two polygons.)


I have created an interactive leaflet map that includes polygons. So far, so good.

Most of the polygons are polygons. Please refer to the yellow, green and northern purple polygons on the map.

However, one polygon (two iterations - one red, one purple - of the same polygon are shown) is -- well -- not a polygon. Please refer to the southeastern purple and red "polygons" on the map.

I've checked the code and I can't find a problem in the script or substantive differences between the script for the "polygon" polygons (yellow, green and northern purple) and the "non-polygon" polygons (southeastern red and purple), so I think there's a possibility that the shapes might mean something about the geographical distribution of the points.


The code that produced the yellow, green and northern purple polygons (this is not a reproducible example):

# Yellow polygon
# filter to specific bank					
arvest <- sch %>%
  dplyr::filter(lender == "ARVEST BANK")
# filter to specific coordinates
arvest_chull <- arvest %>%
  dplyr::filter(long < -91.29 &
                long > -94.65 &
                lat < 37.85 &
                lat > 36.5)
# chull				
arvest_outline <- arvest_chull[chull(arvest_chull$long, arvest_chull$lat),]	

# green polygon
# filter to specific bank					
centralbank <- sch %>%
  dplyr::filter(lender == "CENTRAL BANK") 
# chull
centralbank_outline <- centralbank[chull(centralbank$long, centralbank$lat),]

# northern purple polygon
# filter to specific bank	
firstatecommbank <- sch %>%
  dplyr::filter(lender == "1ST STATE COMMUNITY BANK")
# filter to specific coordinates
firstatecommbank_como <- firstatecommbank %>%
  dplyr::filter(firstatecommbank$lat < 39.92 & 
                firstatecommbank$lat > 39.0
                )
# chull	
firstatecommbank_como_outline <- 
  firstatecommbank_como[chull(firstatecommbank_como$long,                                                                           firstatecommbank_como$lat),]


The "original" non-polygon was produced using this script:

# filter to specific bank
firstatecommbank <- sch %>%
  dplyr::filter(lender == "1ST STATE COMMUNITY BANK")
# filter to specific coordinates
firstatecommbank_se_raw <- firstatecommbank %>%
  dplyr::filter(firstatecommbank$lat  < 38.6 &
                firstatecommbank$lat  > 36.2 &
                firstatecommbank$long  < -89.5 &
                firstatecommbank$long  > -93  
                )
# chull
firstatecommbank_se_raw_outline <- 
  firstatecommbank_se_raw[chull(firstatecommbank_se_raw$long,
                            firstatecommbank_se_raw$lat),]
	

It's pretty but YOWSER! (See below)


Consequently, I eliminated duplicate observations and sorted the data to produce a different "non-polygon" shape. (See below.)

							
# filter to specific bank
firstatecommbank <- sch %>%
  dplyr::filter(lender == "1ST STATE COMMUNITY BANK")
# filter to specific coordinates
firstatecommbank_se <- firstatecommbank %>%
  dplyr::filter(firstatecommbank$lat  < 38.6 &
                firstatecommbank$lat  > 36.2 &
                firstatecommbank$long  < -89.5 &
                firstatecommbank$long  > -93  
                )


# eliminate duplicate observations and arrange
# without these steps the shape was crazier than the raw shape
firstatecommbank_se <- distinct(firstatecommbank_se, lender, equip_descript, lat, long)
firstatecommbank_se <- arrange(firstatecommbank_se, -lat, long)


# chull
firstatecommbank_se_outline <- 
  firstatecommbank_se[chull(firstatecommbank_se$long,
                            firstatecommbank_se$lat),]


So, those of you with greater geo-location experience that me, what do you think?

Do these wild and crazy but pretty non-polygons mean something about how the points are distributed geographically OR is there a scripting problem that I should be looking for?

Thanks in advance.

Linda

Linda,

I believe the polygons are legit - in the strictly technical sense that the enclose a definite area. They do not quite have a business meaning though.

If by "chull" you meant a convex hull I believe you will be better served by sf::st_convex_hull(); you might need to unite your data to multipoints first (i.e. your_data %>% st_union() %>% st_convex_hull()).

Depending on your application a concave hull might be more appropriate, in which case concaveman::concaveman() has served me well.

J.

2 Likes

Thanks! I wasn't aware of this approach. I'll try it. Thanks for educating me.

Linda

This topic was automatically closed 21 days after the last reply. New replies are no longer allowed.