Displaying Style Set Properties - Easier Way?

3 messages Options
Embed this post
Permalink
Oliver Gottwald

Displaying Style Set Properties - Easier Way?

Reply Threaded More More options
Print post
Permalink
Hi,

I put together a method that displays the properties set for a Style.

The only way that I could see to do this was to:
Style as method parameter and base
    iterate: ArrayList of FeatureTypeStyle
           iterate: ArrayList of rules
                 iterate: ArrayList of symbolizers
                            check: for proper symbolizer implementation
                                      display field settings


If there is a cleaner way to do this let me know.  I have my reasons for needing to do this :-).  I have not integrated Point or Line yet but will and post on forum after clean up.  I figured this was a good place to start.  The following is my code:

public void displayStyleProperties(Style style){
    ArrayList ftsList = (ArrayList)style.featureTypeStyles();
    ListIterator i = ftsList.listIterator();
    while(i.hasNext()){
        FeatureTypeStyle ftStyle = (FeatureTypeStyle)i.next();
   
        ArrayList rList = (ArrayList)ftStyle.rules();
        ListIterator j = rList.listIterator();
        while(j.hasNext()){
            Rule ruleo = (Rule)j.next();
   
            ArrayList symList = (ArrayList)ruleo.symbolizers();
            ListIterator s = symList.listIterator();
            while(s.hasNext()){
                Object ts=(Object)s.next();
                System.out.println("++"+ts.getClass().getName()+"++\n");
                if(ts.getClass().getName()=="org.geotools.styling.PolygonSymbolizerImpl"){
                    PolygonSymbolizer polySym = (PolygonSymbolizer)ts;
                    Fill fill = polySym.getFill();
                    System.out.println("fill color: "+fill.getColor());
                    Stroke stroke = polySym.getStroke();
                    System.out.println("stroke color: "+stroke.getColor());
                   
                } //end PolySymbolizerImpl if
                if(ts.getClass().getName()=="org.geotools.styling.TextSymbolizerImpl"){
                    TextSymbolizer tsym = (TextSymbolizer)ts;
                    Font font = tsym.getFont();
                    System.out.println("family: "+font.getFamily());
                    System.out.println("size: "+font.getSize());
                    System.out.println("style: "+font.getStyle());
                    System.out.println("weight: "+font.getWeight());
                    Fill fill = tsym.getFill();
                    System.out.println("color: "+fill.getColor());
                   
                    System.out.println("labelName: "+tsym.getLabel());
                   
                    PointPlacement labelPlacement = (PointPlacement)tsym.getLabelPlacement();
                    AnchorPoint anchorPoint = labelPlacement.getAnchorPoint();
                    System.out.println("anchor.X: "+anchorPoint.getAnchorPointX()+
                                       " anchor.Y: "+anchorPoint.getAnchorPointY());
                    Displacement displacement = (Displacement)labelPlacement.getDisplacement();
                    System.out.println("displacement.X: "+displacement.getDisplacementX()+
                               " displacement.Y: "+displacement.getDisplacementY());
                } //end TextSymbolizerImpl if
            } //end symbolizers symList loop
        } //end rule rList loop
    } //end featureTypeStyle ftsList loop
}





------------------------------------------------------------------------------
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
Oliver Gottwald

Re: Displaying Style Set Properties - Easier Way?

Reply Threaded More More options
Print post
Permalink
i will be curious to see if there is a simpler way to do style property extraction but.....
one thing i noticed that is cleaner in the code - is to do the following:
          symList loop:
        while(s.hasNext()){
         Object ts=(Object)s.next();
         if(ts.getClass().getName()=="org.geotools.styling.PolygonSymbolizerImpl"){
...
...
...
          }
          if(ts.getClass().getName()=="org.geotools.styling.TextSymbolizerImpl"){

with:
           symList loop:
           while(s.hasNext()){
           Symbolizer ts=(Symbolizer)s.next();
                if(ts instanceof PolygonSymbolizer){
...
...
...
                }
                if(ts instanceof TextSymbolizer){



-----Original Message-----
From: "Oliver Gottwald" <[hidden email]>
Sent: Thursday, October 29, 2009 5:07pm
To: [hidden email]
Subject: [Geotools-gt2-users] Displaying Style Set Properties - Easier Way?

Hi,

I put together a method that displays the properties set for a Style.

The only way that I could see to do this was to:
Style as method parameter and base
    iterate: ArrayList of FeatureTypeStyle
           iterate: ArrayList of rules
                 iterate: ArrayList of symbolizers
                            check: for proper symbolizer implementation
                                      display field settings


If there is a cleaner way to do this let me know.  I have my reasons for needing to do this :-).  I have not integrated Point or Line yet but will and post on forum after clean up.  I figured this was a good place to start.  The following is my code:

public void displayStyleProperties(Style style){
    ArrayList ftsList = (ArrayList)style.featureTypeStyles();
    ListIterator i = ftsList.listIterator();
    while(i.hasNext()){
        FeatureTypeStyle ftStyle = (FeatureTypeStyle)i.next();
   
        ArrayList rList = (ArrayList)ftStyle.rules();
        ListIterator j = rList.listIterator();
        while(j.hasNext()){
            Rule ruleo = (Rule)j.next();
   
            ArrayList symList = (ArrayList)ruleo.symbolizers();
            ListIterator s = symList.listIterator();
            while(s.hasNext()){
                Object ts=(Object)s.next();
                System.out.println("++"+ts.getClass().getName()+"++\n");
                if(ts.getClass().getName()=="org.geotools.styling.PolygonSymbolizerImpl"){
                    PolygonSymbolizer polySym = (PolygonSymbolizer)ts;
                    Fill fill = polySym.getFill();
                    System.out.println("fill color: "+fill.getColor());
                    Stroke stroke = polySym.getStroke();
                    System.out.println("stroke color: "+stroke.getColor());
                   
                } //end PolySymbolizerImpl if
                if(ts.getClass().getName()=="org.geotools.styling.TextSymbolizerImpl"){
                    TextSymbolizer tsym = (TextSymbolizer)ts;
                    Font font = tsym.getFont();
                    System.out.println("family: "+font.getFamily());
                    System.out.println("size: "+font.getSize());
                    System.out.println("style: "+font.getStyle());
                    System.out.println("weight: "+font.getWeight());
                    Fill fill = tsym.getFill();
                    System.out.println("color: "+fill.getColor());
                   
                    System.out.println("labelName: "+tsym.getLabel());
                   
                    PointPlacement labelPlacement = (PointPlacement)tsym.getLabelPlacement();
                    AnchorPoint anchorPoint = labelPlacement.getAnchorPoint();
                    System.out.println("anchor.X: "+anchorPoint.getAnchorPointX()+
                                       " anchor.Y: "+anchorPoint.getAnchorPointY());
                    Displacement displacement = (Displacement)labelPlacement.getDisplacement();
                    System.out.println("displacement.X: "+displacement.getDisplacementX()+
                               " displacement.Y: "+displacement.getDisplacementY());
                } //end TextSymbolizerImpl if
            } //end symbolizers symList loop
        } //end rule rList loop
    } //end featureTypeStyle ftsList loop
}





------------------------------------------------------------------------------
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: Displaying Style Set Properties - Easier Way?

Reply Threaded More More options
Print post
Permalink
In reply to this post by Oliver Gottwald
Hi Oliver,

You may also want to look at the SLD helper class which has static
methods to retrieve and set components in a Style:

http://geotools.org/javadocs/org/geotools/styling/SLD.html

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