-
Notifications
You must be signed in to change notification settings - Fork 2
/
state_mapper.py
42 lines (34 loc) · 1.5 KB
/
state_mapper.py
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
import numpy as np
import matplotlib.pyplot as plt
from mpl_toolkits.basemap import Basemap
import math
state_boundries_file_loc = 'Data/stateboundries.csv'
states_shapefile_loc = 'Data/States_shapefiles/tl_2014_us_state'
class Mapper:
def __init__(self, state):
with open(state_boundries_file_loc) as f:
for line in f:
line = line.rstrip().split(',')
if line[0].lower() == state.lower():
ur_lon, ll_lat = float(line[1]), float(line[3])
ll_lon, ur_lat = float(line[2]), float(line[4])
center_lon = ll_lon + ur_lon
if math.copysign(1, ll_lon) != math.copysign(1, ur_lon):
center_lon = -180 + center_lon
else:
center_lon = center_lon / 2
center_lat = (ll_lat + ur_lat) / 2
self.m = Basemap(llcrnrlon = ll_lon, llcrnrlat = ll_lat,
urcrnrlon = ur_lon, urcrnrlat = ur_lat,
projection = 'lcc', lat_1 = center_lat,
lon_0 = center_lon)
def setBorders(self):
self.m.readshapefile(states_shapefile_loc,
'states', drawbounds = True)
def plotPoint(self, lat, lon):
self.m.plot(lat, lon, latlon=True, marker='o', color='m')
def displayMap(self):
plt.show()
if __name__ == '__main__':
m = Mapper('South Carolina')
m.displayMap()