2

I would like to be able to do some simple calculations on fields returned by a GetFeatureInfo with MapServer 7.0.4.

My case is that I am querying a layer (OGR connection to an ESRI File Geodatabase) and one of the fields returned is the area of a polygon. The area is in square meters but I would like to do an on-the-fly calculation to show the value in acres or hectare.

I didn't find anything in the official documentation indicating that this is possible.

Is it possible, without having to modify the source layer?

Here is the template I use to output the result of the GetFeatureInfo:

<!-- MapServer Template -->
<!DOCTYPE HTML PUBLIC "-//W3C//DTD HTML 4.01 Transitional//EN"
       "http://www.w3.org/TR/html4/transitional.dtd">
<html>
  <head>
    <title>MapServer Template Sample</title>
  </head>
<table class="bars_n_stripes" border="2">
            <tbody>
                <tr>
                    <th scope="col" width="30%"><center>Attribut</center></th>
                    <th scope="col"><center>Valeur</center></th>
                </tr>
                <tr>
                    <td>Numéro de lot</td>    
                    <td>[no_lot_renove]</td>
                </tr>
                <tr>
                    <td>Prénom</td>
                    <td>[prenom_proprio]</td>
                </tr>
                <tr>
                    <td>Nom</td>
                    <td>[nom_proprio]</td> 
                </tr>
                <tr>
                    <td>Superficie</td>
                    <td>[shape_area] m<sup>2</sup></td> 
                </tr>
            </tbody>
        </table>
</html>
  • It is probably possible with text/html info_format and a template mapserver.org/mapfile/template.html. Are you still interested? – user30184 Apr 25 '17 at 16:45
  • Yes! Still interested. I still didn't solve my problem. I do use a template to output the result of the GetFeatureInfo – TurboGraphxBeige Apr 25 '17 at 16:59
  • OK. I must experiment a bit first and it may take a few days before I have time for that. – user30184 Apr 25 '17 at 17:02
  • I edited my question to include one of the templates I use. – TurboGraphxBeige Apr 25 '17 at 17:07
  • I had a quick look right away but unfortunately templating mapserver.org/mapfile/template.html does not support any arithmetric operations. I was hoping that they were supported as in expressions mapserver.org/mapfile/…. – user30184 Apr 25 '17 at 18:20
3

I think in principle it should be possible with JavaScript, for example if you consider the following GetFeatureInfo request:

http://ogc.bgs.ac.uk/cgi-bin/TFL-PSI/ows?language=eng&REQUEST=GetFeatureInfo&SERVICE=WMS&VERSION=1.3.0&LAYERS=GBR_Stoke-on-Trent_ESA_EN_5k_psi_TS&STYLES=&FORMAT=image/png&BGCOLOR=0xFFFFFF&TRANSPARENT=TRUE&CRS=EPSG:4326&BBOX=53.0052235378464,-2.28573545848794,53.1251768672774,-2.13175281574312&WIDTH=1086&HEIGHT=846&QUERY_LAYERS=GBR_Stoke-on-Trent_ESA_EN_5k_psi_TS&i=337&j=255&info_format=text/html&

You will see that it includes a Time Series plot that is created on the fly using JavaScript embeded in the template.

Time series plot

View source to see the JavaScript as created.

The relevant parts of the template here are:

Creating the structure we want to plot:

<script type="text/javascript"><!-- 
var [Id]_tsline=[['1992-05-11',[D19920511]],['1993-01-11',[D19930111]],['1993-02-15',[D19930215]],['1993-03-22',[D19930322]],['1993-05-31',[D19930531]],['1993-08-09',[D19930809]],['1993-10-18',[D19931018]],['1993-11-22',[D19931122]],['1995-04-19',[D19950419]],['1995-05-24',[D19950524]],['1995-05-25',[D19950525]],['1995-06-28',[D19950628]],['1995-06-29',[D19950629]],['1995-08-02',[D19950802]],['1995-08-03',[D19950803]],['1995-10-11',[D19951011]],['1995-10-12',[D19951012]],['1995-12-21',[D19951221]],['1996-02-28',[D19960228]],['1996-02-29',[D19960229]],['1996-04-03',[D19960403]],['1996-04-04',[D19960404]],['1996-05-08',[D19960508]],['1996-05-09',[D19960509]],['1996-06-12',[D19960612]],['1996-07-17',[D19960717]],['1996-08-22',[D19960822]],['1996-10-31',[D19961031]],['1996-12-05',[D19961205]],['1997-01-09',[D19970109]],['1997-02-13',[D19970213]],['1997-03-20',[D19970320]],['1997-04-24',[D19970424]],['1997-05-29',[D19970529]],['1997-08-07',[D19970807]],['1997-09-11',[D19970911]],['1997-10-16',[D19971016]],['1997-11-20',[D19971120]],['1997-12-25',[D19971225]],['1998-01-29',[D19980129]],['1998-03-05',[D19980305]],['1998-04-09',[D19980409]],['1998-05-14',[D19980514]],['1998-06-18',[D19980618]],['1998-07-23',[D19980723]],['1998-08-27',[D19980827]],['1998-10-01',[D19981001]],['1998-11-05',[D19981105]],['1998-12-10',[D19981210]],['1999-02-18',[D19990218]],['1999-03-25',[D19990325]],['1999-08-12',[D19990812]],['1999-09-15',[D19990915]],['1999-09-16',[D19990916]],['1999-10-20',[D19991020]],['1999-10-21',[D19991021]],['1999-11-25',[D19991125]],['1999-12-30',[D19991230]],['2000-02-03',[D20000203]],['2000-03-09',[D20000309]],['2000-04-13',[D20000413]],['2000-05-18',[D20000518]],['2000-06-22',[D20000622]],['2000-07-27',[D20000727]],['2000-08-31',[D20000831]],['2000-11-09',[D20001109]],['2000-12-14',[D20001214]],['2001-10-25',[D20011025]],['2002-10-10',[D20021010]],['2003-02-27',[D20030227]]]; //--> 
</script> 

Creating a location to put the chart:

<tr><td id="[Id]_chart1" class="tschart" title="Time series chart for selected point" style="display:none;"></td></tr> 

Adding the JavaScript that do the plotting:

<script type="text/javascript"><!-- 
    $("#[Id]_chart1:hidden").show(); 
    var plot1 = $.jqplot('[Id]_chart1', [[Id]_tsline], { 
        title:'Time series plot for selected point', 
        axes:{xaxis:{renderer:$.jqplot.DateAxisRenderer}}, 
        series:[{lineWidth:3, markerOptions:{style:'circle'}}] 
    }); // --> 
</script>

The JavaScript needs to go at the end of the template to allow the page to load before it runs.

  • I'll certainly look into it within the next weeks. in the meantime, I used FME to routinely convert my data to PostGIS tables and use PostgreSQL functions to do what I need, server-side. – TurboGraphxBeige Dec 21 '17 at 12:34

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service, privacy policy and cookie policy

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