.. _community_sldservice: SLD REST Service ================ The SLD Service is a GeoServer REST service that can be used to create SLD styles on published GeoServer layers doing a classification on the layer data, following user provided directives. The purpose of the service is to allow clients to dinamically publish data and create simple styles on it. All the services are published under the common prefix ``/rest/sldservice/{layer}``, where **layer** is the layer to classify/query. Query Vector Data Attributes ---------------------------- ``/attributes[.]`` .. list-table:: :header-rows: 1 * - Method - Action - Status code - Formats - Default Format * - GET - Gets the list of attributes for the given layer (of vector type) - 200 - HTML, XML, JSON - HTML The service can be used to get the attributes list for the given vector layer. This can be used by a client as a prerequisite for the **classify** service, to get all the attributes usable for classification and let the user choose one. Examples ~~~~~~~~~~ Get attributes for the states layer, in XML format .. code-block:: console curl -v -u admin:geoserver -XGET http://localhost:8080/geoserver/rest/sldservice/states/attributes.xml .. code-block:: xml P_FEMALE Double HOUSHOLD Double SERVICE Double ... Get attributes for the states layer, in JSON format .. code-block:: console curl -v -u admin:geoserver -XGET http://localhost:8080/geoserver/rest/sldservice/states/attributes.json .. code-block:: javascript { "Attributes":{ "@layer":"states", "Attribute":[ { "name":"P_FEMALE", "type":"Double" }, { "name":"HOUSHOLD", "type":"Double" }, { "name":"SERVICE", "type":"Double" }, ... ] } } Classify Vector Data -------------------- ``/classify[.]`` .. list-table:: :header-rows: 1 * - Method - Action - Status code - Formats - Default Format * - GET - Create a set of SLD Rules for the given layer (of vector type) - 200 - HTML, XML, JSON - HTML The service can be used to create a set of SLD rules for the given vector layer, specyfing the **attribute** used for classification, the **classification type** (equalInterval, uniqueInterval, quantile, jenks) and one of the **predefined color ranges** (red, blue, gray, jet, random, custom), together with some other optional parameters. Using the **CUSTOM** ColorMap, startColor and endColor (and optionally midColor) have to be specified. The parameters usable to customize the ColorMap are: .. list-table:: :header-rows: 1 * - Parameter - Description - Values - Default Value * - intervals - Number of intervals (rules) for the SLD - integer numeric value - 2 * - attribute (mandatory) - Classification attribute - one of the layer attribute names - * - method - Classification method - equalInterval, uniqueInterval, quantile, jenks - equalInterval * - open - open or closed ranges - true, false - false * - reverse - normal or inverted ranges - true, false - false * - normalize - normalize (cast) attribute to double type (needed by some stores to handle integer types correctly) - true, false - false * - ramp (mandatory) - color ranges to use - red, blue, gray, jet, random, custom - * - startColor - starting color for the custom ramp - - * - endColor - ending color for the custom ramp - - * - midColor - central color for the custom ramp - - * - colors - list of comma delimited colors for the custom ramp (use this instead of startColor, endColor and midColor to specify colors in more detail) - - * - strokeColor - color of the stroke, for points and polygons - - BLACK * - strokeWeight - weight of the stroke, for points and polygons (use a negative value to not include stroke in style) - - 1 * - pointSize - size of points - - 15 * - fullSLD - create a full valid SLD document, instead of the Rules fragment only - true or false - false * - cache - append caching headers to the responses - expire time in seconds, use 0 to disable cache - 600 (10 minutes) * - viewparams - allows use of parametric views - view parameters in the usual format (:;...;:) - * - customClasses - allows specifying a set of custom classes (client driven style); no classes calculation will happen (method, intervals, etc. are ignored) - classes in the following format: ,,;...;,,) - Examples ~~~~~~~~~~ A default (equalInterval) classification on the states layer LAND_KM attribute using a red based color range. .. code-block:: console curl -v -u admin:geoserver -XGET http://localhost:8080/geoserver/rest/sldservice/states/classify.xml?attribute=LAND_KM&ramp=red .. code-block:: xml > 159.1 AND <= 344189.1 LAND_KM 159.1 LAND_KM 344189.1 #680000 > 344189.1 AND <= 688219.2 LAND_KM 344189.1 LAND_KM 688219.2 #B20000 A uniqueInterval classification on the states layer SUB_REGION attribute using a red based color range. .. code-block:: console curl -v -u admin:geoserver -XGET http://localhost:8080/geoserver/rest/sldservice/states/classify.xml?attribute=SUB_REGION&ramp=red&method=uniqueInterval .. code-block:: xml E N Cen SUB_REGION E N Cen #330000 E S Cen SUB_REGION E S Cen #490000 ... A uniqueInterval classification on the states layer SUB_REGION attribute using a red based color range and 3 intervals. .. code-block:: console curl -v -u admin:geoserver -XGET http://localhost:8080/geoserver/rest/sldservice/states/classify.xml?attribute=SUB_REGION&ramp=red&method=uniqueInterval&intervals=3 .. code-block:: xml Intervals: 9 A quantile classification on the states layer PERSONS attribute with a custom color ramp and 3 **closed** intervals. .. code-block:: console curl -v -u admin:geoserver -XGET http://localhost:8080/geoserver/rest/sldservice/states/classify.xml?attribute=PERSONS&ramp=CUSTOM&method=quantile&intervals=3&startColor=0xFF0000&endColor=0x0000FF .. code-block:: xml > 453588.0 AND <= 2477574.0 PERSONS 453588.0 PERSONS 2477574.0 #FF0000 > 2477574.0 AND <= 4866692.0 PERSONS 2477574.0 PERSONS 4866692.0 #AA0055 > 4866692.0 AND <= 2.9760021E7 PERSONS 4866692.0 PERSONS 2.9760021E7 #5500AA A quantile classification on the states layer PERSONS attribute with a custom color ramp and 3 **open** intervals. .. code-block:: console curl -v -u admin:geoserver -XGET http://localhost:8080/geoserver/rest/sldservice/states/classify.xml?attribute=PERSONS&ramp=CUSTOM&method=quantile&intervals=3&startColor=0xFF0000&endColor=0x0000FF&open=true .. code-block:: xml <= 2477574.0 PERSONS 2477574.0 #FF0000 > 2477574.0 AND <= 4866692.0 PERSONS 2477574.0 PERSONS 4866692.0 #AA0055 > 4866692.0 PERSONS 4866692.0 #5500AA Classify Raster Data -------------------- ``/rasterize[.]`` .. list-table:: :header-rows: 1 * - Method - Action - Status code - Formats - Default Format * - GET - Create a ColorMap SLD for the given layer (of coverage type) - 200 - HTML, XML, JSON, SLD - HTML The service can be used to create a ColorMap SLD for the given coverage, specyfing the **type of ColorMap** (VALUES, INTERVALS, RAMP) and one of the **predefined color ranges** (RED, BLUE, GRAY, JET, RANDOM, CUSTOM). Using the **CUSTOM** ColorMap, startColor and endColor (and optionally midColor) have to be specified. The parameters usable to customize the ColorMap are: .. list-table:: :header-rows: 1 * - Parameter - Description - Values - Default Value * - min - Minimum value for classification - double numeric value - 0.0 * - max - Maximum value for classification - double numeric value - 100.0 * - classes - Number of classes for the created map - integer numeric value - 100 * - digits - Number of fractional digits for class limits (in labels) - integer numeric value - 5 * - type - ColorMap type - INTERVALS, VALUES, RAMP - RAMP * - ramp - ColorMap color ranges - RED, BLUE, GRAY, JET, RANDOM, CUSTOM - RED * - startColor - starting color for the CUSTOM ramp - - * - endColor - ending color for the CUSTOM ramp - - * - midColor - central color for the CUSTOM ramp - - * - cache - append caching headers to the responses - expire time in seconds, use 0 to disable cache - 600 (10 minutes) Examples ~~~~~~~~~~ A RED color ramp with 5 classes .. code-block:: console curl -v -u admin:geoserver -XGET http://localhost:8080/geoserver/rest/sldservice/sfdem/rasterize.sld?min=0&max=100&classes=5&type=RAMP&ramp=RED&digits=1 .. code-block:: xml Default Styler Default Styler name gray A CUSTOM color ramp with 5 classes, with colors ranging from RED (0xFF0000) to BLUE (0x0000FF). .. code-block:: console curl -v -u admin:geoserver -XGET http://localhost:8080/geoserver/rest/sldservice/sfdem/rasterize.sld?min=0&max=100&classes=5&type=RAMP&ramp=CUSTOM&digits=1&startColor=0xFF0000&endColor=0x0000FF .. code-block:: xml Default Styler Default Styler name gray