Labeling Features

4 messages Options
Embed this post
Permalink
Oliver Gottwald

Labeling Features

Reply Threaded More More options
Print post
Permalink
Michael,

You Rock!
I just got labels working in my example sets with option 3 below.
I also added for non default fonts with the following line:
Font font=styleFactory.createFont(filterFactory.literal("Arial"), filterFactory.literal(true), filterFactory.literal(true), filterFactory.literal(7));

createFont(fontFamily,fontStyle,fontWeight,fontSize)
createFont(String,boolean,boolean,double)

2009/10/23 Oliver Gottwald wrote:
> By the way if I wanted to add a Label to the point for the code snipped
> below do you have an example for that possibly or could you point me in
> the right direction?  Labels are on my hit list for tomorrow.
>

Labelling features involves including a TextSymbolizer in your Style
along with PointSymbolizer (or whatever).

Some options for doing it programmatically (there are others too)...

1. Really cheat and use JSimpleStyleDialog which gives the option of
adding labels...

SimpleFeatureType TYPE = ...
Style = JSimpleStyleDialog.showDialog(null, TYPE);

2. Cheat just a little bit and use the SLD utility class...

Color lineColor = ...
Color fillColor = ...
float opacity = 1.0f;
float size = 5.0f;
String labelAttribute = "name";
Font font = styleFactory.getDefaultFont();
Style = SLD.createPointStyle("Circle", lineColor, fillColor, opacity,
size, labelAttribute, font);

3. Spurn easy solutions and do it all by hand...

StyleFactory sf = ...
FilterFactory ff = ...

String symbolName = "Circle"; // or Cross, Square, X, Triangle, Star
Color lineColor = ...
float lineWidth = ...
Color fillColor = ...
float opacity = ..
float size = ..
String labelAttribute = "name";
Font font = sf.getDefaultFont();

Stroke stroke = sf.createStroke(ff.literal(lineColor), ff.literal(lineWidth));
Fill fill = sf.createFill(ff.literal(fillColor), ff.literal(opacity));

Mark mark = sf.createMark(ff.literal(symbolName), stroke, fill,
ff.literal(size), ff.literal(0));

Graphic graphic = sf.createDefaultGraphic();
graphic.graphicalSymbols().clear();
graphic.graphicalSymbols().add(mark);
graphic.setSize(ff.literal(size));

PointSymbolizer pointSym = sf.createPointSymbolizer(graphic, null);

Fill labelFill = sf.createFill(ff.literal(Color.BLACK));
AnchorPoint anchor = sf.createAnchorPoint(ff.literal(0.5), ff.literal(0.0));
Displacement disp = sf.createDisplacement(ff.literal(0), ff.literal(size));
LabelPlacement placement = sf.createPointPlacement(anchor, disp, ff.literal(0));

TextSymbolizer textSym = sf.createTextSymbolizer(
labelFill, new Font[]{font}, null, ff.property(labelField),
placement, null);

Rule rule = sf.createRule();
rule.symbolizers().add( pointSym );
rule.symbolizers().add( textSym );

FeatureTypeStyle fts = sf.createFeatureTypeStyle(new Rule[] {rule});
Style style = sf.createStyle();
style.featureTypeStyles().add(fts);




------------------------------------------------------------------------------
Come build with us! The BlackBerry(R) Developer Conference in SF, CA
is the only developer event you need to attend this year. Jumpstart your
developing skills, take BlackBerry mobile applications to market and stay
ahead of the curve. Join us from November 9 - 12, 2009. Register now!
http://p.sf.net/sfu/devconference
_______________________________________________
Geotools-gt2-users mailing list
[hidden email]
https://lists.sourceforge.net/lists/listinfo/geotools-gt2-users
mbedward

Re: Labeling Features

Reply Threaded More More options
Print post
Permalink
Hi again Oliver,

Sorry - I replied to your other post before I saw this one.  Great to
hear that you got things working :)

Michael

------------------------------------------------------------------------------
Come build with us! The BlackBerry(R) Developer Conference in SF, CA
is the only developer event you need to attend this year. Jumpstart your
developing skills, take BlackBerry mobile applications to market and stay
ahead of the curve. Join us from November 9 - 12, 2009. Register now!
http://p.sf.net/sfu/devconference
_______________________________________________
Geotools-gt2-users mailing list
[hidden email]
https://lists.sourceforge.net/lists/listinfo/geotools-gt2-users
dadar

Re: Labeling Features

Reply Threaded More More options
Print post
Permalink
I want to ask something. can we labelling features not using ff.property(labelField)??
i want to add another string to labelling the features. how can I do it?

Darmawan
mbedward wrote:
Hi again Oliver,

Sorry - I replied to your other post before I saw this one.  Great to
hear that you got things working :)

Michael

------------------------------------------------------------------------------
Come build with us! The BlackBerry(R) Developer Conference in SF, CA
is the only developer event you need to attend this year. Jumpstart your
developing skills, take BlackBerry mobile applications to market and stay
ahead of the curve. Join us from November 9 - 12, 2009. Register now!
http://p.sf.net/sfu/devconference
_______________________________________________
Geotools-gt2-users mailing list
Geotools-gt2-users@lists.sourceforge.net
https://lists.sourceforge.net/lists/listinfo/geotools-gt2-users
Stefan Tzeggai

Re: Labeling Features

Reply Threaded More More options
Print post
Permalink
Am Sonntag 08 November 2009 17:28:15 schrieb dadar:
> I want to ask something. can we labelling features not using
> ff.property(labelField)??
> i want to add another string to labelling the features. how can I do it?
if you want to use a fixed string, use ff.literal("here!")



--
wiki² - Softwareentwicklung
Stefan Krüger
Straßburger Weg 26
53113 Bonn

email [hidden email]
mobile 0151 50543949
webpage wikisquare.de
skype alfonx

reclaim your net - http://tor.eff.org
enforce privacy - http://www.pgpi.org
pgp key id: 51B576FD - http://pgp.mit.edu

Please note that according to the German law on data retention,
information on every electronic information exchange with me is
retained for a period of six months.


------------------------------------------------------------------------------
Let Crystal Reports handle the reporting - Free Crystal Reports 2008 30-Day
trial. Simplify your report design, integration and deployment - and focus on
what you do best, core application coding. Discover what's new with
Crystal Reports now.  http://p.sf.net/sfu/bobj-july
_______________________________________________
Geotools-gt2-users mailing list
[hidden email]
https://lists.sourceforge.net/lists/listinfo/geotools-gt2-users
My last name will change from Krüger to Tzeggai in mid 2010.