Hi Andy,
it seems like an awful amount of work the way you do it. I actually got it
to work using filters, and it works really well. Takes a little bit to get
a handle on working with filters,
but once you do, it’s very spiffy! Here is my code:
public static Style createDefaultAssetsExposureStyle(GeometryDescriptor
gd) {
PropertyIsEqualTo filterIrrelevant =
ff.equals(ff.property("EXPOSURE"),
ff.literal(-1));
Rule ruleIrrelevant = createDefaultStyleRule(gd, Color.GRAY);
ruleIrrelevant.setFilter(filterIrrelevant);
PropertyIsEqualTo filterAffected =
ff.equals(ff.property("EXPOSURE"),
ff.literal(1));
Rule ruleAffected = createDefaultStyleRule(gd, Color.RED);
ruleAffected.setFilter(filterAffected);
PropertyIsEqualTo filterNotAffected =
ff.equals(ff.property("EXPOSURE"),
ff.literal(0));
Rule ruleNotAffected = createDefaultStyleRule(gd, Color.GREEN);
ruleNotAffected.setFilter(filterNotAffected);
FeatureTypeStyle fts = sf.createFeatureTypeStyle();
fts.rules().add(ruleIrrelevant);
fts.rules().add(ruleAffected);
fts.rules().add(ruleNotAffected);
Style style = sf.createStyle();
style.featureTypeStyles().add(fts);
return style;
}
public static Rule createDefaultStyleRule(GeometryDescriptor gd, Color
fillColor) {
Symbolizer symbolizer = null;
Fill fill = null;
Class<?> geomType = gd.getType().getBinding();
String geometryAttributeName = gd.getLocalName();
Stroke stroke = sf.createStroke(ff.literal(Color.BLACK),
ff.literal(1.0f));
if (LineString.class.isAssignableFrom(geomType) ||
MultiLineString.class.isAssignableFrom(geomType)) {
symbolizer = sf.createLineSymbolizer(stroke,
geometryAttributeName);
} else if (Polygon.class.isAssignableFrom(geomType) ||
MultiPolygon.class.isAssignableFrom(geomType)) {
fill = sf.createFill(ff.literal(fillColor),
ff.literal(OPACITY));
symbolizer = sf.createPolygonSymbolizer(stroke, fill,
geometryAttributeName);
} else {
fill = sf.createFill(ff.literal(fillColor),
ff.literal(OPACITY));
Mark mark = sf.getCircleMark();
mark.setFill(fill);
// mark.setStroke(stroke);
Graphic graphic = sf.createDefaultGraphic();
graphic.graphicalSymbols().clear();
graphic.graphicalSymbols().add(mark);
graphic.setSize(ff.literal(POINT_SIZE));
symbolizer = sf.createPointSymbolizer(graphic,
geometryAttributeName);
}
Rule rule = sf.createRule();
rule.symbolizers().add(symbolizer);
return rule;
}
Gaby
On 1/05/15 17:38, "Andy Turner" <[email protected]> wrote:
>With this, I would be tempted to split this into three point shapefiles
>and try rendering them on top of each other in different orders applying
>different styles to see how the picture/map looked. I think I tried, but
>did not find a way to do it all in one go keeping all the data in the
>same shapefile.
>
>The points I add in the foreground of my map:
>
> // Add foreground0
> // ---------------
> private static void addForeground0(
> MapContent result,
> AGDT_StyleParameters styleParameters,
> ArrayList<AGDT_Shapefile> foregroundDW_Shapefile0) {
> if (foregroundDW_Shapefile0 != null) {
> Iterator<AGDT_Shapefile> ite;
> ite = foregroundDW_Shapefile0.iterator();
> int indexx = 0;
> while (ite.hasNext()) {
> AGDT_Shapefile sf = ite.next();
> FeatureLayer foregroundFeatureLayer0;
> foregroundFeatureLayer0 = sf.getFeatureLayer(
>
>styleParameters.getForegroundStyle0().get(indexx));
> result.addLayer(foregroundFeatureLayer0);
> indexx++;
> }
> }
> }
>
>That code is from:
>
>https://github.com/agdturner/digital-welfare/blob/master/src/main/java/uk/
>ac/leeds/ccg/andyt/projects/digitalwelfare/mapping/DW_Geotools.java
>point
>
>My DW_ project code depends on the following where I have tried to move
>all my generic geotools type code too (as you may recall):
>https://github.com/agdturner/agdt-geotools
>
>Interested to learn if you figure out a way to do this keeping all the
>data in a single shapefile. There may be a way to do this with
>classifiers which I use to do graduated shading. But with this, you may
>be more restricted in the colours and styles of your points.
>
>Please let me know if this helps or if you want more details (though it
>might take me a week or so to respond from now). Thanks also for your
>reply to my earlier message. I will be taking a good look at your work
>and hopefully referring to it in due course.
>
>I will be getting back to coding in the next week or so having had a few
>week doing other things.
>
>Best wishes,
>
>Andy
>________________________________________
>From: Gabriella Turek [[email protected]]
>Sent: 01 May 2015 03:22
>To: geotools users
>Subject: [Geotools-gt2-users] Help with styling
>
>I have a point shape file with one attribute which can be one of -1,0,1.
>I’d like to set up a style with three colors. Can someone point me in the
>right direction?
>Thanx
>gaby
>
>--------------------------------------------------------------------------
>----
>One dashboard for servers and applications across Physical-Virtual-Cloud
>Widest out-of-the-box monitoring support with 50+ applications
>Performance metrics, stats and reports that give you Actionable Insights
>Deep dive visibility with transaction tracing using APM Insight.
>http://ad.doubleclick.net/ddm/clk/290420510;117567292;y
>_______________________________________________
>GeoTools-GT2-Users mailing list
>[email protected]
>https://lists.sourceforge.net/lists/listinfo/geotools-gt2-users
------------------------------------------------------------------------------
One dashboard for servers and applications across Physical-Virtual-Cloud
Widest out-of-the-box monitoring support with 50+ applications
Performance metrics, stats and reports that give you Actionable Insights
Deep dive visibility with transaction tracing using APM Insight.
http://ad.doubleclick.net/ddm/clk/290420510;117567292;y
_______________________________________________
GeoTools-GT2-Users mailing list
[email protected]
https://lists.sourceforge.net/lists/listinfo/geotools-gt2-users