Jesus Loves GRASS

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

Friday, May 18, 2007

GML information in array form

The GML information is structured like this in the $key (dump programmin in the post below)

Keys array

Array
(
[SCHEMA] => Array
(
[0] => 0
[1] => 2
[2] => 4
[3] => 50
[4] => 51
)

[IMPORT] => Array
(
[0] => 1
)

[ELEMENT] => Array
(
[0] => 3
[1] => 9
[2] => 11
[3] => 13
[4] => 15
[5] => 17
[6] => 19
[7] => 21
[8] => 23
[9] => 25
[10] => 27
[11] => 29
[12] => 31
[13] => 33
[14] => 35
[15] => 37
[16] => 39
[17] => 41
)

[COMPLEXTYPE] => Array
........................ (more) .............

The number indicated by the key and the nested arrays is the location of of the specific tags inside the values array, for example the data from the first ELEMENT Tag will be in position 3 of the $Values array ([ELEMENT] => Array([0] => 3....)
Values array

Array
(
:
:
:
[3] => Array
(
[tag] => ELEMENT
[type] => complete
[level] => 2
[attributes] => Array
(
[NAME] => major_cities
[TYPE] => ms:major_citiesType
[SUBSTITUTIONGROUP] => gml:_Feature
)

)
:
:

An example to fetch the NAME data from the first ELEMENT would be:
$values[$keys["ELEMENT"][0]]["attributes"]["NAME"]

or using a more sofisticate approach with the point functions of PHP:
$values[reset($keys["ELEMENT"])]["attributes"]["NAME"]

This is not as sofisticates as the XML-DOM system but it works fine.

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: , , , ,