You might look at Functions 
(http://docs.geotools.org/latest/userguide/tutorial/function.html).  To achieve 
something similar to what I think you’re asking about, I defined a class called 
RoadLabelFunction (and an associated Factory class) and used it when creating a 
text symbolizer of the layer style.  This causes my function to be invoked for 
each feature.  Here’s a few code snippets:

 

public class RoadLabelFunction implements Function …

 

 

StyleBuilder sb = new StyleBuilder();

TextSymbolizer styleText = sb.createTextSymbolizer(
                                  sb.createFill(Color.BLACK),
                                   new Font[] { 
sf.createFont(ff2.literal(fontName), 
                                                
ff2.literal(fontStyle),ff2.literal(fontWeight), ff2.literal(fontSize)) },
                                  sb.createHalo(),
                                  
ff2.function("RoadLabel",ff2.property(labelFieldName)),
                                  pointPlacement,
                                  null);

…

 

Best,

Hal

 

From: Jochen Schramm [mailto:joc...@innoplexia.com] 
Sent: Thursday, June 26, 2014 7:04 AM
To: Jody Garnett; geotools-gt2-users@lists.sourceforge.net
Subject: Re: [Geotools-gt2-users] How to apply a custum label on polygons in 
Geotools?

 

Thank you for your answer.



What I need is text per label, not text for all polygons the same text.

Probably I am stupid, but I do not really get how the labels are applied to 
polygons.

 

On Wed, Jun 25, 2014 at 12:08 PM, Jody Garnett <jody.garn...@gmail.com> wrote:

I am a bit confused, there is no such thing as a standard label in GeoTools? 
When defining a label you can use an expression to generate the label you want. 
I suppose if you just filled in <Label>text</Label> you would get "text" 
repeated again and a gain, if you use 
<Label><PropertyName>name</PropertyName></Label> the value of the attribute 
name will be filled in for each polygon.

 

For more information and examples see the user guide:

- 
http://docs.geotools.org/latest/userguide/library/render/style.html#textsymbolizer

 

There is a discussion on how rendering (and labelling) work as part of the 
tutorial:

- http://docs.geotools.org/latest/userguide/tutorial/map/style.html

 

 

 




Jody Garnett

 

On Wed, Jun 25, 2014 at 6:23 PM, Jochen Schramm <joc...@innoplexia.com> wrote:

Hi

I am new to Geotools and I am stuck in trying to get custom labels on polygons 
in Geotools. What I get running is a map with the wanted regions filled with 
the liked colors.

Yet, it is needed to have different labelling than the standard postal code. I 
cannot find a way getting some free text as label text. An option would also be 
removing the standard label (not showing it) and create i.e. a point placed on 
the polygon having something like a free text label. This as well I get 
working, unfortunately.

Could anyone give me a hint how it is possible placing custom labels on 
polygons? Any help is very much appreciated!

Best regards

Jochen 



-- 

Jochen Schramm

 

Developer


  <http://www.innoplexia.de/ci/logo/inno_logo_links%20200x80.png>  

Innoplexia GmbH
Mannheimer Str. 175

69123 Heidelberg 

Tel.: +49 (0) 6221 7198033 
Fax: +49 (0) 6221 7198034 
Web:  <http://www.innoplexia.com/> www.innoplexia.com 

Sitz: 69123 Heidelberg, Mannheimer Str. 175 - Steuernummer 32494/62606 - USt. 
IdNr.: DE 272 871 728 - Geschäftsführer: Prof. Dr. Herbert Schuster

 

------------------------------------------------------------------------------
Open source business process management suite built on Java and Eclipse
Turn processes into business applications with Bonita BPM Community Edition
Quickly connect people, data, and systems into organized workflows
Winner of BOSSIE, CODIE, OW2 and Gartner awards
http://p.sf.net/sfu/Bonitasoft
_______________________________________________
GeoTools-GT2-Users mailing list
GeoTools-GT2-Users@lists.sourceforge.net
https://lists.sourceforge.net/lists/listinfo/geotools-gt2-users

 




-- 

Jochen Schramm

 

Developer


  <http://www.innoplexia.de/ci/logo/inno_logo_links%20200x80.png>  

Innoplexia GmbH
Mannheimer Str. 175

69123 Heidelberg 

Tel.: +49 (0) 6221 7198033 
Fax: +49 (0) 6221 7198034 
Web:  <http://www.innoplexia.com/> www.innoplexia.com 

Sitz: 69123 Heidelberg, Mannheimer Str. 175 - Steuernummer 32494/62606 - USt. 
IdNr.: DE 272 871 728 - Geschäftsführer: Prof. Dr. Herbert Schuster

------------------------------------------------------------------------------
Open source business process management suite built on Java and Eclipse
Turn processes into business applications with Bonita BPM Community Edition
Quickly connect people, data, and systems into organized workflows
Winner of BOSSIE, CODIE, OW2 and Gartner awards
http://p.sf.net/sfu/Bonitasoft
_______________________________________________
GeoTools-GT2-Users mailing list
GeoTools-GT2-Users@lists.sourceforge.net
https://lists.sourceforge.net/lists/listinfo/geotools-gt2-users

Reply via email to