# Split features of multi-part polygons according to condition(s) in QGIS

I have a multi-part polygon with a large number of irregularly-shaped features (>600 features). I would like to split them into smaller sub-features/ segments(?) and assign a unique id to these smaller sub-features. Ideally, I would like to split these features based on the condition that the line/ border between them is straight. However, some of the features hardly have straight lines running through them, so another way to split them could be based on a pre-determined area size.

Is there a function to do this automatically in QGIS? And, what are the steps to do this? I'm using QGIS version 3.4.4-Madeira.

For example, I would like to do something like this and then add a unique id row in the feature table: ## 1 Answer

1. Use the `polygons to lines` tool to convert the polygon borders into lines.
2. Use the `explode lines` tool to split the border lines into their separate segments.
3. Manually select and delete all the border lines except the middle border.
4. Use the `geometry by expression` tool to create a perpendicular line at the first vertex of every border line segment. Use an expression like this one, but substitute an appropriate distance value in both places where it says 500. The lines will be twice as long as the distance value.

`make_line( project(make_point(\$x_at(0),\$y_at(0)),500,angle_at_vertex(\$geometry,0) + 90), project(make_point(\$x_at(0), \$y_at(0)),500, angle_at_vertex(\$geometry,0) - 90))`

5. Use `split with lines` to split the original polygon with the perpendicular lines

Note: This method will split the polygon at every vertex. In your example image, it looks like some of the segments are not perfectly straight. To avoid splitting the polygons at the vertices of the not-quite-straight segments, you'll need to do some processing between steps 3 and 4. Experiment with the `simplify` and `snap to geometry` tools, or manually remove the extra vertices with the vertex tool.
{"ft_lang_label":"__label__en","ft_lang_prob":0.96165687,"math_prob":0.94203776,"size":717,"snap":"2021-21-2021-25","text_gpt3_token_len":161,"char_repetition_ratio":0.13183731,"word_repetition_ratio":0.016806724,"special_character_ratio":0.22036262,"punctuation_ratio":0.108843535,"nsfw_num_words":0,"has_unicode_error":false,"math_prob_llama3":0.95000535,"pos_list":[0,1,2],"im_url_duplicate_count":[null,3,null],"WARC_HEADER":"{\"WARC-Type\":\"response\",\"WARC-Date\":\"2021-06-24T18:12:09Z\",\"WARC-Record-ID\":\"<urn:uuid:df7a333c-fa20-40d6-86c6-954b46d0f22b>\",\"Content-Length\":\"160639\",\"Content-Type\":\"application/http; msgtype=response\",\"WARC-Warcinfo-ID\":\"<urn:uuid:ad7fbf04-73c3-4894-a0a0-2b009bfbac69>\",\"WARC-Concurrent-To\":\"<urn:uuid:297f18ef-65e8-48d4-8577-93a4c1302e10>\",\"WARC-IP-Address\":\"151.101.1.69\",\"WARC-Target-URI\":\"https://gis.stackexchange.com/questions/333509/split-features-of-multi-part-polygons-according-to-conditions-in-qgis\",\"WARC-Payload-Digest\":\"sha1:I73M56WQPJJBG7EAL2JIDUY43Q2SFVOU\",\"WARC-Block-Digest\":\"sha1:CC4JQKMIIA7UYSCHODZPWL335LQM36WC\",\"WARC-Identified-Payload-Type\":\"text/html\",\"warc_filename\":\"/cc_download/warc_2021/CC-MAIN-2021-25/CC-MAIN-2021-25_segments_1623488556482.89_warc_CC-MAIN-20210624171713-20210624201713-00399.warc.gz\"}"}