Martin.
------------------------------------------------------------------------
Subject:
[Geotools-gt2-users] Exception raised accessing attributes of Feature
with Lite rendrer
From:
LepiMarbois <[EMAIL PROTECTED]>
Date:
Wed, 08 Mar 2006 10:00:50 +0100
To:
geotools-gt2-userst <[email protected]>
To:
geotools-gt2-userst <[email protected]>
Hi,
trying to refer to attributes on creating Style on Features of
Point.Class inserted into MemoryDataStore this raises exception when
creating layer with Lite Rendrer if Graphic creation attempts to refer
to attributes as:
sb.attributeExpression("size") , or even as
attributeExpression("size",ff),
see below the stack trace of exception generated or even when
creating TextSymbolizer if it refers to attributes as:
sb.attributeExpression("nompt"), same for
attributeExpression("nompt",ff),
see below the stack trace generated in this case.
In both cases it seems not possible to access any attribute of the
features on the style generation.
Here below the code to for the Feature creation and Style creation
Thanks for response,
Pierre
protected void ajoutePointsLayer()
{
try{ builder = new StyleBuilder();
AttributeType[] typepoint = new AttributeType[4];
typepoint[0] =
AttributeTypeFactory.newAttributeType("the_geomln", Point.class);
typepoint[1] = AttributeTypeFactory.newAttributeType("nompt",
String.class);
typepoint[2] = AttributeTypeFactory.newAttributeType("size",
Float.class);
typepoint[3] =
AttributeTypeFactory.newAttributeType("rotation", Float.class);
FeatureType ftPoint =
FeatureTypeFactory.newFeatureType(typepoint, "points");
GeometryFactory geomf = new GeometryFactory();
Point geometry = geomf.createPoint(new Coordinate(35.0, -12.0 ));
String nom = ("Label");
Float size = new Float(20.);
Float rotat = new Float(1.);
Feature ftpt1 = ftPoint.create(new Object[]
{geometry,nom,size,rotat}, "pt1");
FeatureCollection fc =
FeatureCollections.newCollection();
fc.add(ftpt1); final DataStore store = new
MemoryDataStore( fc); final FeatureSource
features = store.getFeatureSource(store.getTypeNames()[0]);
final Style style = buildStyle();
final Ma_DefaultMapLayer layer = new
Ma_DefaultMapLayer( features, style);
layer.setTitle("Points");
layer.SetBuilder(builder);
layer.SetNature(1);
BlockingSwingWorker worker = new
BlockingSwingWorker(this) {
protected void doNonUILogic() throws RuntimeException {
System.out.println("ajoute layer");
context.addLayer(layer);
System.out.println("ajoute layerpost");
if (context.getLayerCount() == 1) {
System.out.println("ajoute layer 3");
mapPane.reset();
} }
};
worker.start();
} catch (IOException ex)
{ System.out.println("ExceptionIO: " + ex);
ex.printStackTrace ();
} catch (SchemaException ex)
{ System.out.println("SchemaException: " + ex);
ex.printStackTrace ();
} catch ( IllegalAttributeException ex)
{ System.out.println("ExceptionIllegalAttribute: " + ex);
ex.printStackTrace ();
} catch ( IllegalFilterException ex)
{ System.out.println("IllegalFilterExp " + ex);
ex.printStackTrace ();
} catch (Exception ex)
{ System.out.println("Exception: " + ex);
ex.printStackTrace ();
}
}
private Expression attributeExpression(String
attributeName,FilterFactory ff)
throws org.geotools.filter.IllegalFilterException {
org.geotools.filter.AttributeExpression attribute =
ff.createAttributeExpression( null, attributeName );
return attribute;
}
private Style buildStyle() throws Exception {
StyleBuilder sb = new StyleBuilder();
FilterFactory ff = sb.getFilterFactory();
Style style = sb.createStyle();
style.setName("MyStyle");
Mark testMark = sb.createMark(StyleBuilder.MARK_STAR,
//sb.attributeExpression("name"),
sb.createFill(Color.BLUE, 0.5), null);
Graphic graph = sb.createGraphic(null,
new Mark[] { testMark },
null,
sb.literalExpression(1),
sb.attributeExpression("size"),
//sb.literalExpression(10.), attributeExpression("size",ff),
sb.attributeExpression("rotation")) ; //
attributeExpression("rotation",ff)); sb.literalExpression(0.));
/* Graphic graph = builder.createGraphic(null //extn
graphic
, testMark ,
null //Symbol
, 0.5 // opacity 0.0 transparent 1.0 completement opaque
, 10. //size
, 0 // rotation
); */
style.addFeatureTypeStyle(sb.createFeatureTypeStyle("testPoint",
new Symbolizer[] { sb.createPointSymbolizer(graph) }));
AnchorPoint anchorPoint = sb.createAnchorPoint(0.,0.);
PointPlacement pointPlacement =
sb.createPointPlacement(anchorPoint, null,
sb.literalExpression(0));
TextSymbolizer textSymbolizer =
sb.createTextSymbolizer(sb.createFill(Color.BLACK),
new Font[] { sb.createFont("Lucida Sans", 10),
sb.createFont("Arial", 10) },
sb.createHalo(),
sb.attributeExpression("nompt"), //
attributeExpression("nompt",ff),
pointPlacement, null);
Mark circle = sb.createMark(StyleBuilder.MARK_CIRCLE, Color.RED);
Graphic graph2 = sb.createGraphic(null, circle, null, 1, 4, 0);
PointSymbolizer pointSymbolizer =
sb.createPointSymbolizer(graph2);
style.addFeatureTypeStyle(sb.createFeatureTypeStyle("labelPoint",
new Symbolizer[] { pointSymbolizer })); //
textSymbolizer,
return style;
}
stack trace generated on Graphic creation if it refers to attributes :
= "size" "rotation"
7 mars 2006 18:47:39
org.geotools.renderer.lite.LiteRenderer$DefaultRenderListener
errorOccurred
GRAVE: null
java.lang.NullPointerException
at
org.geotools.renderer.style.SLDStyleFactory.evalToDouble(SLDStyleFactory.java:1388)
at
org.geotools.renderer.style.SLDStyleFactory.createPointStyle(SLDStyleFactory.java:415)
at
org.geotools.renderer.style.SLDStyleFactory.createStyleInternal(SLDStyleFactory.java:328)
at
org.geotools.renderer.style.SLDStyleFactory.createStyle(SLDStyleFactory.java:288)
at
org.geotools.renderer.lite.LiteRenderer.processSymbolizers(LiteRenderer.java:1181)
at
org.geotools.renderer.lite.LiteRenderer.processStylers(LiteRenderer.java:1069)
at
org.geotools.renderer.lite.LiteRenderer.render(LiteRenderer.java:814)
at
org.geotools.renderer.LegendIconMaker.reallyMakeLegendIcon(LegendIconMaker.java:304)
at
org.geotools.renderer.LegendIconMaker.makeLegendIcon(LegendIconMaker.java:171)
at
org.geotools.renderer.LegendIconMaker.makeLegendIcon(LegendIconMaker.java:161)
at
org.geotools.renderer.LegendIconMaker.makeLegendIcon(LegendIconMaker.java:151)
at
org.geotools.renderer.LegendIconMaker.makeLegendIcon(LegendIconMaker.java:156)
at org.geotools.gui.swing.Legend.constructRuleNote(Legend.java:245)
at org.geotools.gui.swing.Legend.contructLayer(Legend.java:220)
at
org.geotools.gui.swing.Legend.contructTreeModelAndLayerList(Legend.java:174)
at org.geotools.gui.swing.Legend.contextChanged(Legend.java:372)
at org.geotools.gui.swing.Legend.layerAdded(Legend.java:408)
at
org.geotools.map.DefaultMapContext.fireMapLayerListListenerLayerAdded(DefaultMapContext.java:845)
at
org.geotools.map.DefaultMapContext.addLayer(DefaultMapContext.java:196)
at MapLegendViewer$4.doNonUILogic(MapLegendViewer.java:699)
at
org.geotools.gui.swing.worker.BlockingSwingWorker.construct(BlockingSwingWorker.java:124)
at
org.geotools.gui.swing.worker.BlockingSwingWorker.access$000(BlockingSwingWorker.java:34)
at
org.geotools.gui.swing.worker.BlockingSwingWorker$2.run(BlockingSwingWorker.java:79)
at java.lang.Thread.run(Unknown Source)
stack trace if TextSymbolizer refer to attribute "nompt" :
7 mars 2006 18:18:41
org.geotools.renderer.lite.LiteRenderer$DefaultRenderListener
errorOccurred
GRAVE: null
java.lang.NullPointerException
at
org.geotools.renderer.style.SLDStyleFactory$SymbolizerKey.hashCode(SLDStyleFactory.java:1360)
at java.util.HashMap.hash(Unknown Source)
at java.util.HashMap.get(Unknown Source)
at
org.geotools.renderer.style.SLDStyleFactory.createStyle(SLDStyleFactory.java:281)
at
org.geotools.renderer.lite.LiteRenderer.processSymbolizers(LiteRenderer.java:1181)
at
org.geotools.renderer.lite.LiteRenderer.processStylers(LiteRenderer.java:1069)
at
org.geotools.renderer.lite.LiteRenderer.render(LiteRenderer.java:814)
at
org.geotools.renderer.LegendIconMaker.reallyMakeLegendIcon(LegendIconMaker.java:304)
at
org.geotools.renderer.LegendIconMaker.makeLegendIcon(LegendIconMaker.java:171)
at
org.geotools.renderer.LegendIconMaker.makeLegendIcon(LegendIconMaker.java:161)
at
org.geotools.renderer.LegendIconMaker.makeLegendIcon(LegendIconMaker.java:151)
at
org.geotools.renderer.LegendIconMaker.makeLegendIcon(LegendIconMaker.java:156)
at org.geotools.gui.swing.Legend.constructRuleNote(Legend.java:245)
at org.geotools.gui.swing.Legend.contructLayer(Legend.java:220)
at
org.geotools.gui.swing.Legend.contructTreeModelAndLayerList(Legend.java:174)
at org.geotools.gui.swing.Legend.contextChanged(Legend.java:372)
at org.geotools.gui.swing.Legend.layerAdded(Legend.java:408)
at
org.geotools.map.DefaultMapContext.fireMapLayerListListenerLayerAdded(DefaultMapContext.java:845)
at
org.geotools.map.DefaultMapContext.addLayer(DefaultMapContext.java:196)
at MapLegendViewer$4.doNonUILogic(MapLegendViewer.java:697)
at
org.geotools.gui.swing.worker.BlockingSwingWorker.construct(BlockingSwingWorker.java:124)
at
org.geotools.gui.swing.worker.BlockingSwingWorker.access$000(BlockingSwingWorker.java:34)
at
org.geotools.gui.swing.worker.BlockingSwingWorker$2.run(BlockingSwingWorker.java:79)
at java.lang.Thread.run(Unknown Source
-------------------------------------------------------
This SF.Net email is sponsored by xPML, a groundbreaking scripting
language
that extends applications into web and mobile media. Attend the live
webcast
and join the prime developer group breaking into this new coding
territory!
http://sel.as-us.falkag.net/sel?cmd=lnk&kid=110944&bid=241720&dat=121642
_______________________________________________
Geotools-gt2-users mailing list
[email protected]
https://lists.sourceforge.net/lists/listinfo/geotools-gt2-users