if (monitor == null)
monitor = new NullProgressMonitor();
monitor.beginTask("csv render", 100);
CSVReader reader = null;
try {
g.setColor(Color.BLACK);
ILayer layer = getContext().getLayer();
IGeoResource resource = layer.findGeoResource(CSV.class);
if (resource == null)
return;
CoordinateReferenceSystem dataCRS = layer.getCRS();
CoordinateReferenceSystem worldCRS = context.getCRS();
MathTransform dataToWorld = CRS.findMathTransform(dataCRS, worldCRS, false);
ReferencedEnvelope bounds = getRenderBounds();
monitor.subTask("connecting");
CSV csv = resource.resolve(CSV.class, new SubProgressMonitor(monitor, 10) );
reader = csv.reader();
int nameIndex = csv.getHeader("name");
IProgressMonitor drawMonitor = new SubProgressMonitor(monitor, 90);
Coordinate worldLocation = new Coordinate();
drawMonitor.beginTask("draw "+csv.toString(), csv.getSize());
String [] row;
while ((row = reader.readNext()) != null) {
Point point = csv.getPoint(row);
Coordinate dataLocation = point.getCoordinate();
try {
JTS.transform(dataLocation, worldLocation, dataToWorld);
} catch (TransformException e) {
continue;
}
if (bounds != null && !bounds.contains(worldLocation)) {
continue; // optimize!
}
java.awt.Point p = getContext().worldToPixel(worldLocation);
g.fillOval(p.x, p.y, 10, 10);
String name = row[nameIndex];
g.drawString(name, p.x + 15, p.y + 15);
drawMonitor.worked(1);
if (drawMonitor.isCanceled())
break;
}
drawMonitor.done();
} catch (IOException e) {
throw new RenderException(e); // rethrow any exceptions encountered
} catch (FactoryException e) {
throw new RenderException(e); // rethrow any exceptions encountered
} finally {
if (reader != null)
try {
reader.close();
} catch (IOException e) {
throw new RenderException(e);
}
monitor.done();
}