Jesus Loves GRASS

Technical blog about GRASS/GIS,open source geoinformatics and MAPSERVER.

Friday, May 18, 2007

WFS reply to DescribeFeatureType

This is the GML version 2 that the DescribeFeatureType will produce from a layer containing the most important cities of the study area:

<schema targetNamespace="http://mapserver.gis.umn.edu/mapserver" elementFormDefault="qualified" version="0.1">
<import namespace="http://www.opengis.net/gml" schemaLocation="http://schemas.opengis.net/gml/2.1.2/feature.xsd"/>
<element name="major_cities" type="ms:major_citiesType" substitutionGroup="gml:_Feature"/>
<complexType name="major_citiesType">
<complexContent>
<extension base="gml:AbstractFeatureType">
<sequence>
<element name="msGeometry" type="gml:GeometryPropertyType" minOccurs="0" maxOccurs="1"/>
<element name="cat" type="string"/>
<element name="AREA" type="string"/>
<element name="PERIMETER" type="string"/>
<element name="CITIES_" type="string"/>
<element name="CITIES_ID" type="string"/>
<element name="CITY_NAME" type="string"/>
<element name="GMI_ADMIN" type="string"/>
<element name="ADMIN_NAME" type="string"/>
<element name="FIPS_CNTRY" type="string"/>
<element name="CNTRY_NAME" type="string"/>
<element name="STATUS" type="string"/>
<element name="POP_RANK" type="string"/>
<element name="POP_CLASS" type="string"/>
<element name="PORT_ID" type="string"/>
<element name="AREA_1" type="string"/>
<element name="LEN" type="string"/>
</sequence>
</extension>
</complexContent>
</complexType>
</schema>

Labels: , ,

WFS XML verbose to Array structure

I was expecting for the WFS reply to be more "friendly" meaning the Mapserver dump in GML to be easily openned by other programs like ArcGIS. But is not the case....since my supervisor wants the results to be in CSV I have to send sometime on it.

Meanwhile I have a nice way of concerting the mapserver WFS reply to an array structure using PHP XML Parser (I should have used the XML-DOM parser but it was a bit to advanced..., also I couldn't find any nice class to deal with it in the website php classes)

(programming requesting the WFS layer)

$buffer = ms_iogetstdoutbufferstring();
ms_ioresethandlers();

//creation of the values and keys containing the DescribeFeatureType or GetFeature
$xp = xml_parser_create();
xml_parse_into_struct($xp,$buffer,$values_meta,$keys_meta);
xml_parser_free($xp);

//dumping all the array structure for checking
echo "Keys array_meta<br><br><pre>";
print_r($keys_data);
echo "</pre><br><br>Values array_meta<br><br><pre>";
print_r($values_data);
echo "</pre>";

The example is from the book "Beginning PHP5" and it was the simplest way I found to pass everything to arrays

Labels: , , , ,

Monday, April 16, 2007

WCS and WFS metadata

I forgot that aside from the information if the map is downloadable or not is is also necessary to know what service, so another metadata tag was added

METADATA
"ows_service" "wcs"
END

it can be "wcs" or "wfs"

The programming is basically the same for the download but simpler since is it only a property and it doesn't need functions like isDownload()

The getMetadata is a bit different because the wcs and wfs are string and need '', otherwise the javascript eval() will not work (this functions runs the init.php reply)

$ows_service = "null";
if ($oLayer->getMetaData ("ows_service") !="") {
if(strcasecmp($oLayer->getMetaData("ows_service"), "wcs") == 0)
$ows_service = "'wcs'";

if(strcasecmp($oLayer->getMetaData("ows_service"), "wfs") == 0)
$ows_service = "'wfs'";

}

Labels: , , ,

Thursday, April 05, 2007

WCS wrapper for Mapserver

WMS,WFS and WCS is how it is possible to connected to a webGIS server and to download data:
WMS == Raster as an image
WFS == Vectorial information
WCS == Raster as a layer (original raster with values)

The request of WxF is normally done by a GET to the Mapserv program (is like a normal CGI-BIN for program execution), well I don't want Apache to run any program, so the solution is a wrapper PHP script, where the script catches the requests and uses them for a valid WCS reply.

The wrapper is very simple and there is a basic example on the mapserver home page, This is a wrapper with small modifications to work with WCS:

<?php
/*ows.php?service=WCS&version=1.0.0&Request=GetCapabilities*/
$request = ms_newowsrequestobj();

//$request->loadparams();

foreach ($_GET as $k=>$v) {
$request->setParameter($k, $v);
}



// forcing to version 1.0.0
$request->setParameter("VeRsIoN","1.0.0");

ms_ioinstallstdouttobuffer();

$oMap = ms_newMapobj("/usr/local/apache2/htdocs/secure/ms/data/calter.map");
$oMap->owsdispatch($request);
$contenttype = ms_iostripstdoutbuffercontenttype();
$buffer = ms_iogetstdoutbufferstring();

header('Content-type: application/xml');
echo $buffer;

ms_ioresethandlers();

?>

For start Mapserver only suports WCS version 1.0.0 so any request for higher versions has to be redirect:
$request->setParameter("VeRsIoN","1.0.0");

There seems to be a bug with $request->loadparams(); this produces an empy file reply from the server with no errors, so the solution it to get the parameters directely from the GET
foreach ($_GET as $k=>$v) {
$request->setParameter($k, $v);
}

if replacing $_GET for $_POST is should be possible to use POST to request the WCS, mapserver only accepts GET.

Labels: , , , , ,