# Split polygon into features where it intersects with points/lines - QGIS, R or Python

I have a polygon that represents the area surveyed over a line (a buffer with 1.5m of width). The points represent the start of a "substrate type" observed during the survey, e.g. the white point represents the start of rocky substrate and the green point represent the start of sandy bottom (and hence, the end of rocky substrate).

I want to divide this polygon, so that I can represent continuously the substrate type (and not by points) by generating a "split" polygon in which each feature represents a substrate type.

So basically, I want to split the polygon where it intersects with the points.

I have found a way to split the polygon into equal parts with equal areas. However, I couldn't yet find the solution to my problem. Something that I thought would be quite easy to do in QGIS is turning into a nightmare! Somehow I can't find any algorithm to do so. I have also tried different functions in R and python but I can't seem to find a solution.

I have also generated manually a new line shapefile representing the point where I would like my polygon to be split:

But, again, I am stuck and I can't find a way to split the polygon where it intersects with the lines.

Does anyone have any idea how I could proceed?

From each point, get the closest point on the boudary of the polygon and connect this one with the point itself. Extend the line on both sides for a small distance, long enough to cross both sides of the buffer. Use these auxiliary lines to split the buffer, using `Menu Processing > Toolbox > Split with lines`.

The auxiliary lines can be created with `Menu Processing > Toolbox > Geometry by expression`, using the point layer as input. Use this expression:

``````extend (
make_line (
\$geometry,
closest_point (
overlay_nearest (
'polygon', -- replace this with the name of your polygon layer
boundary(\$geometry))[0],
\$geometry)
),
1,  -- adapt the length of the auxiliary lines to your needs
1 -- adapt the length of the auxiliary lines to your needs
)
``````

Auxiliary lines in black (here create with Geoemtry generator for visualization puropse) used to split the polygon:

In Python, with lines use Shapely

``````from shapely.wkt import loads
# lines
a = loads("LineString (107.21989924433245278 -581.00352644836289073, 316.47581863979849004 -426.17833753148624965)")
b = loads("LineString (379.37355163727960417 -628.17682619647371212, 524.52216624685149782 -588.26095717884140868)")
c = loads("LineString (884.97455919395486035 -613.66196473551656254, 951.50100755667529029 -543.50680100755675994)")
d = loads("LineString (1286.55239294710372633 -590.68010075566758132, 1255.10352644836302716 -489.07607052896730693)")
# polygon
poly = loads("'POLYGON ((3.196725440805984 -169.7491183879093, 52.78916876574303 -248.3712846347607, 122.9443324937027 -308.8498740554156, 148.3453400503778 -354.8136020151135, 196.7282115869018 -394.7294710327457, 216.0813602015113 -487.8664987405542, 268.0929471032746 -516.8962216624686, 349.1342569269522 -527.7823677581865, 422.9181360201512 -550.7642317380354, 462.8340050377834 -567.6982367758187, 480.9775818639799 -618.5002518891689, 554.7614609571789 -610.0332493702772, 737.4068010075569 -542.2972292191437, 848.6874055415618 -496.3335012594459, 882.5554156171286 -466.0942065491184, 914.0042821158692 -483.0282115869019, 917.6329974811085 -528.9919395465996, 938.1957178841311 -568.9078085642319, 984.1594458438288 -551.9738035264485, 1011.97959697733 -561.6503778337533, 1043.428463476071 -544.7163727959698, 1057.943324937028 -545.925944584383, 1073.667758186398 -539.8780856423175, 1106.326196473552 -567.6982367758187, 1097.85919395466 -600.3566750629724, 1143.822921914358 -611.2428211586903, 1233.331234256927 -541.0876574307306, 1244.217380352645 -507.2196473551638, 1278.085390428212 -504.8005037783377, 1321.629974811083 -496.3335012594459, 1361.545843828716 -496.3335012594459, 1366.384130982368 -532.6206549118389, 1319.210831234257 -531.4110831234258, 1273.247103274559 -555.6025188916877, 1235.750377833753 -602.7758186397987, 1184.948362720403 -623.3385390428213, 1129.308060453401 -647.5299748110833, 1102.697481108312 -641.4821158690178, 1010.770025188917 -634.2246851385391, 945.4531486146097 -624.5481108312343, 923.680856423174 -595.51838790932, 910.3755667506299 -596.7279596977331, 883.7649874055418 -542.2972292191437, 802.7236775818641 -549.5546599496223, 750.7120906801009 -578.5843828715366, 670.8803526448364 -617.2906801007558, 592.258186397985 -642.6916876574309, 554.7614609571789 -649.9491183879095, 514.8455919395467 -651.1586901763226, 491.8637279596978 -658.4161209068011, 426.5468513853905 -595.51838790932, 373.3256926952141 -568.9078085642319, 259.6259445843829 -555.6025188916877, 210.0335012594458 -536.2493702770782, 200.356926952141 -521.734508816121, 178.5846347607053 -491.4952141057936, 166.4889168765743 -450.3697732997482, 171.3272040302267 -417.7113350125945, 131.4113350125944 -382.6337531486147, 93.91460957178839 -370.5380352644837, 92.70503778337527 -319.7360201511335, 45.53173803526444 -287.07758186398, 24.96901763224176 -281.0297229219144, 5.615869017632185 -252, 3.196725440805984 -168.5395465994962, 3.196725440805984 -169.7491183879093))'")
``````

Shapely has the split function but it only works for splitting a (Multi)Polygon by only one line.

``````from shapely.ops import split
res = split(poly,a) # split by line a
``````

With multiple lines use the solution of Split polygon by MultiLineString - shapely and Splitting Polygon by Linestring in GeoDjango?

``````lines = [a,b,c,d] # list of lines
lines.append(poly.boundary) # append the boundary of the Polygon
from shapely.ops import unary_union, polygonize
border_lines = unary_union(lines)
splitted = polygonize(borfer_lines)
``````

Result:

As @BERA mentioned in comments, use Geoprocessing tool "Split with Lines".