PySOS
Python SOS server for serving relational data
Introduction
PySOS serves data in a relational database through the SOS interface, and is written entirely in Python.We've deployed PySOS for serving data for NANOOS and the Center for Coastal Margin Observation and Prediction using Apache and PostgreSQL. Our own implementation is up and accessible. Here are some sample queries:
Capabilities
DescribeSensor
GetObservation: Latest
Get Observation: Time Range
GetObservation: Specific Time
GetObservation: Bounding Box
Background
Unlike the Perl/RDBMS Cookbook, PySOS assumes all relevant data is stored in your database -- platforms, sensors, variables, and metadata -- as well as the raw observations. Therefore, there is no need to duplicate one's metadata in both your database and the SOS XML files; the XML is generated dynamically. Also, PySOS is a complete server -- the only code that needs to be written is four SQL statements corresponding to 1) offerings (i.e., platforms), 2) observedproperties (i.e., variables associated with each platform), 3) sensors (i.e., instruments associated with platforms, or just the platform itself), and 4) observations (i.e., observations associated with a platform and variable).
If one's data is already in an RDBMS, this prototype should be deployable without much effort. Simply provide a SQL statement (or better yet, write a view) for each of four SOS concepts in the config file, ensuring they return tuples with the following schemes:
- sos_offering(description, offering, srid, xmin, ymin, xmax, ymax, starttime, endtime, uri, featureOfInterest)
- sos_observedproperty(offering, observedProperty, variable, mmiuri, featureOfInterest, uom)
- sos_sensor(description, offering, srid, xmin, ymin, xmax, ymax, starttime, endtime, uri, featureOfInterest)
- sos_observation(offering, observedProperty, time, lat, lon, depth, value)
I emulate these tables using views, so the queries in my config file are especially simple; e.g.
SELECT * FROM sos_offering
where sos_offering is a view defined over our OOSDB schema. For more information about the design of the schema, review a set of slides gleaned from a presentation to the Portland PostgreSQL user's group.
Installing PySOS
- Download PySOS,
- Install PostgreSQL, Python, Apache, mod_python, and PyGreSQL.
- Configure mod_python sos.py supplies its own handler, so you will not be using the default "publisher.handler" as per the mod_python installation instructions. However, its a good idea to get mod_python installed, tested, and working before moving on to configuring pysos. Also, I set the handler to capture all requests, not just .py. Finally, you may need to change the PythonPath to include the directory where pysos can be found.
- Unzip pysos.tar.gz to your web server
- Edit config.py, changing the application paths, and maybe the queries if you're not using the sample database.
For example:
<Directory /usr/local/apache2/htdocs/pysos>
AddHandler mod_python
DirectoryIndex index.html index.py
PythonHandler sos
PythonDebug On
PythonPath "['//usr/local/apache2/htdocs/pysos/'] + sys.path"
</Location>
Check over the config file carefully. In addition to the four main queries, you will need to specify the filter expressions for bounding box queries and time queries, as these may be specific to your environment. We use PostGIS for spatial data processing. Contact howeb AT stccmop.org with questions about the config file.
The current version is designed to work with Postgresql. You can modify the connection object in sos.py to use a different db or connection library. There will soon be a version released that works with both postgresql and mysql.
Installing OOSDB Sample
- Download the schema and sample data,
- Ensure PostgreSQL is installed
- Install postGIS
- Unzip OOSDB.tar.gz to any directory
- Verify the paths in the createOOSDB script, then run it
correction for example in #3
Posted by
mcalder
at
2008-05-27 14:47
AddHandler should be
AddHandler mod_python .py
The createOOSDB script needs to load OOSDBschema.sql first, not OOSDB.sql (which does not exist).