Skip to content

Instantly share code, notes, and snippets.

@lakshmanok
Created March 7, 2020 17:18
Show Gist options
  • Save lakshmanok/26c7276fdaab495ec55b8c71739125d6 to your computer and use it in GitHub Desktop.
Save lakshmanok/26c7276fdaab495ec55b8c71739125d6 to your computer and use it in GitHub Desktop.
def create_geo(LATRES, LONRES, ORIGIN_LAT, ORIGIN_LON, rowno, startcol, endcol):
# represent each rectangle by a polygon of its corners
top = ORIGIN_LAT - rowno * LATRES
bot = ORIGIN_LAT - (rowno+1) * LATRES
left = ORIGIN_LON + startcol * LONRES
right = ORIGIN_LON + endcol * LONRES
poly = json.dumps({
'type': 'Polygon',
'coordinates': [
[ # polygon 1
[left, top], # topleft
[left, bot], # botleft
[right, bot], # botright
[right, top], # topright
[left, top] # same as first point
]
]
})
center = 'POINT({:2f} {:2f})'.format( (left+right)/2, (top+bot)/2 )
return poly, center, endcol
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment