Jesus Loves GRASS

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

Tuesday, September 29, 2009

WMS/WFS getfeature on hover, problem to display the GML (mapserver)

I had a hard time programming something similar to the "WFS GetFeature Example" shown in the OpenLayers examples, the example uses calls to a WFS/WMS services that have the same name and data origin.

The WFS/WMS service call is done with the OpenLayers.Protocol.WFS.fromWMSLayer as follows (the layerWMS is a OpenLayrs.Layer.WMS object)

control = new OpenLayers.Control.GetFeature({
protocol: OpenLayers.Protocol.WFS.fromWMSLayer(layerWMS),
hover: true
});

Using firebug it is possible to see the requests going back-and-forward when hovering the polygons, but in the end the polygons aren't select, because trigger-events aren't called.

The problem is cause by the namespace used in the WFS of mapserver (since the example given in the web site uses geoserver, everything is ok), the solution is to indicate the namespace and featureTypeName.

In my mapserver response I have something like this:
<gml:featureMember>
<ms:wdpa gml:id="wdpa.67886">

Therefore control has to be changed as follows:

control = new OpenLayers.Control.GetFeature({
protocol: OpenLayers.Protocol.WFS.fromWMSLayer(layerWMS,{featureType:"wdpa",featurePrefix:"ms"}),
hover: true
});


It seems that the same has to be done for the standard WFS layer when using mapserver.

Labels: , , ,

Thursday, July 30, 2009

white space fore php tag

While a blank line before the <?php start tag may look innocent, when processed by PHP, it will turn into an echo statement printing out a blank line.

If working with web service wrapper scripts from mapserver this could be a disaster resulting in some strange behaviours like:

1) After $request->loadparams(); the script will send you an empty file as a reply
2) If the $request has uses setparameters, all the outputs will be dumped to the browser window, for example a WMS GetMap request will be a binary string in the browser window.
3) The ms_iogetStdoutBufferBytes(); will return nothing if you want to save the image locally.
4) Output with Warning: Cannot modify header information - headers already sent by

These symptoms are caused by the existence of an open buffer cause by the blank line, at the begining of the php programming.

Labels: , ,

Wednesday, April 29, 2009

Problem with Tomcat 5.5. HTTP Status 404 - The requested resource (...) is not available. (mod_jk)

Dealing with tomcat errors can be a pain in the neck.

For example a situation like this:

1) Considering that tomcat is running and apache's mod_jk is being used to connect to it.
a. Tomcat works fine when using http://mysite.com:8180/mypage
b. http://mysite.com/mypage generates a HTTP error 404 with resource not found.

2) Probably there is a miss match between the httpd.conf file and the server.xml configuration file
- ServerName, server IP or ports may be different in the 2 configuration files
- If you recompiled Apache, then you need to recompile mod_jk


If you are a newbie in tomcat (like me) this error may take some time to figure it out, since the error logs of apache are clean and the tomcat error logs don't help much

Labels: , , , ,

Wednesday, January 21, 2009

Error on CGI script

An error like this:
(8)Exec format error: exec of '/usr/local/apache2/cgi-bin/CGI2WPS.py' failed
[Wed Jan 21 09:38:41 2009] [error] [client 127.0.0.1] Premature end of script headers: CGI2WPS.py

Means that the execution of the script failed, probably the server has some problems on getting the python interpreter.

Adding the python location to the script will solve it:

#!/usr/bin/python
#-*- coding: utf-8 -*-

Labels: , ,

Friday, August 29, 2008

gdalinfo 1.4.2 versus gdalinfo 1.5.2

