[R-sig-Geo] Mixing points and sf objects

Patrick Giraudoux p@tr|ck@g|r@udoux @end|ng |rom un|v-|comte@|r
Thu Mar 3 11:47:12 CET 2022


After some trials off list with Roger, it appears that the underlying 
problem was that chbrut[,5:6] are character columns, which need to be 
converted to numeric first.
Ashes on my head, a looked for complicated things where the issue was at 
hand for a R early beginner...
Sorry to have polluted the list with such a trivial issue...


Le 03/03/2022 à 10:32, Roger Bivand a écrit :
> On Thu, 3 Mar 2022, Patrick Giraudoux wrote:
>
>> Dear listers,
>>
>> Just for curiosity, using one sf object (depts) and one classical
>> data.frame with two columns bearing coordinates, I wonder why this
>> sequence works (points and department limits are correctly drawn):
>>
>> plot(chbrut[,5:6],asp=1)
>> plot(st_geometry(depts),add=TRUE)
>>
>> .. but not this one (points of chbrut are not projected - or projected
>> somewhere else, and are not visible on the map)
>>
>> plot(st_geometry(depts),reset=FALSE)
>> points(chbrut[,5:6],pch=19,col=cols)
>
> Sorry, cannot reproduce:
>
> library(sf)
> nc <- st_read(system.file("gpkg/nc.gpkg", package="sf"))
> nc_xy <- st_transform(nc, "EPSG:32019")
> set.seed(1)
> pts <- as.data.frame(st_coordinates(st_sample(nc_xy, 100)))
>
> plot(pts, asp=1)
> plot(st_geometry(nc_xy), add=TRUE)
>
> and
>
> plot(st_geometry(nc_xy))
> points(pts)
>
> seem the same. reset= is irrelevant if the plot method for sfc objects 
> is used, I think it applies to sf objects only, when multiple maps may 
> be displayed with keys.
>
> Hope this helps,
>
> Roger
>
>
>>
>> Best,
>>
>> Patrick
>>
>>     [[alternative HTML version deleted]]
>>
>> _______________________________________________
>> R-sig-Geo mailing list
>> R-sig-Geo using r-project.org
>> https://eur02.safelinks.protection.outlook.com/?url=https%3A%2F%2Fstat.ethz.ch%2Fmailman%2Flistinfo%2Fr-sig-geo&data=04%7C01%7CRoger.Bivand%40nhh.no%7C5d59728741d046dc88ab08d9fcf204c5%7C33a15b2f849941998d56f20b5aa91af2%7C0%7C0%7C637818938783874996%7CUnknown%7CTWFpbGZsb3d8eyJWIjoiMC4wLjAwMDAiLCJQIjoiV2luMzIiLCJBTiI6Ik1haWwiLCJXVCI6Mn0%3D%7C3000&sdata=KxQmoTdwqh0IhlHnHeXmtX0DTIf2kGceX2INux47%2FHM%3D&reserved=0 
>>
>>
>

	[[alternative HTML version deleted]]



More information about the R-sig-Geo mailing list