Jesus Loves GRASS

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

Friday, May 25, 2007

google maps

I had to make a google map with the locations of hotel for the participants of the AEMP2007 congress. The API of google maps is very simple:
1) Creation of the map including center point and zoom used
2) Include controls
3) Creation of the Icons to be used
4) Adding a point to the map and making a marker (clicking the point it will display HTML)
5) Div section with the map on the webpage

There is a nice webpage with google maps icons:
http://www.econym.demon.co.uk/googlemaps/geicons.htm

1) Creation of the map:
function load() {
if (GBrowserIsCompatible()) {
var map = new GMap2(document.getElementById("map"));
map.setCenter(new GLatLng(37.03339,-7.95112), 13);
map.setMapType(G_HYBRID_TYPE);

2) Include controls
map.addControl(new GSmallMapControl());
map.addControl(new GMapTypeControl(true));

3) Creation of Hotel icon

var iconHotel = new GIcon();
iconHotel.image = "http://maps.google.com/mapfiles/kml/pal2/icon20.png";
iconHotel.shadow = "http://maps.google.com/mapfiles/kml/pal2/icon20s.png";
iconHotel.iconSize = new GSize(32, 32);
iconHotel.shadowSize = new GSize(37, 34);
iconHotel.iconAnchor = new GPoint(9, 34);
iconHotel.infoWindowAnchor = new GPoint(9, 2);
iconHotel.infoShadowAnchor = new GPoint(18, 25);

4) Adding Point and marker
var pointIbis = new GLatLng(37.03339,-7.95112);
var markerIbis=new GMarker(pointIbis,iconHotel)
map.addOverlay(markerIbis);
GEvent.addListener(markerIbis, "click", function() {
markerIbis.openInfoWindowHtml("<b>Hotel Ibis</b>");
}); //don't forget this

and closing the load function and if statement:
}
}

- The function load() is called inside the body tag with the onload event
<body onload="load()">

- The DIV in the page couldn't be simpler
<div id="map" style="width: 600px; height: 400px"></div>

Labels: , ,

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

Sunday, May 13, 2007

I can't belive it I got the job !!!!

I was a couple of days in the Alentejo region working on a research field and had to take care of some temperature logger and collect soil samples for a project. I discovered that the field was infested with ticks, after I got home by the end of the week I discovered 3 ticks on my body, it was a bit painful to take the bitches out with alcohol.

But the good news was that I got the job at the JRC in Ispra, I just have to pass a medical exam and to send some documentation and if everything goes according to plan I am starting at the 16th July.

This means that I have to finish the WFS system in the CALTER project As Soon As Possible!!!

Labels: , ,