Hello Martin,
First I'll point out one way to do this and then I'll tell you why I
don't like it :-)
When you create a point feature from a JTS Point, which in turn was
created from a Coordinate, each step takes ownership of the Coordinate
instance rather than copying it as demonstrated by this code
snippet...
GeometryFactory gf = JTSFactoryFinder.getGeometryFactory(null);
Coordinate c = new Coordinate(10, 20);
Point p = gf.createPoint(c);
SimpleFeatureType TYPE = DataUtilities.createType("mytype",
"the_geom:Point, id:String");
SimpleFeature f = SimpleFeatureBuilder.build(TYPE, new
Object[]{p, "1"}, null);
Point p2 = (Point) f.getDefaultGeometry();
// this will print POINT(10 20)
System.out.println(p2);
c.x = 30;
c.y = 40;
p2 = (Point) f.getDefaultGeometry();
// this will print POINT(30 40)
System.out.println(p2);
So, it would be possible to have an array of Coordinates and modify
these directly to change the feature data that you are rendering.
Now, why I don't like this approach...
1. It's fragile. There's nothing in the API that guarantees this
behaviour. It's just how it works at the moment (as an aside, this has
caused me grief in the past when I inadvertently recycled Coordinates
when creating Geometries).
2. It bypasses the GeoTools system for detecting changes to feature
data and publishing such events to other classes, such as the
renderer.
If you're not put off by the above problems then you can certainly do
it, but for your use case, as you have described it on another thread,
I think it's a particularly bad idea. Having your moving elements
represented as features in a map layer, along with the layer(s) for
the static background, will mean that the renderer has to paint the
background again when an element moves. You can ask the renderer to
just paint a rectangle of the map rather than everything but it will
still be very inefficient compared to painting the moving elements
onto the map with custom code as in the demo app.
Hope this helps.
Michael
------------------------------------------------------------------------------
Throughout its 18-year history, RSA Conference consistently attracts the
world's best and brightest in the field, creating opportunities for Conference
attendees to learn about information security's most important issues through
interactions with peers, luminaries and emerging and established companies.
http://p.sf.net/sfu/rsaconf-dev2dev
_______________________________________________
Geotools-gt2-users mailing list
[email protected]
https://lists.sourceforge.net/lists/listinfo/geotools-gt2-users