This application provides basic functionality for a Web Feature Service (WFS) which allows advanced searches on the GeoNet earthquake catalogue. WFS is an Open Geospatial Consortium (OGC) standard to allow web-based access to geographical data.
Below are some sample queries for retrieving earthquake data from the WFS in CSV, JSON, GML and KML formats.
The earthquake catalogue is stored so that the most recent data is returned first. You can easily retrieve the last 50 quakes in the New Zealand region in a variety of formats:
It is not recommended to get all quakes in one request due to system capacity,
please use the cql_filter
below to build your request, e.g.:
http://wfs.geonet.org.nz/geonet/ows?service=WFS&version=1.0.0&request=GetFeature&typeName=geonet:quake_search_v1&outputFormat=csv&cql_filter=origintime>='2020-01-01'+AND+origintime<'2021-01-01'
To download all quakes by separate http requests, see this script:
#!/bin/bash -eu
#
# download all quakes from WFS and save data in a single csv file
#
[ ! -e data ] && mkdir data
cd data/
outPutFile="wfs_all.csv"
outPutTemp="temp.csv"
[ -e $outPutFile ] && rm $outPutFile
wfsURL="https://wfs.geonet.org.nz/geonet/ows?service=WFS&version=1.0.0&request=GetFeature&typeName=geonet:quake_search_v1&outputFormat=csv&cql_filter="
start=1980
end=$(date '+%Y')
end=$(($end + 1))
previousYear=$start
echo "### START downloading WFS data..."
#download data year by year
for ((year=$start; year<=$end; year+=1)); do
if [ $year == $start ]; then
url="${wfsURL}origintime<'${year}-01-01'"
curl -s $url
else
if [ $year == $end ]; then
url="${wfsURL}origintime>='${previousYear}-01-01'"
else
url="${wfsURL}origintime>='${previousYear}-01-01'+AND+origintime<'${year}-01-01'"
fi
curl -s $url|tail +2
fi
previousYear=$year
done>$outPutTemp
#sort by modificationtime
(head -n 1 $outPutTemp && tail -n +2 $outPutTemp | sort -k4,4 -t ',') >$outPutFile
rm $outPutTemp
echo "### DONE data saved to data/$outPutFile"
To download quakes after a specified modificationtime
, see
this script:
# download quakes from WFS for specified modification time and save data in a single csv file
# the modificationtime can be specified as
# 1. command line argument
# 2. extracted from existing data file (if no argument specified), e.g. earthquakes.csv
# usage: ./wfs_modified.sh 2021-01-01T00:21:59.311Z
#
dataFile="earthquakes.csv"
outPutFile="earthquakes_new.csv"
tempFile="earthquakes_temp.csv"
date=''
[ ! -e data ] && mkdir data
cd data/
#check cmd args
if [ ! $# -eq 0 ]; then
date=$1
else
if [ -e $dataFile ]; then
# extract from dataFile, last line, 4th cell
date=$(tail -n 1 ${dataFile} | cut -d ',' -f4)
fi
fi
if [ "$date" == "" ]; then
echo Error: please supply a date argument or a base data file data/$dataFile. Usage: ./wfs_modified.sh 2021-01-01T00:21:59.311Z
exit
fi
wfsURL="https://wfs.geonet.org.nz/geonet/ows?service=WFS&version=1.0.0&request=GetFeature&typeName=geonet:quake_search_v1&outputFormat=csv&cql_filter="
url="${wfsURL}modificationtime>'${date}'"
echo "### START downloading from ${url}"
[ -e $outPutFile ] && rm $outPutFile
# query data, remove header, sort by modificationtime and save
curl -s $url |tail -n +2 | (sort -k 4 -t ',')>$tempFile
if [ -e $dataFile ]; then
# concat and remove duplicate publicid
sort -t, -k1,1 -k4,4 -r -s $dataFile $tempFile| sort -t, -k1,1 -u -s|sort -t, -k4,4 -k3,3 -s>$outPutFile
rm $tempFile
else
mv $tempFile $outPutFile
fi
echo "### DONE data saved to data/$outPutFile"
You can make more complex queries using Contextual Query Language (CQL) to filter the results. Some examples are show below. The parameters and the output format can be adjusted in the URL. Also, see the CQL specification and the GeoServer CQL tutorial.
Note: when filtering with spatial queries filter on the origin_geom point type. The longitude and latitude columns are extracted from the origin_geom and provided in the output as a convenience for CSV users.
http://wfs.geonet.org.nz/geonet/wms/kml?layers=geonet:quake_search_v1&cql_filter=magnitude>6
NB. To search a polygon, you need to search a closed shape, i.e. the first longitude/latitude pair is repeated again at the end
NB. To search a polygon, you need to search a closed shape, i.e. the first longitude/latitude pair is repeated again at the end
The following date time formats are supported: