ArcGIS Server WMS GetFeatureInfo and GeoJSON XSL

4659
0
06-26-2013 06:17 PM
by Anonymous User
Not applicable
Hello all,

I came across an issue with an article in the ArcGIS resource section. The article on ArcGIS Server and Customizing a WMS GetFeatureInfo response in terms of GeoJSON with the supplied featureinfo_application_geojson.xsl. I believe this is still and issue with 10.1

http://help.arcgis.com/en/arcgisdesktop/10.0/help/index.html#//005300000228000000

In short, to transform the WMS GetFeatureInfo response into GeoJSON (which is getting popular for good JavaScript reasons) ESRI recommend using a file called featureinfo_application_geojson.xsl supplied with ArcGIS Server. The problem is that this does not produce valid GeoJSON. The issue is that they put a comma at the end of each list, which means common JSON parser's such as JSON.parse() do not work.

SOLUTION:
I fixed this with the following small changes to the supplied featureinfo_application_geojson.xsl.

<xsl:template match="/">
{
"type": "FeatureCollection",
"features":
  [
  <xsl:for-each select="esri_wms:FeatureInfoResponse/esri_wms:FeatureInfoCollection/esri_wms:FeatureInfo">
   {
    "type": "Feature",
    "geometry": null,
    "properties":
     {
     <xsl:for-each select="esri_wms:Field">        
      "<xsl:value-of select="esri_wms:FieldName"/>":"<xsl:value-of select="esri_wms:FieldValue"/>"
      <xsl:choose>
       <xsl:when test="position() != last()">,<br/></xsl:when>
      </xsl:choose>
     </xsl:for-each>
     },
    "layerName":"<xsl:value-of select="../@layername"/>"
   }
   <xsl:choose>
    <xsl:when test="position() != last()">,<br/></xsl:when>
   </xsl:choose>
  </xsl:for-each>
  ]
}
</xsl:template>

RECOMMENDATION:
Geoserver now does info_format = application/geojson, it would be cool if ArcGIS server could also do this. Not hugely important, XSL transformations do give flexibility.

Steven Ackerly
Geoscience Australia
0 Kudos
0 Replies