Try this example and see if it works for you...
package org.geotools.userlist;
import java.awt.Color;
import com.vividsolutions.jts.geom.Coordinate;
import com.vividsolutions.jts.geom.GeometryFactory;
import com.vividsolutions.jts.geom.Point;
import org.geotools.data.simple.SimpleFeatureCollection;
import org.geotools.feature.FeatureCollections;
import org.geotools.feature.simple.SimpleFeatureBuilder;
import org.geotools.feature.simple.SimpleFeatureTypeBuilder;
import org.geotools.geometry.jts.JTSFactoryFinder;
import org.geotools.map.FeatureLayer;
import org.geotools.map.Layer;
import org.geotools.map.MapContent;
import org.geotools.referencing.crs.DefaultEngineeringCRS;
import org.geotools.styling.SLD;
import org.geotools.styling.Style;
import org.geotools.swing.JMapFrame;
import org.opengis.feature.simple.SimpleFeature;
import org.opengis.feature.simple.SimpleFeatureType;
public class CalculatedPointsExample {
private static final GeometryFactory GEOMFAC =
JTSFactoryFinder.getGeometryFactory();
public static void main(String[] args) {
new CalculatedPointsExample().runMe();
}
private void runMe() {
final SimpleFeatureType TYPE = createFeatureType();
final SimpleFeatureBuilder BLDR = new SimpleFeatureBuilder(TYPE);
SimpleFeatureCollection features = FeatureCollections.newCollection();
// arbitrary start pos
Coordinate pos = new Coordinate(0, 0);
final double pointSpacing = 1.0;
int id = 0;
features.add(createFeature(BLDR, pos, id));
while (true) {
pos = nextPos(pos, pointSpacing);
if (pos.y < 0) {
break;
}
features.add(createFeature(BLDR, pos, ++id));
}
// Display the points on screen
Style style = SLD.createPointStyle("circle", Color.BLUE,
Color.BLUE, 1.0f, 5.0f);
Layer layer = new FeatureLayer(features, style);
MapContent map = new MapContent();
map.addLayer(layer);
// It is safe to call this method from any thread (not just
// the Event Dispatch Thread as is usual for Swing widgets)
JMapFrame.showMap(map);
}
/*
* Generates a point on the parabola y = -0.005x^2 + 0.5x
*/
private Coordinate nextPos(Coordinate startPos, double dist) {
double x = startPos.x + dist;
return new Coordinate(x, -0.01 * x * x + x );
}
private SimpleFeatureType createFeatureType() {
SimpleFeatureTypeBuilder typeBldr = new SimpleFeatureTypeBuilder();
typeBldr.setName("trajectory");
typeBldr.add("pos", Point.class, DefaultEngineeringCRS.CARTESIAN_2D);
typeBldr.add("id", Integer.class);
return typeBldr.buildFeatureType();
}
private SimpleFeature createFeature(SimpleFeatureBuilder bldr,
Coordinate pos, int id) {
Point p = GEOMFAC.createPoint(pos);
bldr.add(p);
bldr.add(id);
// null arg means allow the builder to generate a default feature ID
return bldr.buildFeature(null);
}
}
------------------------------------------------------------------------------
Virtualization & Cloud Management Using Capacity Planning
Cloud computing makes use of virtualization - but cloud computing
also focuses on allowing computing to be delivered as a service.
http://www.accelacomm.com/jaw/sfnl/114/51521223/
_______________________________________________
GeoTools-GT2-Users mailing list
[email protected]
https://lists.sourceforge.net/lists/listinfo/geotools-gt2-users