# Author: jamie.vleeshouwer@csiro.au def getScale(areaBounds_ha): # Note areaBounds_ha is the size of the polygon's bounds, not to size of the polygon itself. area_m2 = areaBounds_ha * 10000 maxSize_MB = 1024 # Maximum file size resolutions = [1,2,5,10,15,30,50,100,250,500,1000,5000,10000] # Common resolutions ranging from 1m to 10km pixelSize_b = 32 # Size of a floating point number pixelsAvailable = maxSize_MB * 1024 * 1024 / pixelSize_b # The number of pixels that can be packed into the file size for the given datatype # Find the first resolution that fits within the file size constraint bestScaleToFit = [resolution for resolution in resolutions if area_m2 / (resolution * resolution) <= pixelsAvailable][0] return bestScaleToFit # Testing #fieldBoundSize_ha = 150 # Cotton field #fieldBoundSize_ha = 850 #fieldBoundSize_ha = 3500 #fieldBoundSize_ha = 90000000 # NSW #fieldBoundSize_ha = 1500000000 # Australia fieldBoundSize_ha = 52000000000 # Earth scale = getScale(fieldBoundSize_ha) print(scale)
Run
Reset
Share
Import
Link
Embed
Language▼
English
中文
Python Fiddle
Python Cloud IDE
Follow @python_fiddle
Browser Version Not Supported
Due to Python Fiddle's reliance on advanced JavaScript techniques, older browsers might have problems running it correctly. Please download the latest version of your favourite browser.
Chrome 10+
Firefox 4+
Safari 5+
IE 10+
Let me try anyway!
url:
Go
Python Snippet
Stackoverflow Question