I have to plot polygons based on site 'regions'. I want a line that goes around the outside of a region to define it's perimeter.
Here is my code:
#Import the source data and libraries
import pandas as pd
import geopandas as gpd
import folium
from shapely.geometry import Polygon
df = pd.read_csv('tacs.csv')
#Extract the lat long lists from the datasource
lat_point_list = df['magnet.latitude'].tolist()
lon_point_list = df['magnet.longitude'].tolist()
#Some wizardry
polygon_geom = Polygon(zip(lon_point_list, lat_point_list))
crs = {'init': 'epsg:4326'}
polygon = gpd.GeoDataFrame(index=[0], crs=crs, geometry=[polygon_geom])
#output to files
polygon.to_file(filename='polygon.geojson', driver='GeoJSON')
polygon.to_file(filename='polygon.shp', driver="ESRI Shapefile")
#plot on a map with central point being birmingham
m = folium.Map([51.509865, -0.118092], zoom_start=12, tiles='cartodbpositron')
folium.GeoJson(polygon).add_to(m)
folium.LatLngPopup().add_to(m)
m
The issue is, it comes out like the below. It's not a line around the perimeter, rather a big mess of interconnecting points.
Any ideas how I can get around this?
