Trouble with SF and spatial joining - reprex and datapasta inside.

Good evening everyone, i am attempting at spatial joining but cannot seem to get it to work apparently it is erroring out before my actual spatial join. See below, any help appreciated.

## reprex and datapasta

library(sf)
#> Linking to GEOS 3.6.1, GDAL 2.2.3, PROJ 4.9.3
library(tidyverse)


## head of data that shows all bus pass up points
latlong_dp <- tibble::tribble(
  ~latitude,       ~longitude,
  49.902525502534, -97.168133009356,
  49.892922865173, -97.139020101836,
  49.896572778324, -97.152386734568,
  49.911673416378, -97.132615330547,
  49.888762777292, -97.157892009947,
  49.888958144329, -97.135232212037
)

## head of polygon data of the city of winnipeg
wpg_dp <- data.frame(
  geometry = c("list(c(-97.101068054847, -97.101057633481, -97.101017854888,
                 -97.100931449308, -97.100776314372, -97.100590517773,
                 -97.094109289129, -97.093918257773, -97.093940217125, -97.093786970232,
                 -97.093697911443, -97.093686602955, -97.09366465814,
                 -97.081369804699, -97.081080060473, -97.081075493802, -97.080791922232,
                 -97.088129972782, -97.088519375967, -97.094945805384,
                 -97.095258438012, -97.098657907868, -97.099208705274, -97.101364500617,
                 -97.102993217405, -97.102002344004, -97.10176613496,
                 -97.101460136755, -97.101257540021, -97.101119462733, -97.101068054847,
                 49.904738664792, 49.905126025972, 49.905371946913, 49.905577498982,
                 49.905799072517, 49.90597997387, 49.911108615638, 49.911045228152,
                 49.911027855569, 49.910977014823, 49.910947468794,
                 49.910943716666, 49.910961085747, 49.906884119339, 49.906784881086,
                 49.906783365386, 49.906689245819, 49.905498698569, 49.905426185365,
                 49.904392289705, 49.904341988246, 49.903789560247, 49.903700018025,
                 49.903349435214, 49.903084546396, 49.903593807876,
                 49.903721309945, 49.903950880562, 49.90418431683, 49.904456236955,
                 49.904738664792))", "list(c(-97.213977751417, -97.21397609447,
                 -97.213967417106, -97.213548480417, -97.20814382323, -97.199463300795,
                 -97.195892334197, -97.194073994454, -97.193147226559,
                 -97.192973912857, -97.192711129042, -97.192275027527, -97.182523426765,
                 -97.182919126657, -97.185490571405, -97.188009274445, -97.213977751417,
                 49.768105484827, 49.76865359624, 49.777508645519,
                 49.777651836706, 49.77949894561, 49.782464793264, 49.783684577947,
                 49.784305627404, 49.78462214545, 49.784681335708, 49.784771081681,
                 49.784920015316, 49.768543454196, 49.768464403909, 49.768230153332,
                 49.768178937009, 49.768105484827))", "list(c(-97.180379193987,
                 -97.180870170973, -97.180875672292, -97.18056019535, -97.17969445916,
                 -97.179612573054, -97.179603237629, -97.179521576676,
                 -97.179521684245, -97.179307283435, -97.176176088637, -97.174499581448,
                 -97.1741928016, -97.173827693662, -97.173754811339,
                 -97.172465571053, -97.170800461447, -97.170753327914, -97.170553334414,
                 -97.170524820103, -97.170516949094, -97.170321560583,
                 -97.170192166459, -97.170174445869, -97.169988938463, -97.169957570375,
                 -97.169754346176, -97.169625267158, -97.168457662035, -97.168455801556,
                 -97.168407060268, -97.168208358356, -97.168177370166,
                 -97.167981126092, -97.167882640145, -97.167692644329, -97.16768362385,
                 -97.167165968998, -97.167146414279, -97.165844465523,
                 -97.164831887892, -97.164816865457, -97.164800422439, -97.164547398537,
                 -97.173555916921, -97.176152951271, -97.177342519398,
                 -97.180379193987, 49.829793475066, 49.831924798548, 49.832843159401,
                 49.834055728728, 49.83629125586, 49.837134254555, 49.842472356415,
                 49.84316063651, 49.844994065997, 49.846879827529, 49.846846019999,
                 49.846845180341, 49.846860695378, 49.84691078752, 49.846787319538,
                 49.845188552109, 49.845751725592, 49.845693449483,
                 49.845445345206, 49.845405628013, 49.845395919515, 49.845153862935,
                 49.844993559865, 49.844971606455, 49.844741786574, 49.844702925472,
                 49.844451151807, 49.844290742407, 49.842838792292, 49.84283632915,
                 49.842753869164, 49.842511281661, 49.842472298134,
                 49.842229895862, 49.842108579517, 49.841873367746, 49.841876422284,
                 49.841234293859, 49.841209989323, 49.839590513514, 49.838341955465,
                 49.838323414376, 49.838303125531, 49.837990859062, 49.834910340517,
                 49.833593539714, 49.832671223156, 49.829793475066))",
               "list(c(-97.082398341883, -97.082589237551, -97.104020325521,
                 -97.099114261393, -97.098910065974, -97.091411768776, -97.09112943563,
                 -97.091004891134, -97.086525650834, -97.087082382071, -97.086957847199,
                 -97.086714378687, -97.086618401358, -97.086448539764,
                 -97.086244706648, -97.086033324768, -97.085825718172, -97.08558193547,
                 -97.085448346275, -97.085336644888, -97.085110222477,
                 -97.084883802209, -97.084657381228, -97.084430960997, -97.084204542837,
                 -97.083978124035, -97.083751705912, -97.083525289932,
                 -97.083298873239, -97.083072457296, -97.082846043424, -97.082615478458,
                 -97.082385291055, -97.082158877996, -97.081932467008, -97.081706055378,
                 -97.081479644427, -97.081253235618, -97.081026826096,
                 -97.080800417325, -97.080574010625, -97.080347603283, -97.08012119662,
                 -97.079894792099, -97.079668386866, -97.079441982382,
                 -97.07921557997, -97.078989176881, -97.078913715234, -97.078706196346,
                 -97.078498679487, -97.078291161836, -97.078083644785,
                 -97.077876128334, -97.077668613877, -97.077461098627, -97.077253583978,
                 -97.076933259347, -97.076679293845, -97.076485747084, -97.081389842395,
                 -97.082398341883, 49.920370640774, 49.920434175307,
                 49.927580021395, 49.932773159981, 49.932927054316, 49.93043792352,
                 49.930791566848, 49.93075017603, 49.929261389105, 49.928564918503,
                 49.928523522219, 49.928442591613, 49.928410687876, 49.928354224041,
                 49.928286467204, 49.928216200482, 49.928147188154,
                 49.928066148601, 49.928021740758, 49.927984607792, 49.92790933909,
                 49.927834069077, 49.927758799505, 49.9276835286, 49.927608258181,
                 49.927532986406, 49.927457715094, 49.927382442472, 49.927307170291,
                 49.927231896776, 49.927156623748, 49.927079970149, 49.927003441067,
                 49.926928165797, 49.926852891014, 49.926777614875, 49.9267023392,
                 49.926627062214, 49.926551785669, 49.926476507791,
                 49.926401230399, 49.926325951651, 49.926250673367, 49.926175393772,
                 49.926100114619, 49.926024834131, 49.925949554131, 49.925874273673,
                 49.925849183786, 49.925780189275, 49.925711193522, 49.925642197382,
                 49.925573200876, 49.925504204004, 49.925435206791,
                 49.925366209189, 49.925297211222, 49.925190703442, 49.925106252512,
                 49.925041892006, 49.921168011331, 49.920370640774))",
               "list(c(-97.326465816713, -97.326256067928, -97.316727232583, -97.310786408673,
                 -97.310804642254, -97.310925425027, -97.310940729282,
                 -97.310942565372, -97.3109598016, -97.310978529439, -97.3109890111,
                 -97.311006148605, -97.311014492904, -97.311023039989, -97.311040203453,
                 -97.311050455734, -97.311056823811, -97.311074259184,
                 -97.311086417993, -97.31109142363, -97.311108314374, -97.31112238104,
                 -97.311124660609, -97.311136002591, -97.311141551091,
                 -97.311158170633, -97.311171963415, -97.311175605181, -97.311191678741,
                 -97.311207923637, -97.311208842248, -97.311224914168, -97.311241259515,
                 -97.311243883256, -97.311258422625, -97.311275312054,
                 -97.311279842241, -97.311291929167, -97.3113096362, -97.311315800654,
                 -97.311326525194, -97.311343550854, -97.311351758465,
                 -97.311370792483, -97.311387717064, -97.311388498833, -97.311422039411,
                 -97.311436890988, -97.311475314196, -97.311497758512,
                 -97.311508331593, -97.311523786171, -97.311541480163, -97.311544311411,
                 -97.311557813364, -97.311575236352, -97.311580292049, -97.31159211352,
                 -97.311608446366, -97.311616270662, -97.311625051165,
                 -97.31164220011, -97.311652248671, -97.311658532542, -97.311675409086,
                 -97.311688226077, -97.311693101827, -97.311709945759,
                 -97.311724204272, -97.311731811088, -97.311760180472, -97.311765353083,
                 -97.311799527504, -97.311804842439, -97.311808642617,
                 -97.311845723273, -97.311867961363, -97.311906206881, -97.311936015526,
                 -97.311943258642, -97.311984748376, -97.311989415047, -97.31279361037,
                 -97.312922793971, -97.313502621314, -97.315250714374,
                 -97.315959231887, -97.316844887505, -97.317705049749, -97.318634002148,
                 -97.319510154727, -97.320372833848, -97.321076202957,
                 -97.321629325558, -97.322130924238, -97.322494316114, -97.322949248245,
                 -97.323314074026, -97.324023439322, -97.324805160698,
                 -97.325537901625, -97.326152847017, -97.326507743705, -97.327417233517,
                 -97.327066368499, -97.326873160218, -97.326811433439,
                 -97.326793322023, -97.326465816713, 49.878360882242, 49.880448571713,
                 49.881587606616, 49.882302558031, 49.882099345087, 49.880887235604,
                 49.880733647644, 49.880715217766, 49.880542243361, 49.880354283594,
                 49.88024909346, 49.88007710254, 49.879993349384, 49.879907573529,
                 49.879735309529, 49.879632416034, 49.879568513704,
                 49.879393515604, 49.879271481747, 49.879221251598, 49.879051721645,
                 49.878910547442, 49.878887660748, 49.878773830019, 49.878718130778,
                 49.878551335802, 49.878412895641, 49.878376337651, 49.878215010803,
                 49.878051961224, 49.878042746738, 49.877881419854, 49.8777173589,
                 49.87769102677, 49.877545094809, 49.877375564773,
                 49.877330093176, 49.877208769711, 49.877031036527, 49.876969158644,
                 49.876861507364, 49.876690610262, 49.876608224074, 49.876417174353,
                 49.876247289487, 49.876239442027, 49.875902761127, 49.875766279205,
                 49.875375345561, 49.875149897672, 49.875044128575,
                 49.874888465676, 49.874710732209, 49.874683188771, 49.87454667096,
                 49.874371671581, 49.87432224805, 49.874202142144, 49.874038079971,
                 49.873961308169, 49.873871284603, 49.873699019256, 49.87360036825,
                 49.873534957959, 49.87336542758, 49.873239428293, 49.873187694034,
                 49.87301849238, 49.872878488317, 49.872798841253, 49.872517548283,
                 49.872461885765, 49.872122783383, 49.872069462509,
                 49.872027013308, 49.871659303529, 49.871438661127, 49.871062978983,
                 49.870770157396, 49.870699004289, 49.870291423896, 49.87024558722,
                 49.870186873396, 49.870383965456, 49.870821154722, 49.871835376487,
                 49.872191926803, 49.872469710213, 49.872601875959,
                 49.872668803342, 49.872651299071, 49.872555743866, 49.872388159239,
                 49.872146355477, 49.871782962916, 49.871412920385, 49.87078741544,
                 49.870375561726, 49.869825772213, 49.869366492486, 49.868971567827,
                 49.868759683858, 49.86866834303, 49.868918051943, 49.872409850355,
                 49.874324584726, 49.874936273958, 49.875115747947,
                 49.878360882242))", "list(c(-97.152357750422, -97.152503608067,
                 -97.152986019715, -97.153882186328, -97.154766663072, -97.155879603757,
                 -97.156859293084, -97.157029241699, -97.157614105879,
                 -97.158114803938, -97.158586421069, -97.159374440138, -97.159713020568,
                 -97.160288983609, -97.160537051475, -97.160849693145, -97.16126119033,
                 -97.161696524532, -97.161262118539, -97.15979624446,
                 -97.155803361591, -97.155797113748, -97.155790250721, -97.15534314593,
                 -97.154831569, -97.153102017043, -97.152357750422, 49.875597455979,
                 49.87502399348, 49.874438848292, 49.87394431807,
                 49.873737702442, 49.873738976009, 49.873983994883, 49.874028866529,
                 49.874250800379, 49.874558539512, 49.874969227362, 49.875806723453,
                 49.876217617697, 49.877100541767, 49.877433308583, 49.877722945655,
                 49.877967923962, 49.878197670505, 49.878356113875, 49.87889075061,
                 49.879123052147, 49.879080257999, 49.879033250109,
                 49.879060657636, 49.879083418318, 49.877342937555, 49.875597455979))"),
  id = as.factor(c("1012", "1727", "1432", "759", "87", "1474")),
  name = as.factor(c("Talbot-Grey", "Prairie Pointe", "Buffalo",
                     "Rossmere-B", "Glendale", "Armstrong Point"))
)

# convert passup data frame into sf object
latlong_sf <- latlong_dp %>%
  st_as_sf(
    coords = c("longitude", "latitude"),
    agr = "constant",
    crs = 26914,        # nad83 / Manitoba Projection
    stringsAsFactors = FALSE,
    remove = TRUE
  ) %>%
  drop_na()


wpg_sf <- wpg_dp %>%
  st_transform(26914) %>%   # convert to same projection as above
  select(id, name) 
#> Error in UseMethod("st_transform"): no applicable method for 'st_transform' applied to an object of class "data.frame"

Created on 2020-04-01 by the reprex package (v0.3.0)

Check the documentation:

wpg_dp is not one of the allowed object classes.

what would you suggest as a solution? or how would i get around this?

i am trying to map polygon data (i.e., my neighbourhood names) onto the point data.

The link states that the it must be an "object of class sf, sfc or sfg", so you'll have to convert your dataframe.

1 Like

It worked, thanks!

i figured out my issue: latlong_dp technically isnt a simple feature, by definition a simple feature is an entire row of information along with geometric information

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