0

I have a shapefile (EPSG:4326 - WGS 84) containing many features with linestring geometries and I would really like to divide each line (like that one shown in the uploaded picture,example of linestring geometry to work with) into several segments, every time the "shape" of the line changes. It is probably possible to use the angle created by lines linking 2 successive points (perhaps the amount of azimuth change should be the most appropriate measurement), but I am not sure. The direction of the different segments could be completely random, so I suggest not taking into account this parameter. The final aim should be to identify the straight segments circled in blue which should result parallel to linestring geometries from other shapefiles (representing nautical miles limits). Is this issue fixable using R or QGIS?

I have already tried some algorithms in QGIS, such as "Explode lines", or coding something in R defining functions to check if a segment is straight based on angle threshold, but nothing worked.

I need to find the "straight parts" of my irregular curved line. Segments I should obtain have no fixed length and the number of segments within each line feature of the shapefile could be variable.

dput(first_line_feature)
structure(list(trip = 1, geometry = structure(list(structure(c(12.9020599, 
12.9020599, 12.9020599, 12.9020599, 12.9022016, 12.9045633, 12.9061516, 
12.9052416, 12.9053599, 12.9056833, 12.9059316, 12.9063283, 12.9062733, 
12.905615, 12.905855, 12.906235, 12.9062583, 12.90638, 12.9065916, 
12.9060383, 12.9058183, 12.9055433, 12.9053866, 12.9051033, 12.9051016, 
12.905165, 12.90482, 12.9049416, 12.9047516, 12.9059549, 12.9061616, 
12.9061416, 12.9060399, 12.9062516, 12.9057933, 12.90571, 12.9057549, 
12.9056499, 12.9067083, 12.9080516, 12.9093633, 12.9094066, 12.90986, 
12.910375, 12.9109949, 12.9115833, 12.9119733, 12.9125083, 12.9127283, 
12.9132166, 12.913825, 12.9144183, 12.9148533, 12.9153899, 12.9156733, 
12.916255, 12.9168266, 12.91731, 12.9178383, 12.91856, 12.9185183, 
12.9188983, 12.9193783, 12.9199349, 12.920255, 12.92044, 12.9205666, 
12.921435, 12.92136, 12.921875, 12.922405, 12.9230383, 12.9236083, 
12.924, 12.924475, 12.9244299, 12.9245349, 12.9247583, 12.9251483, 
12.9257533, 12.9261616, 12.92675, 12.92672, 12.9266, 12.9264849, 
12.9260966, 12.9260183, 12.9260183, 12.9262533, 12.9264666, 12.9270266, 
12.9274933, 12.9281333, 12.9286, 12.9290233, 12.9290783, 12.929265, 
12.9295499, 12.9299483, 12.9305066, 12.9310733, 12.9315483, 12.9320083, 
12.9321533, 12.9327683, 12.9333033, 12.9338683, 12.9342516, 12.9346133, 
12.9344783, 12.9318816, 12.9292883, 12.9261816, 12.92308, 12.9198833, 
12.91663, 12.9134816, 12.9110283, 12.9089816, 12.9069299, 12.9047116, 
12.9027549, 12.9021899, 12.8996883, 12.8975133, 12.8953933, 12.8931466, 
12.8915216, 12.8914083, 12.893865, 12.8962466, 12.8985033, 12.9008299, 
12.9024716, 12.9046849, 12.9064816, 12.9080816, 12.9099666, 12.9118183, 
12.9136383, 12.9156849, 12.9169916, 12.9189016, 12.9206683, 12.9224499, 
12.9243616, 12.92617, 12.928005, 12.9301099, 12.9318383, 12.93356, 
12.9353816, 12.9368116, 12.9388066, 12.94018, 12.94197, 12.9438783, 
12.945815, 12.94785, 12.9501516, 12.9520483, 12.954225, 12.9560366, 
12.9552816, 12.95755, 12.9599316, 12.9601916, 12.960565, 12.961085, 
12.9615733, 12.96205, 12.962435, 12.962585, 12.9624283, 12.96048, 
12.9598716, 12.9592766, 12.9581283, 12.9576583, 12.9564333, 12.9553016, 
12.954985, 12.9545766, 12.9513483, 12.9497183, 12.9484983, 12.948355, 
12.948055, 12.9460666, 12.9453583, 12.944425, 12.942445, 12.9417316, 
12.9436916, 12.9456783, 12.9476833, 12.9497, 12.9515466, 12.9535766, 
12.95558, 12.95756, 12.9593766, 12.9612, 12.9630616, 12.96481, 
12.9664749, 12.9680933, 12.9699316, 12.9719266, 12.9736766, 12.9720583, 
12.96976, 12.9677666, 12.965725, 12.96351, 12.961285, 12.9590983, 
12.95682, 12.9545833, 12.9523416, 12.9501116, 12.947765, 12.9456333, 
12.9436233, 12.9410133, 12.93828, 12.935435, 12.9322966, 12.9292733, 
12.9261366, 12.9230599, 12.9197466, 12.9165949, 12.913525, 12.9101733, 
12.9068183, 12.9048516, 12.9059399, 12.9037366, 12.9021333, 12.9021333, 
12.9021333, 12.9021333, 12.9021333, 12.9021333, 12.9021333, 12.9021333, 
43.9249449, 43.9249449, 43.9249449, 43.9249449, 43.9249266, 43.9246083, 
43.9255916, 43.927285, 43.9289666, 43.93096, 43.9328333, 43.9346733, 
43.9365433, 43.9382616, 43.9401199, 43.9419349, 43.9438366, 43.9460533, 
43.9482966, 43.9503816, 43.9526616, 43.9549083, 43.9571699, 43.9594416, 
43.961675, 43.9639366, 43.9661849, 43.9684633, 43.9706983, 43.972825, 
43.9750583, 43.9773333, 43.9796166, 43.9819516, 43.9842083, 43.9863933, 
43.9886983, 43.9910233, 43.9932033, 43.9953499, 43.996345, 43.9961766, 
43.9958899, 43.9956666, 43.995335, 43.9950433, 43.9948483, 43.99455, 
43.9944183, 43.9942316, 43.99394, 43.9936666, 43.993505, 43.9932166, 
43.9930816, 43.9927799, 43.9924866, 43.9922833, 43.9919866, 43.9901, 
43.9899633, 43.9897683, 43.9895816, 43.9893249, 43.9891016, 43.98895, 
43.9888999, 43.9885583, 43.9885199, 43.98826, 43.9880316, 43.987725, 
43.987465, 43.9872666, 43.98692, 43.9869349, 43.9868733, 43.9867483, 
43.9865766, 43.986265, 43.9860666, 43.98578, 43.9857166, 43.98568, 
43.9843783, 43.9820733, 43.9811516, 43.9811516, 43.9810433, 43.9809316, 
43.9806516, 43.9803616, 43.9800483, 43.9798466, 43.9795433, 43.9794516, 
43.9793033, 43.9793433, 43.9792, 43.9788883, 43.9786699, 43.9784299, 
43.9781116, 43.97806, 43.9778233, 43.9776033, 43.9773216, 43.9771333, 
43.9769533, 43.9760483, 43.9762716, 43.9755566, 43.9751166, 43.9746983, 
43.9744166, 43.9745416, 43.9749583, 43.9759, 43.9768333, 43.9777699, 
43.9787583, 43.9796983, 43.981825, 43.9828366, 43.98386, 43.9847816, 
43.9858133, 43.9842033, 43.9823916, 43.9812833, 43.980195, 43.9791933, 
43.9780133, 43.9758016, 43.9739183, 43.9718016, 43.969615, 43.9674633, 
43.9654316, 43.9632916, 43.96127, 43.9589883, 43.9568916, 43.9546983, 
43.9524933, 43.95045, 43.9482616, 43.94606, 43.9440399, 43.9418983, 
43.9396766, 43.937485, 43.93524, 43.933175, 43.9308533, 43.9287516, 
43.9266399, 43.9244816, 43.9223383, 43.9204166, 43.9183566, 43.9163183, 
43.9142433, 43.9130833, 43.912075, 43.9108583, 43.91037, 43.9100533, 
43.9096066, 43.9092683, 43.9089183, 43.9086966, 43.90829, 43.9087516, 
43.9102049, 43.9112399, 43.9120566, 43.9124766, 43.9135166, 43.9136566, 
43.9139383, 43.91502, 43.9161266, 43.9183933, 43.9196333, 43.9207999, 
43.9217899, 43.922865, 43.9223016, 43.9212283, 43.9202133, 43.91886, 
43.917355, 43.9159966, 43.9146433, 43.9133016, 43.9118933, 43.910445, 
43.9091, 43.9077233, 43.9063066, 43.9049766, 43.9036233, 43.9022733, 
43.9008716, 43.899415, 43.898005, 43.8966233, 43.8962633, 43.8959199, 
43.89772, 43.89943, 43.90121, 43.9030166, 43.9046983, 43.9063483, 
43.9079816, 43.9095883, 43.9111649, 43.9127966, 43.9144816, 43.9160166, 
43.9176783, 43.919075, 43.920125, 43.9210799, 43.9220283, 43.922985, 
43.9239633, 43.9247833, 43.92573, 43.9264366, 43.9272633, 43.9281449, 
43.9288283, 43.9291383, 43.927565, 43.9252733, 43.9248983, 43.924955, 
43.924955, 43.924955, 43.924955, 43.924955, 43.924955, 43.924955, 
43.924955), dim = c(247L, 2L), class = c("XY", "LINESTRING", 
"sfg"))), class = c("sfc_LINESTRING", "sfc"), precision = 0, bbox = structure(c(xmin = 12.8914083, 
ymin = 43.8959199, xmax = 12.9736766, ymax = 43.996345), class = "bbox"), crs = structure(list(
    input = "EPSG:4326", wkt = "GEOGCRS[\"WGS 84\",\n    ENSEMBLE[\"World Geodetic System 1984 ensemble\",\n        MEMBER[\"World Geodetic System 1984 (Transit)\"],\n        MEMBER[\"World Geodetic System 1984 (G730)\"],\n        MEMBER[\"World Geodetic System 1984 (G873)\"],\n        MEMBER[\"World Geodetic System 1984 (G1150)\"],\n        MEMBER[\"World Geodetic System 1984 (G1674)\"],\n        MEMBER[\"World Geodetic System 1984 (G1762)\"],\n        MEMBER[\"World Geodetic System 1984 (G2139)\"],\n        ELLIPSOID[\"WGS 84\",6378137,298.257223563,\n            LENGTHUNIT[\"metre\",1]],\n        ENSEMBLEACCURACY[2.0]],\n    PRIMEM[\"Greenwich\",0,\n        ANGLEUNIT[\"degree\",0.0174532925199433]],\n    CS[ellipsoidal,2],\n        AXIS[\"geodetic latitude (Lat)\",north,\n            ORDER[1],\n            ANGLEUNIT[\"degree\",0.0174532925199433]],\n        AXIS[\"geodetic longitude (Lon)\",east,\n            ORDER[2],\n            ANGLEUNIT[\"degree\",0.0174532925199433]],\n    USAGE[\n        SCOPE[\"Horizontal component of 3D system.\"],\n        AREA[\"World.\"],\n        BBOX[-90,-180,90,180]],\n    ID[\"EPSG\",4326]]"), class = "crs"), n_empty = 0L)), row.names = 1L, sf_column = "geometry", agr = structure(c(trip = NA_integer_), levels = c("constant", 
"aggregate", "identity"), class = "factor"), class = c("sf", 
"tbl_df", "tbl", "data.frame"))
margusl
  • 7,804
  • 2
  • 16
  • 20
  • Welcome to SO! Please share some samples from your input data, e.g. `dput()` output of `sf` object or geometry column, along with your current attempts. There are many other more or less straight sections on linked image, what defines the sections you are after? Constant azimuth (i.e. 45 deg, +/-)? Amount of azimuth change? Minimum length? Distance tolerance? Does direction matter (for 45deg segments include NorthWest, SouthEast or both)? Are those geometries on a sphere or projected geometries on plane (2 North-South segments on sphere are only parallel on equator) , should it matter? – margusl Aug 23 '23 at 10:22
  • 1
    @margusl I have just tried to reply to your comment modifying the question body, adding some particulars which should be useful to address the issue – Pamela Lattanzi Aug 23 '23 at 11:27

0 Answers0