mirror of
https://github.com/GSA/notifications-api.git
synced 2025-12-21 07:51:13 -05:00
If a polygon is smaller than the largest polygon in our dataset of simplified polygons then we’re only throwing away useful detail by simplifying it. We should still simplify larger polygons as a fallback, to avoid sending anything to the CBC that we’re not sure it will like. The thresholds here are low: we can raise them as we test and experiment more. Here’s some data about the Flood Warning Service polygons Percentile | 80% | 90% | 95% | 98% | 99% | 99.9% -----------|-----|-------|--------|---------|---------|--------- Point count| 226 | 401.9 | 640.45 | 1015.38 | 1389.07 | 3008.609 Percentile | 80% | 90% | 95% | 98% | 99% | 99.9% --------------|-----|-------|--------|---------|---------|--------- Polygon count |2----|3------|5-------|8--------|10-------|40.469
34 lines
1004 B
Python
34 lines
1004 B
Python
from bs4 import BeautifulSoup
|
||
|
||
|
||
def cap_xml_to_dict(cap_xml):
|
||
# This function assumes that it’s being passed valid CAP XML
|
||
cap = BeautifulSoup(cap_xml, "xml")
|
||
return {
|
||
"msgType": cap.alert.msgType.text,
|
||
"reference": cap.alert.identifier.text,
|
||
"cap_event": cap.alert.info.event.text,
|
||
"category": cap.alert.info.category.text,
|
||
"expires": cap.alert.info.expires.text,
|
||
"content": cap.alert.info.description.text,
|
||
"areas": [
|
||
{
|
||
"name": area.areaDesc.text,
|
||
"polygons": [
|
||
cap_xml_polygon_to_list(polygon.text)
|
||
for polygon in area.find_all('polygon')
|
||
]
|
||
}
|
||
for area in cap.alert.info.find_all('area')
|
||
]
|
||
}
|
||
|
||
|
||
def cap_xml_polygon_to_list(polygon_string):
|
||
return [
|
||
[
|
||
float(coordinate) for coordinate in pair.split(',')
|
||
]
|
||
for pair in polygon_string.strip().split(' ')
|
||
]
|