[mapserver-users] Calculate length!

Schylberg Lars lars.schylberg at saabgroup.com
Sun Mar 15 11:59:52 PDT 2015


Hi Jukka,

You were right about that is possible to calculate length of a line in a KML file in Mapserver via ogr and sqlite.
It is possible with a VRT file. I had some weekend fun learning. This will be useful in another project I am doing!

The only trouble I found, was that I could not get the relativeToVRT=1 to work when I did an inline specification of the ovf in the mapfile.
The only way to get the inline ScrDataSource specification to work  was to use a full path description to the kml file location.
In most cases I like to use relative location specifications.
Shapepath specification in the mapfile didn’t help

/Lars

Example follows:

Make a ovf-file: doc_test.ovf

<OGRVRTDataSource>
   <OGRVRTLayer name='doc_test'>
   <SrcDataSource relativeToVRT=1>./doc_test.kml</SrcDataSource>
   <SrcSQL dialect='sqlite'>
     select geometry,
     Name,
     cast(OGR_STYLE as chartater(32)) as 'LINE_STYLE',
     cast(ST_length(geometry, 4857) as integer(12)) as 'DISTANCE'
     FROM 'Fibertech solution'
     where ST_GeometryType(geometry) LIKE 'LINESTRING%'</SrcSQL>
  </OGRVRTLayer>
</OGRVRTDataSource>

The class from the new mapfile.


  LAYER
    CONNECTIONTYPE OGR
    CONNECTION "doc_test.ovf"
    DATA 'doc_test'
    NAME "kml_example"
    GROUP LINES
    TYPE LINE
    STATUS ON
    CLASSITEM "LINE_STYLE"
    CLASS
      EXPRESSION "@msn_ylw-pushpin4"
      STYLE
        COLOR 250 0 0
        WIDTH 2.5
      END
      LABEL
        TEXT ("Distance: " + '[DISTANCE]' + ' meters ' + '#' + '[Name]')
        WRAP '#'
        SIZE MEDIUM
        COLOR 255 100 100
        POSITION AUTO
      END
    END
…….


-------------- next part --------------
An HTML attachment was scrubbed...
URL: <http://lists.osgeo.org/pipermail/mapserver-users/attachments/20150315/36275af2/attachment.html>


More information about the mapserver-users mailing list