Hello all! I'm pretty unsure which kind of information is required to really understand my problem and to answer my question but maybe this one is so general that the following suffices:
Currently I'm working on a proof-of-concept application based on geotools 14 which displays 1. some static shape file based vector (line or point) layers constituting a cadastral map as well as 2. a dynamic layer that shows the user's location (plus course, trace, and so on) which is derived from the output of a GNSS receiver. So far I've got the map layers and the dynamic position display working. To display e.g. the "location trace" and other information in that dynamic layer I thought I would just implement the MarkFactory interface. However the Feature argument of MarkFactory.getShape() gives me a feature that only contains the feature location but none of the other attributes I've added when I created that Feature before. So it seems the Feature object received is just a copy of the original one where all attributes (except for location) seems to be considered irrelevant. Where does the copying take place and how can I influence it in a way that my custom attributes are copied as well? Thanks in advance! Thomas Here's where the feature (plus the layer) is created and my MarkFactory implementation: public class CurrentPositionFeatureLayer extends FeatureLayer{ private Coordinate coord = null; private SimpleFeature feat_loc = null; private int history_size = 15; private LinkedList<Coordinate> coord_history = new LinkedList<Coordinate>(); private Double azimuth = new Double( Math.PI ); //just to be able to distinguish it from target_heading at first,... private Double target_direction = new Double( 0 ); private CurrentPositionFeatureLayer( ListFeatureCollection collection, Style style) { super( collection, style ); coord = new Coordinate( 4439138.7714, 5522681.2760 ); GeometryFactory geometryFactory = JTSFactoryFinder.getGeometryFactory(); SimpleFeatureBuilder fb_point = new SimpleFeatureBuilder( (SimpleFeatureType) collection.getSchema() ); com.vividsolutions.jts.geom.Point my_loc = geometryFactory.createPoint( coord ); fb_point.add( my_loc ); fb_point.add( coord_history ); fb_point.add( azimuth ); fb_point.add( target_direction ); feat_loc = fb_point.buildFeature( null ); feat_loc.setAttribute( "location_history", coord_history ); feat_loc.setAttribute( "azimuth", azimuth ); feat_loc.setAttribute( "target_direction", target_direction ); collection.add( feat_loc ); System.out.println( "feature.toString()=" + feat_loc ); //displays four attributes: //feature.toString()=SimpleFeatureImpl:Location=[SimpleFeatureImpl.Attribute: location<location id=fid-5363c5b7_1528d3b0c7e_-8000>=POINT // (4439138.7714 5522681.276), SimpleFeatureImpl.Attribute: location_history<location_history id=fid-5363c5b7_1528d3b0c7e_-8000>=[], // SimpleFeatureImpl.Attribute: azimuth<azimuth id=fid-5363c5b7_1528d3b0c7e_-8000>=3.141592653589793, SimpleFeatureImpl.Attribute: target_heading<target_heading id=fid-5363c5b7_1528d3b0c7e_-8000>=0.0] List<Object> attrs = feat_loc.getAttributes(); System.out.println( "attrlistsize=" + attrs.size() ); // attrlistsize=4 fireMapLayerListenerLayerChanged( 0 ); setTitle( "CurrentPositionFeatureLayer" ); } public static CurrentPositionFeatureLayer create() throws SchemaException{ SimpleFeatureTypeBuilder sft_builder = new SimpleFeatureTypeBuilder(); sft_builder.setName( "Location" ); sft_builder.add( "location", Point.class ); sft_builder.add( "location_history", List.class ); sft_builder.add( "azimuth", Double.class ); sft_builder.add( "target_direction", Double.class ); SimpleFeatureType ft_location = sft_builder.buildFeatureType(); ListFeatureCollection collection = new ListFeatureCollection( ft_location ); StyleFactory sf = CommonFactoryFinder.getStyleFactory(); FilterFactory ff = CommonFactoryFinder.getFilterFactory(); StyleBuilder builder = new StyleBuilder(); Graphic gr = builder.createGraphic(null, builder.createMark("gpsrcv"), null); PointSymbolizer ps = builder.createPointSymbolizer( gr ); Rule point_rule = sf.createRule(); point_rule.symbolizers().add( ps ); FeatureTypeStyle fts_point = sf.createFeatureTypeStyle( new Rule[] { point_rule } ); Style style = sf.createStyle(); style.featureTypeStyles().add( fts_point ); return(new CurrentPositionFeatureLayer( collection, style ) ); } // public double getOrdinate( int index ){ // return( coord.getOrdinate( index ) ); // } public void updateCoordinate( double x, double y ){ Coordinate new_coord = new Coordinate( x, y ); enqueueToHistory( new_coord ); coord.setCoordinate( new_coord ); feat_loc.setAttribute( "azimuth", azimuth ); this.fireMapLayerListenerLayerChanged( MapLayerEvent.DATA_CHANGED ); } private void enqueueToHistory( Coordinate coord ){ coord_history.add( coord ); while( coord_history.size() > history_size ){ coord_history.removeFirst(); } } private ReferencedEnvelope envelope = null; @Override public ReferencedEnvelope getBounds(){ try{ if( envelope == null ){ envelope = new ReferencedEnvelope( 4437422, 4441958, 5522097, 5523412, CRS.decode( "EPSG:5678" ) ); } return( envelope ); }catch( MismatchedDimensionException e ){ e.printStackTrace(); }catch( NoSuchAuthorityCodeException e ){ e.printStackTrace(); }catch( FactoryException e ){ e.printStackTrace(); } return( null ); } } public class PositionMarkFactory implements MarkFactory{ public Shape getShape(Graphics2D graphics, Expression symbolUrl, Feature feature) throws Exception { if (symbolUrl == null) { return null; } String wellKnownName = symbolUrl.evaluate(feature, String.class); if (wellKnownName != null && wellKnownName.equalsIgnoreCase("gpsrcv")) { System.out.println( "feature.toString()=" + feature ); //here I get // feature.toString()=SimpleFeatureImpl:Location=[SimpleFeatureImpl.Attribute: location<location id=fid-5363c5b7_1528d3b0c7e_-8000>=POINT (4439138.7714 5522681.276)] SimpleFeature feat = (SimpleFeature)feature; @SuppressWarnings("unchecked") List<Coordinate> location_history = (List<Coordinate>) feat.getAttribute( "location_history" ); List attrs = feat.getAttributes(); System.out.println( "attrlistsize=" + attrs.size() ); // attrlistsize=4 System.out.println( attrs.get( 0 ).getClass().getName() ); // com.vividsolutions.jts.geom.Point GeneralPath shape = new GeneralPath(); shape.moveTo( -1, 0 ); shape.lineTo( 1, 0.33f ); shape.lineTo( 1, -0.33f ); shape.closePath(); //shape.closePath(); //AffineTransform trans = new AffineTransform(); //trans.rotate( -Math.PI/3.0f ); //shape.transform( trans ); return( shape ); } return null; // we do not know this one } } ------------------------------------------------------------------------------ Site24x7 APM Insight: Get Deep Visibility into Application Performance APM + Mobile APM + RUM: Monitor 3 App instances at just $35/Month Monitor end-to-end web transactions and take corrective actions now Troubleshoot faster and improve end-user experience. Signup Now! http://pubads.g.doubleclick.net/gampad/clk?id=267308311&iu=/4140 _______________________________________________ GeoTools-GT2-Users mailing list GeoTools-GT2-Users@lists.sourceforge.net https://lists.sourceforge.net/lists/listinfo/geotools-gt2-users