Skip to content

Instantly share code, notes, and snippets.

@rafalrusin
Created June 12, 2011 21:55
Show Gist options
  • Save rafalrusin/1022034 to your computer and use it in GitHub Desktop.
Save rafalrusin/1022034 to your computer and use it in GitHub Desktop.
GIS data visualization
File file = new File("110m_cultural\\110m_admin_0_countries.shp");
FileDataStore store = FileDataStoreFinder.getDataStore(file);
SimpleFeatureSource featureSource = store.getFeatureSource();
SimpleFeatureCollection c = featureSource.getFeatures();
SimpleFeatureIterator featuresIterator = c.features();
Coordinate[] coords;
Geometry polygon;
Point centroid;
Bounds bounds;
while (featuresIterator.hasNext()) {
SimpleFeature o = featuresIterator.next();
String name = (String) o.getAttribute("NAME");
Object geometry = o.getDefaultGeometry();
}
map.setOnMousePressed(new EventHandler<MouseEvent>() {
public void handle(MouseEvent event) {
scene.setCursor(Cursor.MOVE);
dragBaseX = map.translateXProperty().get();
dragBaseY = map.translateYProperty().get();
dragBase2X = event.getSceneX();
dragBase2Y = event.getSceneY();
}
});
map.setOnMouseDragged(new EventHandler<MouseEvent>() {
public void handle(MouseEvent event) {
map.setTranslateX(dragBaseX + (event.getSceneX()-dragBase2X));
map.setTranslateY(dragBaseY + (event.getSceneY()-dragBase2Y));
}
});
map.setOnMouseReleased(new EventHandler<MouseEvent>() {
public void handle(MouseEvent event) {
scene.setCursor(Cursor.DEFAULT);
}
});
if (geometry instanceof MultiPolygon) {
MultiPolygon multiPolygon = (MultiPolygon) geometry;
centroid = multiPolygon.getCentroid();
final Text text = new Text(name);
bounds = text.getBoundsInLocal();
text.getTransforms().add(new Translate(centroid.getX(), centroid.getY()));
text.getTransforms().add(new Scale(0.1,-0.1));
text.getTransforms().add(new Translate(-bounds.getWidth()/2., bounds.getHeight()/2.));
texts.getChildren().add(text);
for (int geometryI=0;geometryI<multiPolygon.getNumGeometries();geometryI++) {
polygon = multiPolygon.getGeometryN(geometryI);
coords = polygon.getCoordinates();
Path path = new Path();
path.setStrokeWidth(0.05);
currentColor = (currentColor+1)%colors.length;
path.setFill(colors[currentColor]);
path.getElements().add(new MoveTo(coords[0].x, coords[0].y));
for (int i=1;i<coords.length;i++) {
path.getElements().add(new LineTo(coords[i].x, coords[i].y));
}
path.getElements().add(new LineTo(coords[0].x, coords[0].y));
map1.getChildren().add(path);
}
}
private void zoom(double d) {
map.scaleXProperty().set(map.scaleXProperty().get() * d);
map.scaleYProperty().set(map.scaleYProperty().get() * d);
}
...
VBox vbox = new VBox();
final Button plus = new Button("+");
plus.setOnAction(new EventHandler<ActionEvent>() {
public void handle(ActionEvent event) {
zoom(1.4);
}
});
vbox.getChildren().add(plus);
final Button minus = new Button("-");
minus.setOnAction(new EventHandler<ActionEvent>() {
public void handle(ActionEvent event) {
zoom(1./1.4);
}
});
vbox.getChildren().add(minus);
root.getChildren().add(vbox);
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment