{"id":16386507,"url":"https://github.com/rowanwins/polygon-splitter","last_synced_at":"2025-03-21T02:31:18.687Z","repository":{"id":37770177,"uuid":"169561867","full_name":"rowanwins/polygon-splitter","owner":"rowanwins","description":"A small (\u003c10kb minified) javascript library for splitting polygons by a polyline.","archived":false,"fork":false,"pushed_at":"2022-07-06T05:03:56.000Z","size":645,"stargazers_count":48,"open_issues_count":6,"forks_count":5,"subscribers_count":3,"default_branch":"master","last_synced_at":"2025-03-17T19:52:14.034Z","etag":null,"topics":["computational-geometry","geometry","polygon"],"latest_commit_sha":null,"homepage":"https://rowanwins.github.io/polygon-splitter/debug/dist/index.html","language":"JavaScript","has_issues":true,"has_wiki":null,"has_pages":null,"mirror_url":null,"source_name":null,"license":"mit","status":null,"scm":"git","pull_requests_enabled":true,"icon_url":"https://github.com/rowanwins.png","metadata":{"files":{"readme":"README.md","changelog":"CHANGES.md","contributing":null,"funding":"FUNDING.yml","license":"LICENSE","code_of_conduct":null,"threat_model":null,"audit":null,"citation":null,"codeowners":null,"security":null,"support":null},"funding":{"github":["rowanwins"],"custom":["https://paypal.me/rowanwinsemius"]}},"created_at":"2019-02-07T11:34:26.000Z","updated_at":"2024-12-04T06:47:49.000Z","dependencies_parsed_at":"2022-07-12T16:52:09.927Z","dependency_job_id":null,"html_url":"https://github.com/rowanwins/polygon-splitter","commit_stats":null,"previous_names":["rowanwins/polygon-split"],"tags_count":3,"template":false,"template_full_name":null,"repository_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/rowanwins%2Fpolygon-splitter","tags_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/rowanwins%2Fpolygon-splitter/tags","releases_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/rowanwins%2Fpolygon-splitter/releases","manifests_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/rowanwins%2Fpolygon-splitter/manifests","owner_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/owners/rowanwins","download_url":"https://codeload.github.com/rowanwins/polygon-splitter/tar.gz/refs/heads/master","host":{"name":"GitHub","url":"https://github.com","kind":"github","repositories_count":244725552,"owners_count":20499628,"icon_url":"https://github.com/github.png","version":null,"created_at":"2022-05-30T11:31:42.601Z","updated_at":"2022-07-04T15:15:14.044Z","host_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub","repositories_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories","repository_names_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repository_names","owners_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/owners"}},"keywords":["computational-geometry","geometry","polygon"],"created_at":"2024-10-11T04:17:27.769Z","updated_at":"2025-03-21T02:31:18.327Z","avatar_url":"https://github.com/rowanwins.png","language":"JavaScript","funding_links":["https://github.com/sponsors/rowanwins","https://paypal.me/rowanwinsemius"],"categories":[],"sub_categories":[],"readme":"## polygon-splitter\r\nA small (\u003c10kb minified) javascript library for splitting geojson polygons by a polyline.\r\n\r\nWorks with\r\n- Concave polygons\r\n- Polygons with holes\r\n- Single \u0026 Multi-part geometries\r\n\r\n### Install\r\n````\r\nnpm install polygon-splitter\r\n````\r\n\r\n### API\r\nAccepts either a geojson `Feature` or `Geometry` (inc `MultiPolygon` and `MultiLineString`).\r\n\r\n```js\r\nimport polygonSplitter from 'polygon-splitter'\r\n// or\r\nconst polygonSplitter = require('polygon-splitter')\r\n\r\nconst polygon = {\r\n    \"type\": \"Polygon\",\r\n    \"coordinates\": [[[0, 0],[10, -10], [20, 0], [10, 10], [0, 0]]]\r\n}\r\n\r\nconst polyline = {\r\n    \"type\": \"LineString\",\r\n    \"coordinates\": [[20, 10], [5, 0], [20, -10]]\r\n}\r\nconst output = polygonSplitter(polygon, polyline)\r\n```\r\n\r\n### Performance\r\n\r\nSplitting a polygon with a hole into 4 pieces.\r\nCompared with an approach [outlined here](http://kuanbutts.com/2020/07/07/subdivide-polygon-with-linestring/), and also another [one described here](https://gis.stackexchange.com/a/344277)\r\n````\r\npolygon-splitter x 228,391 ops/sec ±0.63% (88 runs sampled)\r\nalternate approach x 2,052 ops/sec ±3.60% (78 runs sampled)\r\nalternate approach 2 x 900 ops/sec ±3.60% (78 runs sampled)\r\n````\r\n\r\n### Describing the algorithm\r\nThis is basically my own implementation of this algorithm. If you're interested in the details it's probably best to read to the source code.\r\nSome key points of understanding\r\n- Each intersection point will be used in two output polygons so we'll need to keep track of how many times we visit each intersection point in constructing the output\r\n- The algorithm works by switching back and forth walking along the polyline and polygon to collect an output polygon\r\n- An output polygon must contain at least one stretch from the linestring, and at least one stretch from the polgon, but it might also contain many, so we'll use a while loop to just keep going till we get back to the start\r\n- For each intersection point we mark whether the polyline is heading into the polygon or not, this is helpful for knowing which we need to walk the polyline in constructing the output (eg it could be backwards or forwards).\r\n\r\n\r\n### Acknowledgements\r\nThanks to mourner for the most excellent [robust-predicates library](https://github.com/mourner/robust-predicates).\r\n\r\nThanks for my employer [FrontierSI](http://frontiersi.com.au/) for freeing up some of my time to finish off this algorithm.","project_url":"https://awesome.ecosyste.ms/api/v1/projects/github.com%2Frowanwins%2Fpolygon-splitter","html_url":"https://awesome.ecosyste.ms/projects/github.com%2Frowanwins%2Fpolygon-splitter","lists_url":"https://awesome.ecosyste.ms/api/v1/projects/github.com%2Frowanwins%2Fpolygon-splitter/lists"}