Class CapReader
Reads CAP 1.2 marine weather warnings in the three forms the NWS and other
alerting authorities publish (design note docs/design/weather-sources.md ยง6.1):
public static class CapReader
- Inheritance
-
CapReader
- Inherited Members
Remarks
-
CAP XML: one
<alert>in the CAP 1.2 namespace (urn:oasis:names:tc:emergency:cap:1.2; 1.1 and 1.0 read the same). -
Atom: a feed whose entries each hold a whole
<alert>, or, asapi.weather.gov/alerts.atomwrites them, carry the alert's fields ascap:elements of the entry itself (one info, one area), with the identifier in the entry'sid, the headline in itstitleand the description in itssummary. -
NWS GeoJSON: an alert feature, or a feature collection of them, as
api.weather.gov/alertsreturns them. The feature's geometry is the area's polygon;endsis Ends.
Elements are matched by local name, so a producer's namespace prefix
doesn't matter. Unknown elements are ignored. A polygon or
circle that can't be read is skipped rather than failing the file.
Fields
AtomNamespace
The Atom namespace.
public const string AtomNamespace = "http://www.w3.org/2005/Atom"
Field Value
Cap12Namespace
The CAP 1.2 XML namespace.
public const string Cap12Namespace = "urn:oasis:names:tc:emergency:cap:1.2"
Field Value
CapNamespacePrefix
The start every CAP namespace shares (1.0, 1.1 and 1.2).
public const string CapNamespacePrefix = "urn:oasis:names:tc:emergency:cap:"
Field Value
Methods
IsCapRoot(string, string, string)
Whether an XML root element (its namespace and local name, and the
document's first characters) is CAP: an alert in a CAP namespace,
or an Atom feed whose text declares the CAP namespace.
public static bool IsCapRoot(string namespaceUri, string localName, string documentPrefix)
Parameters
namespaceUristringThe root's namespace URI.
localNamestringThe root's local name.
documentPrefixstringThe start of the document, or its whole text.
Returns
LooksLikeCap(ReadOnlySpan<byte>)
Whether leadingBytes, the start of a file, look like
CAP: an XML document whose root is a CAP alert, or an Atom
feed that declares the CAP namespace; or JSON from
api.weather.gov that names an alert (wx:Alert or an
/alerts/ URL). Used to detect CAP files whatever their extension.
public static bool LooksLikeCap(ReadOnlySpan<byte> leadingBytes)
Parameters
leadingBytesReadOnlySpan<byte>The file's first bytes; a kilobyte is enough for the NWS forms.
Returns
Remarks
An S-100 GML dataset (S-124 and the others) has a DataSet root in
an S-100 namespace, so it is never CAP; GeoJSON from anywhere other than
api.weather.gov isn't claimed.
ParseCircle(string)
Parses a CAP circle: latitude,longitude radius, the radius in kilometres.
public static CapCircle? ParseCircle(string text)
Parameters
textstringThe element's text.
Returns
ParsePolygon(string)
Parses a CAP polygon: space-separated latitude,longitude
pairs, the first and last the same. A ring that isn't closed is closed.
public static IReadOnlyList<GeoPosition>? ParsePolygon(string text)
Parameters
textstringThe element's text.
Returns
- IReadOnlyList<GeoPosition>
The ring, or null when it has fewer than three distinct positions or can't be read.
Read(Stream)
Reads CAP from stream, which is left open.
public static CapDocument Read(Stream stream)
Parameters
streamStreamThe stream, read to its end.
Returns
- CapDocument
The alerts.
Exceptions
- CapFormatException
The stream isn't CAP XML, a CAP Atom feed or NWS alert GeoJSON.
Read(ReadOnlySpan<byte>)
Reads CAP from bytes.
public static CapDocument Read(ReadOnlySpan<byte> bytes)
Parameters
bytesReadOnlySpan<byte>The file's bytes.
Returns
- CapDocument
The alerts.
Exceptions
- CapFormatException
The bytes aren't CAP XML, a CAP Atom feed or NWS alert GeoJSON.
Read(string)
Reads a CAP file.
public static CapDocument Read(string path)
Parameters
pathstringThe file's path.
Returns
- CapDocument
The alerts.
Exceptions
- CapFormatException
The file isn't CAP XML, a CAP Atom feed or NWS alert GeoJSON.