从多边形中找到最大面积矩形。
maxrect的Python项目详细描述
找到给定多边形的最大内接轴对齐矩形。 找到多个多边形的交集。
安装
pip install git+https://${GITHUB_TOKEN}@github.com/planetlabs/maxrect.git
cli
# For a given GeoJSON file $ max-rect [path/to/file]# Piping $ cat path/to/file.geojson | max-rect # For a quick visualization $ cat path/to/file.geojson | max-rect | geojsonio # For comparison between the original polygon and the inscribed rectangle $ cat path/to/file.geojson | max-rect --compare | geojsonio # Find the intersection of two geojson files poly-intersect path/to/file1.geojson path/to/file2.geojson | geojsonio # Find the largest inscribed rectangle that sits within multiple shapes poly-intersect path/to/file1.geojson path/to/file2.geojson | max-rect | geojsonio # Find the intersection of two geojson files poly-intersect path/to/file1.geojson path/to/file2.geojson | geojsonio # Find the largest inscribed rectangle that sits within multiple shapes poly-intersect path/to/file1.geojson path/to/file2.geojson | max-rect | geojsonio
Python
frommaxrectimportget_intersection,get_maximal_rectangle,rect2poly# For a given convex polygoncoordinates1=[[x0,y0],[x1,y1],...[xn,yn]]coordinates2=[[x0,y0],[x1,y1],...[xn,yn]]# find the intersection of the polygons_,coordinates=get_intersection([coordinates1,coordinates2])# get the maximally inscribed rectanglell,ur=get_maximal_rectangle(coordinates)# casting the rectangle to a GeoJSON-friendly closed polygonrect2poly(ll,ur)