Take the 2-minute tour ×
Geographic Information Systems Stack Exchange is a question and answer site for cartographers, geographers and GIS professionals. It's 100% free, no registration required.

I'm experimenting with MapServer and SOS but I'm not getting back any useful data from the GetObservation call I'm doing. My .map file uses a Postgres query to get data and when I run that same query in PGAdmin I get the four columns I expect: id, geom, date and total_alkalinity_value. All the columns have the right data. Below is the getObservation response in which I see only the gml:boundedBy and ms:msGeometry values, no sign of the id or total_alkalinity_value.

<om:ObservationCollection xmlns:gml="http://www.opengis.net/gml" xmlns:ows="http://www.opengis.net/ows/1.1" xmlns:swe="http://www.opengis.net/swe/1.0.1" xmlns:xlink="http://www.w3.org/1999/xlink" xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance" xmlns:sos="http://www.opengis.net/sos/1.0" xmlns:ms="http://mapserver.gis.umn.edu/mapserver" xmlns:om="http://www.opengis.net/om/1.0" gml:id="WQIS_TOTAL_ALKALINITY" xsi:schemaLocation="http://www.opengis.net/om/1.0 http://schemas.opengis.net/om/1.0.0/om.xsd http://mapserver.gis.umn.edu/mapserver http://wqis-sos.test.niwa.co.nz/cgi-bin/wqis-sos?service=WFS&amp;version=1.1.0&amp;request=DescribeFeatureType&amp;typename=total_alkalinity">
<om:member>
<om:Observation>      
  <om:samplingTime>
    <gml:TimeInstant>
      <gml:timePosition>1989-04-12</gml:timePosition>
    </gml:TimeInstant>
  </om:samplingTime>
  <om:procedure xlink:href="urn:ogc:def:procedure:80"/>
  <om:observedProperty>
    <swe:CompositePhenomenon gml:id="total_alkalinity_value" dimension="3">
      <swe:component xlink:href="urn:ogc:def:property:OGC-SWE:1:id"/>
      <swe:component xlink:href="urn:ogc:def:property:OGC-SWE:1:date"/>
      <swe:component xlink:href="urn:ogc:def:property:OGC-SWE:1:total_alkalinity_value"/>
    </swe:CompositePhenomenon>
  </om:observedProperty>
  <om:featureOfInterest xlink:href="http://wqis-sos.test.niwa.co.nz/cgi-bin/wqis-sos?service=WFS&amp;version=1.1.0&amp;request=DescribeFeatureType&amp;typename=total_alkalinity"/>
  <om:result>
    <gml:featureMember>
      <ms:total_alkalinity>
        <gml:boundedBy>
          <gml:Envelope srsName="urn:ogc:crs:epsg:4326" srsDimension="2">
            <gml:lowerCorner>167.294382 -46.243591</gml:lowerCorner>
            <gml:upperCorner>167.294382 -46.243591</gml:upperCorner>
          </gml:Envelope>
        </gml:boundedBy>
        <ms:msGeometry>
          <gml:Point srsName="urn:ogc:crs:epsg:4326" srsDimension="2">
            <gml:pos>167.294382 -46.243591</gml:pos>
          </gml:Point>
        </ms:msGeometry>
      </ms:total_alkalinity>
    </gml:featureMember>
  </om:result>
</om:Observation>
</om:member>
</om:ObservationCollection>

And here is the relevant stuff from the layer part of the .map file LAYER .... METADATA .... "sos_timeitem" "date" "sos_procedure" "ALKALINITY_SENSOR" "sos_procedure_item" "total_alkalinity_value" "sos_offering_id" "WQIS_TOTAL_ALKALINITY" "sos_observedproperty_id" "Total Alkalinity" "sos_describesensor_url" "http://wqis-sos.test.niwa.co.nz/ALKALINITY_SENSOR.xml"

TYPE POINT
STATUS ON
NAME "total_alkalinity"
DUMP TRUE
DEBUG 0

