Webgis clipping algorithm-line clipping polygon

Source: Internet
Author: User

In the GIS system often use some cutting method, first recommend a very useful space analysis JavaScript library--turf.js, not only powerful, easy to use, but also fast processing speed.

The clipping method for a polygon in turf.js is to use a polygon to crop the polygon, but it is not sufficient to use the line to cut the polygon in the actual work.

Http://turfjs.org/docs#bboxClip

This article uses the basic method of turf.js, and constructs the method of line clipping polygon on this basis.

Click to view online demo

Demo Preview

Algorithm principle

(i) Cutting of individual polygon

Intersection requirements: lines and polygons have only two intersections, and polygons can be divided into two parts

1. Calculate two intersections of polygons and lines and divide polygons into two lines according to intersections

2, divides the two lines according to the cutting point and the cutting line splicing, respectively composes two polygons,(need to note is the line directionality question)

(b) Clipping of the ring polygon

Intersection requirements: lines and polygons have only two intersection points, and polygons can be divided into two parts, while the cut line must not intersect with the inner ring

Note: The order of the outer polygons in the Geojson data is clockwise and the inner polygon order of the Rings is counterclockwise

1. Split the ring polygon into inner and outer rings

2, the outer ring polygon cut through the cutting line method with (a)

3. The outer ring polygon and the inner ring polygon after the combined cutting:

Determine how to combine restores by judging the inner ring polygon inside the cut polygon

(iii) clipping of Multipolygon polygons

Intersect requirement: The cut line can only have two intersections with one polygon in Multipolygon

1, split Multipolygon split into multiple polygon

2, according to the intersection of cutting line and polygon, the polygon with two intersections is cut

3, the segmented polygon and not participate in the cut polygon merged into a feature set to return

Project Address

Github:https://github.com/fwc1994/clip-polygon

Webgis clipping algorithm-line clipping polygon

Contact Us

The content source of this page is from Internet, which doesn't represent Alibaba Cloud's opinion; products and services mentioned on that page don't have any relationship with Alibaba Cloud. If the content of the page makes you feel confusing, please write us an email, we will handle the problem within 5 days after receiving your email.

If you find any instances of plagiarism from the community, please send an email to: info-contact@alibabacloud.com and provide relevant evidence. A staff member will contact you within 5 working days.

A Free Trial That Lets You Build Big!

Start building with 50+ products and up to 12 months usage for Elastic Compute Service

  • Sales Support

    1 on 1 presale consultation

  • After-Sales Support

    24/7 Technical Support 6 Free Tickets per Quarter Faster Response

  • Alibaba Cloud offers highly flexible support services tailored to meet your exact needs.