While processing some gdalinfo string-to-array in PHP I noticed that the output of gdalinfo is different from 1.4 to 1.5 and therefore my code broke in a new machine.
Gdal 1.4.2:
Driver: GTiff/GeoTIFF
Size is 35, 72
Coordinate System is `'
Origin = (-72000.000000000000000,
643700.000000000000000)
Pixel Size = (9422.857142857143117,-9565.277777777777374)
Corner Coordinates:
Upper Left ( -72000.000, 643700.000)
Lower Left ( -72000.000, -45000.000)
Upper Right ( 257800.000, 643700.000)
Lower Right ( 257800.000, -45000.000)
Center ( 92900.000, 299350.000)
Band 1 Block=35x58 Type=Float32, ColorInterp=Gray
Band 2 Block=35x58 Type=Float32, ColorInterp=Undefined
Band 3 Block=35x58 Type=Float32, ColorInterp=Undefined

Gdal 1.5.2
Driver: GTiff/GeoTIFF
Files: geotiff_data2087566292
Size is 35, 72
Coordinate System is `'
Origin = (-72000.000000000000000,643700.000000000000000)
Pixel Size = (9422.857142857143117,-9565.277777777777374)
Image Structure Metadata:
INTERLEAVE=BAND
Corner Coordinates:
Upper Left ( -72000.000, 643700.000)
Lower Left ( -72000.000, -45000.000)
Upper Right ( 257800.000, 643700.000)
Lower Right ( 257800.000, -45000.000)
Center ( 92900.000, 299350.000)
Band 1 Block=35x58 Type=Float32, ColorInterp=Gray
Band 2 Block=35x58 Type=Float32, ColorInterp=Undefined
Band 3 Block=35x58 Type=Float32, ColorInterp=Undefined

The new version includes:
Image Structure Metadata:
INTERLEAVE=BAND

and the name of the file that was read
Files: geotiff_data2087566292

Labels: , , ,

Monday, May 19, 2008

Paper for GI-Days 2008 (Munster)

Just submitted a paper concerning WPS and the AutoMap (Gstat) package. The full paper will be online after the conference, meanwhile here is the abstract:

Web-based geostatistics using WPS
Jorge de Jesus1, Grégoire Dubois2, Paul Hiemstra3
1Institute for Environment and Sustainability / Joint Research Centre of the European Commission
(email removed)
1Institute for Environment and Sustainability / Joint Research Centre of the European Commission
(email removed)
3Department of Physical Geography / University of Utrecht
(email removed)

Abstract.
Mapping data using geostatistics can be a time-consuming process because of the many parameters to define. automap, a geostatistical package written in R, was developed to define automatically a spatial correlation model, a step that is considered to be the biggest obstacle for automating the spatial interpolation process with geostatistical algorithms. The implementation of automap into a Service Oriented Architecture (SOA) would ensure the automatic interpolation routines to be platform independent, easy to integrate into existing applications, and freely available in a network environment. automap is here further proposed as a Web Processing Service (WPS) to allow end-users to benefit from a remote service to be used for the real-time mapping of environmental data in routine situations. It is the purpose of this paper to present the architecture of the service as well as to discuss by means of case studies the limitations of the real time mapping system for emergency response.

Labels: , , , ,

Wednesday, February 27, 2008

The image .... cannot be displayed, because it contains errors.

"The image 'http://localhost/ACI/test.php' cannot be displayed, because it contains errors." Was the only thing I was getting when running some examples and source codes for image creation using GD and PHP. I googled it and all the information found concerned bad installation of GD and other libraries.

But when dumping the GD info with var_dump(gd_info()); everything was ok.

In the end I discovered that actually the error is not related to GD but with the header used to send the image, this example works fine:

<?php
header("Content-type: image/png");
$im = imagecreate(210, 20) or die("Cannot Initialize new GD image stream");
$background_color = imagecolorallocate($im, 0, 0, 0);
$text_color = imagecolorallocate($im, 25, 25, 25);
imageline($im,10,10,20,20,$text_color);
imagepng($im);
imagedestroy($im);
?>

But something like this:
<?php
//Something, source or text
?>
<?php
header("Content-type: image/png");
$im = imagecreate(210, 20) or die("Cannot Initialize new GD image stream");
$background_color = imagecolorallocate($im, 0, 0, 0);
$text_color = imagecolorallocate($im, 25, 25, 25);
imageline($im,10,10,20,20,$text_color);
imagepng($im);
imagedestroy($im);
?>

Will only generate the stupid GD error message.

The header() needs to be the first thing in the PHP code as explained in the PHP doc "Remember that header() must be called before any actual output is sent, either by normal HTML tags, blank lines in a file, or from PHP. It is a very common error to read code with include(), or require(), functions, or another file access function, and have spaces or empty lines that are output before header() is called. The same problem exists when using a single PHP/HTML file."

Labels: , , , ,