I have a table column with data values in wkb format and I want to convert it to geometry. I came across few functions in sql (like "to_geography()") but I am not able to find how to do the same in R. I don't have any code but I have a column in table that contains data in the format:
0105000020E61000001500000001020000000A00000014123812E7FC5BC0CBF066FBE797444000BDC719E7FC5BC03023C634E89744401EB4CF1CE7FC5BC0D56C5E4FE897444035FD3E14E9FC5BC0FEB13C96E9974440DC650DB4F0FC5BC02BAD0036F3974440D0CEB69DF0FC5BC0D9B23E0EF59744403162B5B6F0FC5BC0BC0B065AF5974440DBC8EDEBF3FC5BC04F50327EFB974440AEC3613AF1FC5BC0DECB8254FF974440F3967EA7F2FC5BC065AFC593019844400102000000170000009040BC19B4FC5BC0F2C85718089A4440225D7F2FB4FC5BC0EFEA95D7079A44402FC42B4EB5FC5BC0E3372B66DB994440A6560F35B5FC5BC05014A765DB99444086146DC3B5FC5BC0AFDA4621AB9944409E9E45D0B5FC5BC0B076D721AB994440F9D6F90EB6FC5BC00132475E9F9944409D32835AB6FC5BC024F9B6FF8D994440A58C38D4B6FC5BC0A02B28B96D994440E6C3C2C7B6FC5BC0EDBE44195499444025D2DCE4B6FC5BC03519E62154994440068259D4B6FC5BC0A057625D2F9944406172F6E4B6FC5BC06A3004501999444080BDA5F5B6FC5BC0139CEBEFFC984440B937227CB6FC5BC053608BC7F2984440DBC8A79DB6FC5BC029518AE0F2984440A5EA45E5B6FC5BC0E27A5B4ACF984440BE7A1DE5B6FC5BC046739920CF98444070810EFEB6FC5BC0D2EE33B75F984440731E4E17B7FC5BC019875CD85F9844403773E3CFB7FC5BC0E6E483853C9844408569963FB9FC5BC0D70C1F331B984440E3E9FB3EB9FC5BC0102FFFF71A98444001020000000600000074ECDA1CBDFC5BC07CEB21C6DC974440018F396DBDFC5BC0DBE52AC7DC974440348F6423D6FC5BC017E3C03BDF9744403F23A160E1FC5BC0EA8A904BE3974440097A98C4E6FC5BC05C30AED3E797444014123812E7FC5BC0CBF066FBE797444001020000000A000000E3E9FB3EB9FC5BC0102FFFF71A984440DAE1C84DB9FC5BC0F812FEB81A984440FA2E834DB9FC5BC000AC84971998444008C051FDBBFC5BC0BC2D1C7619984440231972E4BBFC5BC00F688D581898444007E075D7BBFC5BC0655D5837189844406EB61751BCFC5BC069D3535A0C9844402348A4C6BCFC5BC09CC04866F4974440A65D0116BDFC5BC0925E2203DD97444074ECDA1CBDFC5BC07CEB21C6DC97444001020000002C0000008A775FB70EFD5BC00F42DC5817984440D81CA14413FD5BC00C42ACB418984440E18569C51CFD5BC036BAECC01D984440046C543525FD5BC0AE088635229844406E871CBE31FD5BC06C42B139259844403D492BC03EFD5BC04E2DEA1F27984440C9D968B33EFD5BC00B1E172027984440B28D71CB46FD5BC08B446652299844402DDB5AD250FD5BC0DFD17EC22E9844401F369A0F5FFD5BC0A47E7CF739984440310457D366FD5BC083E7FB3040984440B9005B3673FD5BC095E757D349984440C19694A278FD5BC0FC20A0054E98444051A051B681FD5BC03D270F3B559844404A6253EF8DFD5BC0E2B981675E984440F4C04BD592FD5BC016F6E5F5609844405D266AA19CFD5BC02DBE9834649844405EFFBA559FFD5BC0C129B08C61984440AD63D1CDA9FD5BC01C8CE72362984440491CBEDEA9FD5BC0EF90736A659844405C1C97E2A9FD5BC02A13EC5165984440884BC44FA9FD5BC01EA1AE039098444063DBAAF7A8FD5BC03F845001A2984440F94C93DEA8FD5BC0C2A3EE52B0984440F8F92350A8FD5BC00DF80A6DC5984440F41BA91DA8FD5BC04A341D61DD984440A572AE43A8FD5BC0D482DF9601994440B9AC18F2A7FD5BC0047BBE710F994440657EA61BA8FD5BC0BC41BFB10F994440A3E2C6F5A7FD5BC027428806109944409B6BB775A7FD5BC06C27F70223994440307CF22EA6FD5BC0B92FA38F5099444087CF6535A7FD5BC00FD0AD9550994440C96DD088A7FD5BC041674AB1509944400F776AD6A7FD5BC048EBED9950994440F347D98802FE5BC0ACF109185499444016D98BB30FFE5BC035B4AD99549944406DF50A9D18FE5BC013BC0AF154994440A222EFA029FE5BC0D2914341559944403076D09732FE5BC007BAF48255994440A25B941840FE5BC0AB65551C569944401934081B41FE5BC097B762ED559944404E40F16641FE5BC009DE84EF559944407E2F8BCC41FE5BC03BBEC5F25599444001020000000C0000007E2F8BCC41FE5BC03BBEC5F25599444014298B5542FE5BC09BF241D355994440BA33D64645FE5BC0168F23155499444030CB02A052FE5BC0F376D76454994440B081B01258FE5BC0D0A2F5C654994440DF3C506258FE5BC06F8550C1549944408C9D99B158FE5BC05FF2B6B85499444024B5366074FE5BC03A1E8DB854994440B5C416207BFE5BC08E147297549944409F3CB35582FE5BC0DE03F29654994440D6F5EAD982FE5BC07E93C91458994440A8E8FAF682FE5BC05B39BC5B589944400102000000070000006B05A665B1FC5BC0EDB0623FE19A44409F050A66B1FC5BC037740204E19A444060E09478B2FC5BC0F5D83A9BA99A444060075FFAB3FC5BC0D74AFFDD5A9A4440FA8E7DFAB3FC5BC0D0DB20C45A9A444077EBA42CB4FC5BC0B53F194E089A44409040BC19B4FC5BC0F2C85718089A4440010200000007000000721236061CFE5BC05E60A389CA9B444052FF0FDE1BFE5BC00E790ACFCA9B4440E34A93C91BFE5BC0B9389BF2CA9B444042D486C51AFE5BC032052C64CC9B44402801C82007FE5BC0D587E5B7CC9B444042B19E1207FE5BC04EBB9965DF9B4440D40F5AF506FE5BC0AC43060BE69B444001020000000D0000008C33F5357FFE5BC0DE9070AF6E9A44409562CE3B7FFE5BC00C60674A6E9A4440973BD65E7FFE5BC031A32AEA6D9A44400AF022AB7FFE5BC0EDCD37E85F9A44408294C5D380FE5BC08B8FDBC9179A444032395CC780FE5BC05346AB26189A44408F03202C81FE5BC0C79AB322FA9944404655841F81FE5BC0E142DCCADB9944400EF7873881FE5BC070C875EEC9994440C67A895181FE5BC0B49330D6C599444028997E1283FE5BC0025CFEAF58994440971CFD0883FE5BC0F7C9789258994440A8E8FAF682FE5BC05B39BC5B58994440010200000009000000A29A6F7A7CFE5BC008E50749BD9B44409F280EA77CFE5BC0CCFE7E02BD9B4440F5ECF6C27DFE5BC03C7FBDA0329B4440B96AEFB67DFE5BC099269D71329B44404EBF646F7EFE5BC0454B0C92E79A444043F23A847EFE5BC0CB11D5A2E79A4440973BD65E7FFE5BC031A32AEA6D9A44409562CE3B7FFE5BC00C60674A6E9A44408C33F5357FFE5BC0DE9070AF6E9A444001020000000500000068A94CFCEDFD5BC0C0420863B59B44402FACD2ACEDFD5BC0B490256AB59B444074F08EFCC2FD5BC09374D8A1B49B44400B23E0AE9AFD5BC01EC8DFE1B39B4440582EC9799AFD5BC047034BCCB39B4440010200000005000000BBFE78D886FC5BC0BCDA9D0E4A9B4440C719370387FC5BC0719BE6B53E9B4440CB33F1EB87FC5BC0CCA8D4D11A9B4440E31657E987FC5BC048907CBF1A9B444030A55DE187FC5BC06506FA861A9B4440010200000011000000582EC9799AFD5BC047034BCCB39B44404BDDE9499AFD5BC095EAF4DFB39B44406674AD0358FD5BC0A9F0B1F2B19B4440E26AF2FB37FD5BC09A70C14AB19B4440D4046F1EDDFC5BC0AACF587DAF9B44401DB14835AFFC5BC069259672AE9B444099EA5DE4AEFC5BC02D578F68AE9B44401554BB95AEFC5BC0AFB30977AE9B4440AE8046BB8CFC5BC062496FCAAD9B44401E9AFF668CFC5BC09C8D69A7AD9B4440D3DBF3188CFC5BC0B5210FBBAD9B44406C48565985FC5BC0EF12F96CAD9B44403851206E86FC5BC042C48D957D9B4440E9CAD6BB86FC5BC07EABBE14559B4440B6792EE286FC5BC09BF17BCF4A9B4440945E98DC86FC5BC069C1A75F4A9B4440BBFE78D886FC5BC0BCDA9D0E4A9B4440010200000004000000DCB0A69533FE5BC09113D60AB89B444005E5377633FE5BC036477BD7B79B4440330F228E16FE5BC01E397CCDB69B4440AF07A53D16FE5BC0FBE6BCCBB69B4440010200000006000000A17A4802FAFC5BC0E972F2050C984440D447AF78FFFC5BC0C5D0DD4511984440A49CFA3C03FD5BC09012F2510E98444083A67EAF05FD5BC0E3352F3010984440BF83177F0BFD5BC07E8013EC139844408A775FB70EFD5BC00F42DC581798444001020000000600000030A55DE187FC5BC06506FA861A9B4440873332EC87FC5BC0EE08F9481A9B4440AE73E75488FC5BC093660C2FDF9A44403001DE669CFC5BC0DC6BCD19E09A4440B9E62212B1FC5BC044E10323E19A44406B05A665B1FC5BC0EDB0623FE19A444001020000000500000068A94CFCEDFD5BC0C0420863B59B4440A695B61EEEFD5BC07B1EA395B59B44407C56C7C3EDFD5BC06A593D95B79B4440C0B385C3EDFD5BC0B6C72F0AF69B444031E5F908EDFD5BC07953CFF4F59B4440010200000006000000A29A6F7A7CFE5BC008E50749BD9B4440779BBAFF7BFE5BC01BE1758CBD9B4440CBDFE1AE7AFE5BC0C9FC186ABD9B444055166FD07AFE5BC081AA2328B99B4440C7F751E033FE5BC05ABB9BD9B79B4440DCB0A69533FE5BC09113D60AB89B44400102000000020000006A3902B40DFE5BC0D5C46C9CF39B44402AEE58C30DFE5BC0CD1348C7F69B4440010200000003000000690FA0C5EDFD5BC018C5EF44F69B444043170B17EEFD5BC01832D04EF69B44402AEE58C30DFE5BC0CD1348C7F69B444001020000000A000000AF07A53D16FE5BC0FBE6BCCBB69B44409999C53B16FE5BC015837D07B79B4440B1F99E3B16FE5BC025DB200FB79B4440A896EE2E16FE5BC023C00455C29B4440A03AB5FE15FE5BC03674257FCB9B444073D4ED0216FE5BC00525ECD0CB9B4440F664F63716FE5BC043C64F9ECB9B4440A421E25817FE5BC0E0608C64CA9B4440BB00BFB71BFE5BC06BFD9E99CA9B4440721236061CFE5BC05E60A389CA9B4440
Suppose your data frame looks like this:
df <- data.frame(value = 1:2,
wkb = c("000000000140000000000000004010000000000000",
"000000000140000000000000004010000000000000"))
df
#> value wkb
#> 1 1 000000000140000000000000004010000000000000
#> 2 2 000000000140000000000000004010000000000000
Then you can create a geometry column like this:
df$geometry = sf::st_as_sfc(structure(as.list(df$wkb), class = "WKB"))
df
#> value wkb geometry
#> 1 1 000000000140000000000000004010000000000000 POINT (2 4)
#> 2 2 000000000140000000000000004010000000000000 POINT (2 4)
Created on 2022-04-26 by the reprex package (v2.0.1)