[R-sig-Geo] Using sf package to calculate line midpoints from Spatial Line data (both LINESTRING and MULTILINESTRING)

Julian Parnelle ju||@np@rne||e @end|ng |rom out|ook@com
Wed Feb 3 01:20:07 CET 2021


Dear list,

My question is straightforward: how could one use the sf package to calculate the Longitude and Latitude of the line midpoints in spatial line data, in a way that works both for LINESTRING and MULTILINESTRING sf data.frames? (one per spatial line, in case the spatial line is composed of multiple line segments). After searching online for quite a bit, the only direct reference I found was this GIS Stack Exchange question from three years ago: https://gis.stackexchange.com/questions/277219/sf-equivalent-of-r-maptools-packages-spatiallinesmidpoints. However, the solution proposed there is only more or less reliable for LINESTRING data and I lack sufficient knowledge of sf objects and MULTILINESTRING representation to update that and make it more reliable.

I was used to doing that with the SpatialLinesMidPoints command, but I am finding it quite difficult to accomplish the same with the sf package. I do know that this task could perhaps be achieved by interpolating across the lines up to 50% of its extension, using for example ST_Line_Interpolate_Point. However, I don't see to be able to achieve exactly the same with either st_line_sample or st_segmentize.

Any suggestions would be very welcome.

Julian

	[[alternative HTML version deleted]]



More information about the R-sig-Geo mailing list