GeoServer – Obtaining GetFeatureInfo Results Without Geometries

geoservergetfeatureinfo

In GeoServer, is there a way to only retrieve the attributes/properties of features, without geometries, using the GetFeatureInfo request?

I need to use the GetFeatureInfo request to retrieve features' attributes at a location when user clicks on a web map (similar to "Identify" tool in Esri). However, the response contains huge amount of coordinates/geometries in GeoJSON format, which makes it take up lots of computing/network resources. For example, some routes/lines geometries take up 10K lines when formatted nicely!

Looks like there is something called Freemarker but I can't find any good examples/resources so far. It appears that one limitation of Freemarker templates is it would apply to ALL GetFeatureInfo responses, whereas I only want the remove geometries for this particular web app.

Also we could use HTML or text format but they are harder to parse.

I'm new to GeoServer and we use PostgreSQL as the database.

Best Answer

There is an example on the page you link to, all you need to do is remove the lines that print the geometry. (<#-- starts a comment, --> ends it)

<#list features as feature>
{
 "content" : "this is the content",
 "type": "Feature",
 "id" : "${feature.fid}",
 <#list feature.attributes as attribute>
 <#if attribute.isGeometry>
 <#-- "geometry": ${geoJSON.geomToGeoJSON(attribute.rawValue)}, -->
 </#if>
 </#list>
 "properties": {
 <#list feature.attributes?filter(a -> !a.isGeometry) as attribute>
 "${attribute.name}": "${attribute.value}"
 <#if attribute_has_next>
 ,
 </#if>
 </#list>
 }
}
<#if feature_has_next>
,
</#if>
</#list>