CONNECTIONTYPE POSTGIS
CONNECTION XXXXX
DATA "geom from (
    SELECT se.id AS id,
         l.geom AS geom,
         CASE WHEN COALESCE ((se.start_date).month, 0) = 0
              THEN
                (se.start_date).year::CHAR(4)
              WHEN COALESCE ((se.start_date).day, 0) = 0
              THEN
                (se.start_date).year || '-' || (se.start_date).month || '-01'
              ELSE
                (se.start_date).year || '-' || (se.start_date).month || '-' || (se.start_date).day
         END::DATE AS date,
         av.value::NUMERIC AS total_alkalinity_value
    FROM XXXXXXXX
) AS se USING UNIQUE id USING SRID=4326"

So my question is: How do I get id and total_alkalinity_value in my getObservation response?

*updated to show more of the .map file and add sos_dateitem*

*Now that I have the sos_procedure_item set to total_alkalinity_value the om:procedure element contains the data value (in this response it is 80), but that seems like totally the wrong place for it*

share|improve this question
add comment

1 Answer

up vote 0 down vote accepted

Ive not worked with the SOS Server, but it looks like it needs to have METADATA configured to work correctly as with the rest of the OGC services. If these have not been set or are incorrect then attributes can go missing.

At the top of your MAP file you need the following in the WEB section:

METADATA
  "sos_onlineresource" "http://127.0.0.1/cgi-bin/mapserv.exe?map=D:/ms4w/apps/sos/sos_test.map" ## REQUIRED
  "sos_title"          "My SOS Demo Server" ## Recommended
  "sos_srs"            "EPSG:4326" ## REQUIRED
  "sos_enable_request" "*" # Necessary
END

And also METADATA in the LAYER definition:

  LAYER
    NAME "test_sos_layer"
    METADATA
      "sos_timeitem" "DATE"  # YOUR DATE FIELD
      "sos_procedure"  "NS01EE0014" ## REQUIRED
      "sos_offering_id" "WQ1289" ## REQUIRED
      "sos_observedproperty_id" "Water Quality" ## REQUIRED
      "sos_describesensor_url" "http://some/url/NS01EE0014.xml" ## REQUIRED
    END

http://mapserver.org/ogc/sos_server.html

A more detailed way to see what should be happening is to look at the MapServer unit tests. For example the following MAP file:

http://trac.osgeo.org/mapserver/browser/trunk/msautotest/wxs/sos.map

Should produce the following output for a getObservation request:

http://trac.osgeo.org/mapserver/browser/trunk/msautotest/wxs/expected/sos_getobs_all.xml

Based on the obs.shp shapefile in:

http://trac.osgeo.org/mapserver/browser/trunk/msautotest/wxs/data

The same test data can be seen in the CSV file at:

http://trac.osgeo.org/mapserver/browser/trunk/msautotest/wxs/data/obs.csv

Try this example, and gradually change the definitions to match your data. If you really want to find out what is happening then browse the sourcecode or run with a debugger on the source.

share|improve this answer
    
I was missing the sos_timeitem metadata but I had the rest. With that one added I now get a samplingTime element in the response (I've updated the question to show this) but still no data value. I also added sos_procedure_item even though it is optional so it should work without it. That only served to change the procedure to "80" instead of "ALKALINITY_SENSOR" –  Craig Mar 6 '12 at 20:01
    
Actually that 80 is the total_alkalinity_value for this response, but that can't be the right place for it. In the other examples I've seen the data value is within the "om:result" element –  Craig Mar 6 '12 at 20:47
    
@craig It looks like it should be. I've update my answer - try running with the test data to check it works with postGIS. –  geographika Mar 6 '12 at 22:52
    
In the example data you linked to the procedure element was giving the stn_id (station id) and nested in the om:Result was a ms:Value which is the data that I am trying to set. But thanks to the other sample files (sos.map and obs.shp) I saw that changing my SQL to include the line "av.value::NUMERIC AS Value" gave me the output I wanted. Thanks for pointing me that way –  Craig Mar 7 '12 at 3:09
add comment

Your Answer

 
discard

By posting your answer, you agree to the privacy policy and terms of service.

Not the answer you're looking for? Browse other questions tagged or ask your own question.