Created
September 20, 2018 01:51
-
-
Save mappingvermont/6ced994b8e5d9a3c85e53e51ed6ae4bf to your computer and use it in GitHub Desktop.
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
import json | |
def main(): | |
tile_list = ['000E_00N_010E_10N', '000E_10N_010E_20N', '000E_10S_010E_00N', '000E_20N_010E_30N', '010E_00N_020E_10N', '010E_10N_020E_20N', '010E_10S_020E_00N', '010E_20N_020E_30N', '010E_20S_020E_10S', '010E_30S_020E_20S', '010W_00N_000E_10N', '010W_10N_000E_20N', '010W_20N_000E_30N', '020E_00N_030E_10N', '020E_10N_030E_20N', '020E_10S_030E_00N', '020E_20N_030E_30N', '020E_20S_030E_10S', '020E_30S_030E_20S', '020W_00N_010W_10N', '020W_10N_010W_20N', '020W_20N_010W_30N', '030E_00N_040E_10N', '030E_10N_040E_20N', '030E_10S_040E_00N', '030E_20N_040E_30N', '030E_20S_040E_10S', '030E_30S_040E_20S', '030W_10N_020W_20N', '040E_00N_050E_10N', '040E_10N_050E_20N', '040E_10S_050E_00N', '040E_20N_050E_30N', '040E_20S_050E_10S', '040E_30S_050E_20S', '050E_00N_060E_10N', '050E_10N_060E_20N', '050E_10S_060E_00N', '050E_20N_060E_30N', '050E_20S_060E_10S', '050E_30S_060E_20S'] | |
out_gj = {"type":"FeatureCollection","features":[]} | |
for t in tile_list: | |
split = t.split('_') | |
bottom_left_x = parse_coord(split[0]) | |
bottom_left_y = parse_coord(split[1]) | |
top_right_x = parse_coord(split[2]) | |
top_right_y = parse_coord(split[3]) | |
feat = {'type': 'Feature', | |
'properties': {'name': t}, | |
'geometry': { | |
'type': 'Polygon', | |
'coordinates': [[ | |
[bottom_left_x, bottom_left_y], | |
[bottom_left_x + 10, top_right_y - 10], | |
[top_right_x, top_right_y], | |
[top_right_x - 10, bottom_left_y + 10], | |
[bottom_left_x, bottom_left_y] | |
]]}} | |
out_gj['features'].append(feat) | |
with open('out.geojson', 'w') as out: | |
json.dump(out_gj, out) | |
def parse_coord(coord): | |
if 'W' in coord or 'S' in coord: | |
output = '-' | |
else: | |
output = '' | |
try: | |
output += str(int(coord[0:3])) | |
except ValueError: | |
output += str(int(coord[0:2])) | |
return int(output) | |
if __name__ == '__main__': | |
main() | |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment