[Geoserver-users] How to apply different styles for different geometry types in GeometryCollection?

Hi there.

I created an YSLD style for Polygons, LineStrings and Points

feature-styles:

  • name: name
    x-ruleEvaluation: first
    rules:

  • filter: ${dimension(geometry()) = 2}
    symbolizers:

  • polygon:
    fill-color: ‘yellow’
    stroke-color: ‘red’

  • filter: ${dimension(geometry()) = 1}
    symbolizers:

  • line:
    stroke-color: ‘blue’

  • else: true
    symbolizers:

  • point:
    symbols:

  • mark:
    shape: circle
    stroke-width: 1

It works fine with Polygon and Linestring geometries.

But when geometry is a GeometryCollection with Polygon and LineString inside then all child geometries have style of polygone (dimension of Collection is 2). If only Linestrings and Points are indise GeometryCollection then all children have style of lineString (dimension of Collection is 1).

How to apply different styles for geometries of different types inside GeometryCollection?

Hi,

you need a different filter, which checks the /geometryType/ of your
geometry column, for example:

- filter: ${geometryType(yourgeometrycolumn)='Point'}
  symbolizers:
  - point:
    ...

- filter: ${geometryType(yourgeometrycolumn)='Polygon'}
  symbolizers:
  - polygon:
    ...

Cheers,
HSt

--
Sent from: http://osgeo-org.1560.x6.nabble.com/GeoServer-User-f3786390.html

Hi,

you need a different filter, which checks the /geometryType/ of your
geometry column, for example:

  - filter: ${geometryType(yourgeometrycolumn) = 'Point'}
    symbolizers:
    - point:
        ...
     
  - filter: ${geometryType(yourgeometrycolumn) = 'Polygon'}
    symbolizers:
    - polygon:
        ...

Cheers,
HSt

--
Sent from: http://osgeo-org.1560.x6.nabble.com/GeoServer-User-f3786390.html

That is a tricky question, I am not sure we have addressed that case yet.

It may be worth making a function that returns only the points from a collection (as a MultiPoint), and then only the lines, and then only the polygons.

slice( geometryCollection, dimension )

So:
slice( collection, 0 ) =
slice( collection, 1 ) = MultiLineString

slice( collection, 2 ) = MultiPolygon

Or because there are only three perhaps, points(collection), lines( collection), polygons(collection)

With those functions you could construct a more appropriate generic style for your data.

···


Jody Garnett

Thanks for answers!

Yeah, such function would be awesome

вт, 7 апр. 2020 г. в 19:21, Jody Garnett <jody.garnett@anonymised.com>:

That is a tricky question, I am not sure we have addressed that case yet.

It may be worth making a function that returns only the points from a collection (as a MultiPoint), and then only the lines, and then only the polygons.

slice( geometryCollection, dimension )

So:
slice( collection, 0 ) =
slice( collection, 1 ) = MultiLineString

slice( collection, 2 ) = MultiPolygon

Or because there are only three perhaps, points(collection), lines( collection), polygons(collection)

With those functions you could construct a more appropriate generic style for your data.


Jody Garnett

On Mon, 6 Apr 2020 at 17:30, Artem Groznykh <groznykh.dev@anonymised.com4…> wrote:

Hi there.

I created an YSLD style for Polygons, LineStrings and Points

feature-styles:

  • name: name
    x-ruleEvaluation: first
    rules:

  • filter: ${dimension(geometry()) = 2}
    symbolizers:

  • polygon:
    fill-color: ‘yellow’
    stroke-color: ‘red’

  • filter: ${dimension(geometry()) = 1}
    symbolizers:

  • line:
    stroke-color: ‘blue’

  • else: true
    symbolizers:

  • point:
    symbols:

  • mark:
    shape: circle
    stroke-width: 1

It works fine with Polygon and Linestring geometries.

But when geometry is a GeometryCollection with Polygon and LineString inside then all child geometries have style of polygone (dimension of Collection is 2). If only Linestrings and Points are indise GeometryCollection then all children have style of lineString (dimension of Collection is 1).

How to apply different styles for geometries of different types inside GeometryCollection?


Geoserver-users mailing list

Please make sure you read the following two resources before posting to this list:

If you want to request a feature or an improvement, also see this: https://github.com/geoserver/geoserver/wiki/Successfully-requesting-and-integrating-new-features-and-improvements-in-GeoServer

Geoserver-users@lists.sourceforge.net
https://lists.sourceforge.net/lists/listinfo/geoserver-users

Hi Jody

Is there a possibility that such functions would be realized?

--
Sent from: http://osgeo-org.1560.x6.nabble.com/GeoServer-User-f3786390.html

I think it is a good idea, but have not had time/budget to work on this myself.

Indeed I have had this draft email replying to you open for a month or so. I have been very focused on transitioning our build infrastructure, with some small development implementing mapbox style expression support :slight_smile:

Do you have any experience with Java? Or if there are any volunteers on this list interested it should be a combination of:

  1. https://docs.geotools.org/latest/userguide/tutorial/function.html

  2. A method similar to:

public T evaluate(Object object, Class context) {
Expression pointExpression = parameters.get(0);
Geometry geometry = pointExpression.evaluate(object, Geometry.class);
if( geometry == null) return geometry;

Expression dimensionExpression = parameters.get(1);
Integer dimension = dimensionExpression.evaluate(object, Integer.class);

switch(dimension) {
case 0: return toPuntal(geometry);
case 1: return toLineal(geometry);
case 2: return toPolygonal(geometry);
default:
throw IllegalArgumentException(“Dimension “+dimension+” invalid (0,1 or 2 supported)”);
}
}

  1. And then methods to collect each type, this could probably be done a bit more neatly

