46 lines
1.3 KiB
Python
46 lines
1.3 KiB
Python
import requests
|
|
import geopandas as gpd
|
|
#import folium
|
|
import matplotlib.pyplot as plt
|
|
from capparselib.parsers import CAPParser
|
|
|
|
from xml.etree import ElementTree
|
|
|
|
from shapely.geometry import Point, Polygon
|
|
|
|
import contextily as ctx
|
|
|
|
|
|
linktext = requests.get('http://forms.smn.gob.ar/feeds/CAP/oladecalor/87765_cap_en.xml')
|
|
alert_list = CAPParser(linktext.text).as_dict()
|
|
polyList = list()
|
|
|
|
if 'cap_area' in alert_list[0]['cap_info'][0]:
|
|
for area in alert_list[0]['cap_info'][0]['cap_area']:
|
|
for polygon_str in area['polygons']:
|
|
polygon_str_tokens = str(polygon_str).split(' ')
|
|
points = list()
|
|
for token in polygon_str_tokens:
|
|
coords_str = token.split(',')
|
|
if coords_str[0] != '':
|
|
x_coord = float(coords_str[1])
|
|
y_coord = float(coords_str[0])
|
|
points.append(Point(x_coord, y_coord))
|
|
|
|
polyList.append(Polygon(points))
|
|
|
|
crs = {'init': 'epsg:4326'}
|
|
|
|
|
|
|
|
for poly in polyList:
|
|
geo_poly = gpd.GeoSeries(poly, crs=crs)
|
|
geo_poly.crs = 'epsg:4326'
|
|
|
|
area_gdf = gpd.GeoDataFrame(geometry=geo_poly)
|
|
ax = area_gdf.plot(alpha=0.5)
|
|
ctx.add_basemap(ax, zoom=10, crs='EPSG:4326',source=ctx.providers.CartoDB.Positron)
|
|
#ax.set_axis_off()
|
|
|
|
plt.show()
|