Tuesday 11 October 2016

python - Calculating area of polygon inside region?


I am new to geographic information systems and i need to calculate the area of a a polygon ( a circle to be precise) that falls inside the boundaries of a region, say a state or a country. For example, in the figure below, the black outline the state in consideration and the circle is the concerned polygon. The yellow area is the area that is required. I have the concerned shapefile for the state.


I am using python. Can someone guide me about how to approach this problem?enter image description here



Answer



The quickest way that I am aware of, is to use the Shapely library (requires the GEOS Engine, you can find a one-click installer for shapely here if you're on windows)



The manual provides a dead-on example of what your question:


>>> from shapely.geometry import Point
>>> a = Point(1, 1).buffer(1.5)
>>> b = Point(2, 1).buffer(1.5)
>>> c = a.intersection(b)
>>> c.area
4.11619859013966

No comments:

Post a Comment

arcpy - Changing output name when exporting data driven pages to JPG?

Is there a way to save the output JPG, changing the output file name to the page name, instead of page number? I mean changing the script fo...