I have a question regarding the inaccuracy in calculated area by Python and actual value. I searched a lot about it but I didn't find anything. I'm afraid that this difference made my next calculations inaccurate. Here is the code that I calculated with it the area of a circle with radius 1.5:
from shapely.geometry import Point, Polygon
a = Point(1, 1).buffer(1.5)
print (a.area)
and the result that I got is:
7.05723410373
But the actual value for area of the circle with radius 1.5 is:
pi()*(1.5^2) = 7.0685834705
Can anybody explain this difference for me? Should I change any default value on my computer? Also here is the pi()
value of my computer:
import math
print (math.pi)
which is exactly as same as actual pi()
value:
3.14159265359
From the Shapely User Manual :
object.buffer(distance, resolution=16, cap_style=1, join_style=1, mitre_limit=1.0)
Returns an approximate representation of all points within a given distance of the this geometric object.
Per the documentation, the returned value is only an approximation. A bit further down in the document is a circle example:
The default (resolution of 16) buffer of a point is a polygonal patch with 99.8% of the area of the circular disk it approximates.
>>> p = Point(0, 0).buffer(10.0)
>>> len(p.exterior.coords)
66
>>> p.area
313.65484905459385
Again, the documentation states it is only an approximation. 99.8% of 7.068, the actual value with a radius of 1.5, is approximately 7.054, which is the value shapely is calculating.
You can increase the accuracy by passing in a higher resolution:
a = Point(1, 1).buffer(1.5, resolution=32)
The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.