-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathfirst_map.py
More file actions
49 lines (44 loc) · 1.45 KB
/
first_map.py
File metadata and controls
49 lines (44 loc) · 1.45 KB
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
43
44
45
46
47
48
49
import pandas as pd
import geopandas
import geopandas.tools
from shapely.geometry import Point
from shapely.geometry import Polygon
from geopandas.geoseries import GeoSeries
import matplotlib.pyplot as plt
#path = "./shapes.txt"
#shapes_df = pd.read_csv(path, index_col = 0)
import shapefile
path = "../SHAPE/Zonizzazione.dbf"
sf = shapefile.Reader(path)
shapes = sf.shapes()
ID = 0
shapes_df = pd.DataFrame(columns = ["shape_id", "shape_pt_lat", "shape_pt_lon"])
for shape in sf.iterShapes():
for point in shape.points:
# print point[0], point[1]
s = pd.Series()
s.loc["shape_id"] = ID
s.loc["shape_pt_lat"] = float(point[0])
s.loc["shape_pt_lon"] = float(point[1])
shapes_df = pd.concat([shapes_df, pd.DataFrame(s).T], ignore_index=True)
ID += 1
pl = []
for shape_id, group in shapes_df.groupby("shape_id"):
print shape_id
group["geometry"] = \
group.apply(lambda row: (row["shape_pt_lon"], row["shape_pt_lat"]), axis=1)
pl += [Polygon(list(group["geometry"].values))]
s = GeoSeries(pl).convex_hull
s.plot()
plt.show()
#import gmplot
#
#gmap = gmplot.GoogleMapPlotter(45.116177, 7.742615, 16)
#
#gmap.scatter(shapes_df["shape_pt_lat"][shapes_df.shape_id == 1640],\
# shapes_df["shape_pt_lon"][shapes_df.shape_id == 1640],\
# '#3B0B39', marker=False)
##gmap.scatter(marker_lats, marker_lngs, 'k', marker=True)
##gmap.heatmap(heat_lats, heat_lngs)
#
#gmap.draw("mymap.html")