Download the PHP package cstuder/parse-hydrodaten without Composer

On this page you can find all versions of the php package cstuder/parse-hydrodaten. It is possible to download/install these versions without Composer. Possible dependencies are resolved automatically.

FAQ

After the download, you have to make one include require_once('vendor/autoload.php');. After that you have to import the classes with use statements.

Example:
If you use only one package a project is not needed. But if you use more then one package, without a project it is not possible to import the classes with use statements.

In general, it is recommended to use always a project to download your libraries. In an application normally there is more than one library needed.
Some PHP packages are not free to download and because of that hosted in private repositories. In this case some credentials are needed to access such packages. Please use the auth.json textarea to insert credentials, if a package is coming from a private repository. You can look here for more information.

  • Some hosting areas are not accessible by a terminal or SSH. Then it is not possible to use Composer.
  • To use Composer is sometimes complicated. Especially for beginners.
  • Composer needs much resources. Sometimes they are not available on a simple webspace.
  • If you are using private repositories you don't need to share your credentials. You can set up everything on our site and then you provide a simple download link to your team member.
  • Simplify your Composer build process. Use our own command line tool to download the vendor folder as binary. This makes your build process faster and you don't need to expose your credentials for private repositories.
Please rate this library. Is it a good library?

Informations about the package parse-hydrodaten

parse-hydrodaten

PHPUnit tests

Simple PHP package to parse Hydrodaten (FOEN/BAFU) Open Data strings.

Disclaimer: This library is not official and not affiliated with FOEN/BAFU.

Created for usage on api.existenz.ch and indirectly on Aare.guru. As of 2023 in productive use.

Installation

composer require cstuder/parse-hydrodaten

Example usage

The data is a row of value objects (See cstuder/parse-valueholder):

Metadata example usage

For getting a list of locations and parameters, use the metadata parser:

About the Hydrodaten measurement network

FOEN/BAFU (Swiss Federal Office for the Environment / Bundesamt für Umwelt der Schweiz) offers a selection of their Hydrological data data on the opendata.swiss portal.

Not every stations measures every parameter. Not every stations reports its data at the same time.

Periodicity: 10 minutes.

Licencing restrictions apply by FOEN/BAFU. See the Open Data download for information. FOEN/BAFU requires that all usage of the data always labels the FOEN/BAFU as source.

Additional links

Data files overview

There are multiple ways to access the current measurement values in different precisions and different formats. Some are password protected.

File URL Format Password protected Temperature precision Parseable by parse-hydrodaten Comment
Homepage www.hydrodaten.admin.ch HTML 0.1°
hydroweb.xml (Rounded, deprecated) www.hydrodaten.admin.ch/lhg XML 0.1° Yes No longer available. Contains both current values and 24h old ones.
hydroweb.xml (Precise) www.hydrodata.ch XML Yes 0.01° Yes
hydroweb.naqua.xml www.hydrodata.ch XML Yes 0.01° Yes NAQUA Groundwater Monitoring
SMS.xml - XML 0.01° Yes No longer available

Data file: hydroweb.xml (Rounded, deprecated)

Deprecated: No longer available as of june 2021.

Data is available without password, but rounded values (I.e. temperature values to a tenth degree.)

XML file with associated XSD schema containing a list of river measurement stations and their different parameters.

Note that this parser is only interested in the absolute measurement values (Current and 24h old). It ignores max/min/mean values.

The parser also ignores the variant attribute of the parameters.

Both data and metadata is in the same XML. Encoding is UTF-8. Timezone is Europe/Zurich (GMT+2).

Usage data parser

  1. Download the data from https://www.hydrodaten.admin.ch/lhg/az/xml/hydroweb.xml.
  2. Parse it:

Data file: hydroweb.xml (Precise version)

Data is password protected, but with precise values (I.e. temperature values to a hundreth degree.)

XML file with associated XSD schema containing a list of river measurement stations and their different parameters.

Note that this parser is only interested in the absolute current measurement values. It ignores max/min/mean values.

The parser also ignores the variant attribute of the parameters.

Both data and metadata is in the same XML. Encoding is UTF-8. Timezone is Europe/Zurich (GMT+2).

Usage data parser precise

  1. Contact the Abfragezentrale BAFU and ask for access to the file hydroweb.xml.
  2. You should get a username and password for the endpoint https://www.hydrodata.ch/data/xml/hydroweb.xml.
  3. Parse it:

Data file: hydroweb.naqua.xml (Precise version)

Groundwater measurement network, same data format as hydroweb.xml (Precise version). Data is password protected, but with precise values (I.e. temperature values to a hundreth degree.)

Usage data parser for NAQUA

Uses the same data parser as hydroweb.xml (Precise version).

  1. Contact the Abfragezentrale BAFU and ask for access to the file hydroweb.naqua.xml.
  2. You should get a username and password for the endpoint https://www.hydrodata.ch/data/xml/hydroweb.naqua.xml.
  3. Parse it:

Legacy format: SMS.xml

Deprecated: No longer available as of april 2021.

XML file without schema containing a list of river measurement stations and their different parameters.

Note that the legacy data parser is only interested in the absolute measurement values (Current and 24h old). It ignores max/min/mean values.

The parser also ignores the Var attribute of the parameters.

Both data is stored in this XML, no metadata. Encoding is UTF-8. Timezone is Europe/Zurich (GMT+2).

Usage legacy parser

Parser Methods

The parser is intentionally limited: It parses the given string and returns all absolute values which look valid. It silently skips over any value it doesn't understand.

Values are converted to float. Missing values are not returned, the values will never be null.

SuperParser::parse(string $raw)

Parses a Hydrodaten data string, tries out all available parsers one after another. If any of them finds anything, returns that data.

Returns an empty row if no parsers find anything. Use at your own risk.

Returns a row of value objects with the keys timestamp, loc, par, val.

DataParser::parse(string $raw)

Parses a Hydroweb XML string in the hydroweb.xsd format.

Returns a row of value objects with the keys timestamp, loc, par, val.

DataParserPrecise::parse(string $raw)

Parses a Hydroweb XML string in the hydroweb2.xsd format.

Returns a row of value objects with the keys timestamp, loc, par, val.

LegacyDataParser::parse(string $raw)

Parses a legacy Hydroweb XML string in the deprecated SMS.xml format.

Returns a row of value objects with the keys timestamp, loc, par, val.

MetadataParser::parse(string $raw)

Parses a Hydroweb XML string.

Returns two fields: locations and parameters, both containing arrays of StdClass objects with fields such as location coordinates or parameter units.

Testing

Run composer test to execute the PHPUnit test suite.

Releasing

  1. Add changes to the changelog.
  2. Create a new tag vX.X.X.
  3. Push.

License

MIT.

Author

Christian Studer [email protected], Bureau für digitale Existenz.


All versions of parse-hydrodaten with dependencies

PHP Build Version
Package Version
Requires cstuder/parse-valueholder Version ^0.2
Composer command for our command line client (download client) This client runs in each environment. You don't need a specific PHP version etc. The first 20 API calls are free. Standard composer command

The package cstuder/parse-hydrodaten contains the following files

Loading the files please wait ....