return Geometry toPuntal(Geometry geometry){

if( geometry instanceof Puntal) return geometry;
if( geometry instanceof GeometryCollection){
GeometryCollection collection = (GeometryCollection) geometry;
ArrayList points = new ArrayList<>();
for (int i; i<collection.getNumGeometries(); i++){
Geometry g = collection.getGeometryN(geometry,i);
Geometry = toPuntal(g);
if( g instanceof Point)
points.add( (Point) g );
else if( g instanceof MultiPoint) {
MultiPoint pts = (MultiPoint) g;
for (int j; j<pts.getNumGeometries(); j++){
points.add( (Point) pts.getGeometryN(j);
}
}
}
return geometryFactory().createMultiPoint(points.toArray(new Point[points.size()]);
}
return geometryFactory().createMultiPoint();
}

On Wed, 23 Sep 2020 at 03:51, groznykh <groznykh.dev@anonymised.com…84…> wrote:

Hi Jody

Is there a possibility that such functions would be realized?


Sent from: http://osgeo-org.1560.x6.nabble.com/GeoServer-User-f3786390.html


Geoserver-users mailing list

Please make sure you read the following two resources before posting to this list:

If you want to request a feature or an improvement, also see this: https://github.com/geoserver/geoserver/wiki/Successfully-requesting-and-integrating-new-features-and-improvements-in-GeoServer

Geoserver-users@lists.sourceforge.net
https://lists.sourceforge.net/lists/listinfo/geoserver-users

Hi,

Sorry for interrupting into this conversation, but: Are you aware that SLD can style different geometries out of the box? See attached SLD for the INSPIRE theme Environmental Monitoring Facilities which does use survey area (Polygon) and representative point (Point) as geometry. But maybe this is about something different and you can ignore this.

yours, Florian

EMF_fixed2.sld (2.92 KB)

···


MSc Florian Hoedt
Head Geoinformatics | OpenData Representative
Thünen Institute, Centre for Information Management
Bundesallee 44
38116 Braunschweig

Tel: +49 531 596-1428
Mobil: +49 162 92 50 275
Fax: +49 531 596-1499
Mail: florian.hoedt@anonymised.com
Web: www.thuenen.de

The Johann Heinrich von Thünen Institute, Federal Research Institute for Rural Areas, Forestry and Fisheries – Thünen Institute in brief – consists of 14 specialized institutes that carry out research and provide policy advice in the fields of economy, ecology and technology.


Von: “Jody Garnett” jody.garnett@anonymised.com
An: “groznykh” groznykh.dev@anonymised.com
CC: “Geoserver USERS” geoserver-users@lists.sourceforge.net
Gesendet: Montag, 19. Oktober 2020 07:05:10
Betreff: Re: [Geoserver-users] How to apply different styles for different geometry types in GeometryCollection?

I think it is a good idea, but have not had time/budget to work on this myself.

Indeed I have had this draft email replying to you open for a month or so. I have been very focused on transitioning our build infrastructure, with some small development implementing mapbox style expression support :slight_smile:

Do you have any experience with Java? Or if there are any volunteers on this list interested it should be a combination of:

  1. https://docs.geotools.org/latest/userguide/tutorial/function.html

  2. A method similar to:

public T evaluate(Object object, Class context) {
Expression pointExpression = parameters.get(0);
Geometry geometry = pointExpression.evaluate(object, Geometry.class);
if( geometry == null) return geometry;

Expression dimensionExpression = parameters.get(1);
Integer dimension = dimensionExpression.evaluate(object, Integer.class);

switch(dimension) {
case 0: return toPuntal(geometry);
case 1: return toLineal(geometry);
case 2: return toPolygonal(geometry);
default:
throw IllegalArgumentException(“Dimension “+dimension+” invalid (0,1 or 2 supported)”);
}
}

  1. And then methods to collect each type, this could probably be done a bit more neatly

return Geometry toPuntal(Geometry geometry){

if( geometry instanceof Puntal) return geometry;
if( geometry instanceof GeometryCollection){
GeometryCollection collection = (GeometryCollection) geometry;
ArrayList points = new ArrayList<>();
for (int i; i<collection.getNumGeometries(); i++){
Geometry g = collection.getGeometryN(geometry,i);
Geometry = toPuntal(g);
if( g instanceof Point)
points.add( (Point) g );
else if( g instanceof MultiPoint) {
MultiPoint pts = (MultiPoint) g;
for (int j; j<pts.getNumGeometries(); j++){
points.add( (Point) pts.getGeometryN(j);
}
}
}
return geometryFactory().createMultiPoint(points.toArray(new Point[points.size()]);
}
return geometryFactory().createMultiPoint();
}

On Wed, 23 Sep 2020 at 03:51, groznykh <groznykh.dev@anonymised.com> wrote:

Hi Jody

Is there a possibility that such functions would be realized?


Sent from: http://osgeo-org.1560.x6.nabble.com/GeoServer-User-f3786390.html


Geoserver-users mailing list

Please make sure you read the following two resources before posting to this list:

If you want to request a feature or an improvement, also see this: https://github.com/geoserver/geoserver/wiki/Successfully-requesting-and-integrating-new-features-and-improvements-in-GeoServer

Geoserver-users@lists.sourceforge.net
https://lists.sourceforge.net/lists/listinfo/geoserver-users


Geoserver-users mailing list

Please make sure you read the following two resources before posting to this list:

If you want to request a feature or an improvement, also see this: https://github.com/geoserver/geoserver/wiki/Successfully-requesting-and-integrating-new-features-and-improvements-in-GeoServer

Geoserver-users@lists.sourceforge.net
https://lists.sourceforge.net/lists/listinfo/geoserver-users

You should probably use the existion function geometryType in the SLD rule.
If you don’t do that a polygon is visualised as a polygon and also point (the centre of the polygon) for example.

The only thing is that there are multiple geometry-types that represent Point, Polygon and Line.

Polygon:

  • Polygon

  • MultiPolygon

  • MultiSurface

  • CurvePolygon

  • GeometryCollection (this is a difficult one!)

Line:

  • LineString
  • CircularString
  • CompoundCurve
    -CompoundRing
  • CircularRing
  • MultiCurve
  • MultiLineString

Point:

  • Point
  • Multipoint

It would be nice if there was a separate function “mainGeometryType” that just returns Point, Polygon, Line or Collection

On Monday, 19 October 2020, 10:32:15 CEST, Florian Hoedt florian.hoedt@anonymised.com wrote:

Hi,

Sorry for interrupting into this conversation, but: Are you aware that SLD can style different geometries out of the box? See attached SLD for the INSPIRE theme Environmental Monitoring Facilities which does use survey area (Polygon) and representative point (Point) as geometry. But maybe this is about something different and you can ignore this.

yours, Florian


MSc Florian Hoedt
Head Geoinformatics | OpenData Representative
Thünen Institute, Centre for Information Management
Bundesallee 44
38116 Braunschweig

Tel: +49 531 596-1428
Mobil: +49 162 92 50 275
Fax: +49 531 596-1499
Mail: florian.hoedt@anonymised.com
Web: www.thuenen.de

The Johann Heinrich von Thünen Institute, Federal Research Institute for Rural Areas, Forestry and Fisheries – Thünen Institute in brief – consists of 14 specialized institutes that carry out research and provide policy advice in the fields of economy, ecology and technology.


Von: “Jody Garnett” jody.garnett@anonymised.com
An: “groznykh” groznykh.dev@anonymised.com
CC: “Geoserver USERS” geoserver-users@anonymised.comrceforge.net
Gesendet: Montag, 19. Oktober 2020 07:05:10
Betreff: Re: [Geoserver-users] How to apply different styles for different geometry types in GeometryCollection?

I think it is a good idea, but have not had time/budget to work on this myself.

Indeed I have had this draft email replying to you open for a month or so. I have been very focused on transitioning our build infrastructure, with some small development implementing mapbox style expression support :slight_smile:

Do you have any experience with Java? Or if there are any volunteers on this list interested it should be a combination of:

  1. https://docs.geotools.org/latest/userguide/tutorial/function.html

  2. A method similar to:

public T evaluate(Object object, Class context) {
Expression pointExpression = parameters.get(0);
Geometry geometry = pointExpression.evaluate(object, Geometry.class);
if( geometry == null) return geometry;

Expression dimensionExpression = parameters.get(1);
Integer dimension = dimensionExpression.evaluate(object, Integer.class);

switch(dimension) {
case 0: return toPuntal(geometry);
case 1: return toLineal(geometry);
case 2: return toPolygonal(geometry);
default:
throw IllegalArgumentException(“Dimension “+dimension+” invalid (0,1 or 2 supported)”);
}
}

  1. And then methods to collect each type, this could probably be done a bit more neatly

return Geometry toPuntal(Geometry geometry){

if( geometry instanceof Puntal) return geometry;
if( geometry instanceof GeometryCollection){
GeometryCollection collection = (GeometryCollection) geometry;
ArrayList points = new ArrayList<>();
for (int i; i<collection.getNumGeometries(); i++){
Geometry g = collection.getGeometryN(geometry,i);
Geometry = toPuntal(g);
if( g instanceof Point)
points.add( (Point) g );
else if( g instanceof MultiPoint) {
MultiPoint pts = (MultiPoint) g;
for (int j; j<pts.getNumGeometries(); j++){
points.add( (Point) pts.getGeometryN(j);
}
}
}
return geometryFactory().createMultiPoint(points.toArray(new Point[points.size()]);
}
return geometryFactory().createMultiPoint();
}

On Wed, 23 Sep 2020 at 03:51, groznykh <groznykh.dev@anonymised.com> wrote:

Hi Jody

Is there a possibility that such functions would be realized?


Sent from: http://osgeo-org.1560.x6.nabble.com/GeoServer-User-f3786390.html


Geoserver-users mailing list

Please make sure you read the following two resources before posting to this list:

If you want to request a feature or an improvement, also see this: https://github.com/geoserver/geoserver/wiki/Successfully-requesting-and-integrating-new-features-and-improvements-in-GeoServer

Geoserver-users@lists.sourceforge.net
https://lists.sourceforge.net/lists/listinfo/geoserver-users


Geoserver-users mailing list

Please make sure you read the following two resources before posting to this list:

If you want to request a feature or an improvement, also see this: https://github.com/geoserver/geoserver/wiki/Successfully-requesting-and-integrating-new-features-and-improvements-in-GeoServer

Geoserver-users@lists.sourceforge.net
https://lists.sourceforge.net/lists/listinfo/geoserver-users


Geoserver-users mailing list

Please make sure you read the following two resources before posting to this list:

If you want to request a feature or an improvement, also see this: https://github.com/geoserver/geoserver/wiki/Successfully-requesting-and-integrating-new-features-and-improvements-in-GeoServer

Geoserver-users@anonymised.comts.sourceforge.net
https://lists.sourceforge.net/lists/listinfo/geoserver-users

This bug report is for a slightly different problem, when working with a geometry collection the ability to filter out only the points and multi-points.

···


Jody Garnett

Caught up with the JTS team.

There is a postgis function https://postgis.net/docs/ST_CollectionExtract.html that covers this concept.

There are a couple implementations in JTS, GeometryExtracter is close but only can do one geometry type at a time, and we want to do both Point and MultiPoint at the same time.

The other interesting wrinkle …

  • Points (Point and MultiPoint) can be extracted into a a MultiPoint
  • Lines (LineString and MultiLineString) can be extracted into a MultiLineString
  • Polygons (Polygon and MultiPolygon) … cannot be extracted into a MultiPolygon (because they may end up overlapping)

Jody

···


Jody Garnett

That’s what you want to do, in the end, due to SLD symbolizer application rules.
GeoServer does not implement them 100% percent, but the standard says something like:

  • Given a line symbolizer, paint polygon borders (I can’t remember if points need to be converted to tiny lines, believe not)
  • Given a point symbolizer, paint the centroid of whatever you’re given that’s not a point
  • Given a polygon symbolizer, close the lines to form a polygon, create a small square around points, and paint the result as a polygon
    Long story short, you need three separate rules anyways

Cheers
Andrea

···

== GeoServer Professional Services from the experts! Visit http://goo.gl/it488V for more information. == Ing. Andrea Aime @geowolf Technical Lead GeoSolutions S.A.S. Via di Montramito 3/A 55054 Massarosa (LU) phone: +39 0584 962313 fax: +39 0584 1660272 mob: +39 339 8844549 http://www.geo-solutions.it http://twitter.com/geosolutions_it ------------------------------------------------------- Con riferimento alla normativa sul trattamento dei dati personali (Reg. UE 2016/679 - Regolamento generale sulla protezione dei dati “GDPR”), si precisa che ogni circostanza inerente alla presente email (il suo contenuto, gli eventuali allegati, etc.) è un dato la cui conoscenza è riservata al/i solo/i destinatario/i indicati dallo scrivente. Se il messaggio Le è giunto per errore, è tenuta/o a cancellarlo, ogni altra operazione è illecita. Le sarei comunque grato se potesse darmene notizia. This email is intended only for the person or entity to which it is addressed and may contain information that is privileged, confidential or otherwise protected from disclosure. We remind that - as provided by European Regulation 2016/679 “GDPR” - copying, dissemination or use of this e-mail or the information herein by anyone other than the intended recipient is prohibited. If you have received this email by mistake, please notify us immediately by telephone or e-mail.

Actually wait, no, given GeoServer’s ability to accept Functions in the geometry property of each symbolizer (not part of the standard btw),
one rule with three symbolizers, each using the right function in the geometry field, will do.

Cheers
Andrea

···

GeoServer Professional Services from the experts! Visit http://goo.gl/it488V for more information. == Ing. Andrea Aime @geowolf Technical Lead GeoSolutions S.A.S. Via di Montramito 3/A 55054 Massarosa (LU) phone: +39 0584 962313 fax: +39 0584 1660272 mob: +39 339 8844549 http://www.geo-solutions.it http://twitter.com/geosolutions_it ------------------------------------------------------- Con riferimento alla normativa sul trattamento dei dati personali (Reg. UE 2016/679 - Regolamento generale sulla protezione dei dati “GDPR”), si precisa che ogni circostanza inerente alla presente email (il suo contenuto, gli eventuali allegati, etc.) è un dato la cui conoscenza è riservata al/i solo/i destinatario/i indicati dallo scrivente. Se il messaggio Le è giunto per errore, è tenuta/o a cancellarlo, ogni altra operazione è illecita. Le sarei comunque grato se potesse darmene notizia. This email is intended only for the person or entity to which it is addressed and may contain information that is privileged, confidential or otherwise protected from disclosure. We remind that - as provided by European Regulation 2016/679 “GDPR” - copying, dissemination or use of this e-mail or the information herein by anyone other than the intended recipient is prohibited. If you have received this email by mistake, please notify us immediately by telephone or e-mail.

That is good thinking Andrea, that will probably be the most efficient approach.

···


Jody Garnett