[Tutor] overlay

Chris or Leslie Smith smiles at worksmail.net
Sun Nov 6 20:20:47 CET 2005


| From: Shi Mu 
| Is there any sample code to calculate the overlaid area between two
| polygons? 
| Thanks!
| 

The polygon module at ( http://www.dezentral.de/warp.html?http://www.dezentral.de/soft/Polygon/ ) was found by googling for "polygon module python".  If by "overlay" you mean the area in common between two polygons, it can handle this:

###
>>> import Polygon
>>> a=Polygon.Polygon(((0.,0.),(1.,0.),(0.,1.))) #it closes automatically back to starting pt
>>> b=Polygon.Polygon(((0.,0.),(1.,0.),(1.,1.)))
>>> c = a & b
>>> Polygon.pointList(c)
[(1.0, 0.0), (0.0, 0.0), (0.5, 0.5)]
>>> c.area()
0.25
>>>
###

Note: the pdf docs did not appear to be included in the download from the page cited above; there is a link on the page cited above that downloads it for you.

HTH,
/c


More information about the Tutor mailing list