Question

Is there a way to count how many items/geometrys a layer received? What I want to do is to draw a diferent symbol if the query return too many items. Example:

MAXFEATURES 10001 #if I get 10001 results, please zoom in

CLUSTER
  MAXDISTANCE 20
  REGION "retangular"
END

LAYER
  CLASS
    EXPRESSION ([countPoints] > 10000)
    STYLE
      SYMBOL "to_many_points_please_zoom_in"
    END
  END

  CLASS
    EXPRESSION ([countPoints] < 10000 and [Cluster:FeatureCount] > 1)
    STYLE
      SYMBOL "cluster"
    END
  END
  CLASS
    EXPRESSION ([countPoints] < 10000 and [Cluster:FeatureCount] == 1)
    STYLE
      SYMBOL "point"
    END
  END

END

I tried to use [Cluster:FeatureCount] but it couldn't counts the entire layer, it just counts points in the several clusters.

Was it helpful?

Solution

As far as I can make out there are no built in mapserver parameters that match your countPoints pseudo parameter so unfortunately there is no way of doing what you want in a plain mapfile. It seems to me you have two options available:

  1. Use MapScript: you can use getNumFeatures() on a layer to retrieve the number of features and programatically adjust the classes and styling based on the result.

  2. Embed the feature count information in the source data, either explicitly with an attribute field containing the feature count or implicitly by altering the attributes present if MAXFEATURES > 10000. With the latter option you can check whether the attribute is present in a mapfile expression.

Going down the route of embedding the feature count information in the source data means you need to generate the data for each request as you have moved the logic from the mapfile to the code that creates the data. This means either having the data come from a database with SQL calling a procedure encapsulating the logic, or use a layer CONNECTIONTYPE with a remote data source which you control (e.g. an OGR CONNECTIONTYPE can consume a GeoJSON resource over HTTP generated by a script).

Licensed under: CC-BY-SA with attribution
Not affiliated with StackOverflow
scroll top