Javafx and WorldWindJava("Africa Flights")
Stumbled upon airports and flight route data that means a javafx project although not much of javafx coding.The data contains 6 data sets i used the citiesToCities.csv data set.the data has departure locations and arrival locations as coordinates.
The coding
WorldWind.setOfflineMode(true);
WorldWindowGLJPanel wwd = new WorldWindowGLJPanel();
wwd.setPreferredSize(new java.awt.Dimension(1000, 700));
BasicModel basicModel=new BasicModel();
wwd.setModel(basicModel);
EarthFlat earthflat=new EarthFlat();
wwd.getModel().setGlobe(earthflat);
SwingNode swingNode=new SwingNode();
swingNode.setContent(wwd);//convert awt to node
List<String> lines=Files.readAllLines(Paths.get("c:"));
RenderableLayer rl=new RenderableLayer();
for(String s:lines){
String depature_country=s.split(",")[3];
String arrival_country=s.split(",")[7];
if(//depature_country and arrival_country equals african countries//){
double dep_lon=Double.valueOf(s.split(",")[1]);
double dep_lat=Double.valueOf(s.split(",")[2]);
double arr_lon=Double.valueOf(s.split(",")[5]);
double arr_lat=Double.valueOf(s.split(",")[6]);
Position lat=Position.fromDegrees(dep_lat,dep_lon);
Position lon=Position.fromDegrees(arr_lat,arr_lon);
Polyline line=new Polyline(Arrays.asList(lat,lon),3e4);
line.setPathType(Polyline.RHUMB_LINE);
rl.addRenderable(line);
}
}
To achieve a globe with only the line and the shapefile ,remove all the layers from the globe.
wwd.getModel().getLayers().removeAll();
create a layerlist with only the renderable layer
LayerList layer=new LayerList();
layer.add(rl);
add the renderable layer
wwd.getModel().getLayers().addAll(layer);
Working with the Shapefiles.
Using the ShapefileLoader class is quite easy but you cannot set any visual attributes ,so i extend the ShapefileLoader class and override the createPolygonAttributes method,this what i did
public class KenyaShapeFile extends ShapefileLoader{
Shapefile shapefile;
ShapeColor(String s){
this.shapefile=new Shapefile(new File(s));
}
public void createMyPolygon(RenderableLayer rl){
while(this.shapefile.hasNext()){
ShapefileRecord record =this.shapefile.nextRecord();
ShapeAttributes attrs = this.createPolygonAttributes(record);
attrs.setOutlineMaterial(Material.YELLOW);
attrs.setOutlineOpacity(1);
attrs.setInteriorMaterial(Material.BLACK);
attrs.setInteriorOpacity(1);
this.createPolygon(record, attrs, rl);
}
}
}
adding the shapefile to the wwd
KenyaShapeFile kenya_shape_file=new KenyaShapeFile("kenya_outside_boundary.shp");
kenya_shape_file.createMyPolygon(rl);
The scale on the top_right its a flowpane with vertical orientation and children as text, rectangles and labels all in javafx.
The Results
The coding
WorldWind.setOfflineMode(true);
WorldWindowGLJPanel wwd = new WorldWindowGLJPanel();
wwd.setPreferredSize(new java.awt.Dimension(1000, 700));
BasicModel basicModel=new BasicModel();
wwd.setModel(basicModel);
EarthFlat earthflat=new EarthFlat();
wwd.getModel().setGlobe(earthflat);
SwingNode swingNode=new SwingNode();
swingNode.setContent(wwd);//convert awt to node
List<String> lines=Files.readAllLines(Paths.get("c:"));
RenderableLayer rl=new RenderableLayer();
for(String s:lines){
String depature_country=s.split(",")[3];
String arrival_country=s.split(",")[7];
if(//depature_country and arrival_country equals african countries//){
double dep_lon=Double.valueOf(s.split(",")[1]);
double dep_lat=Double.valueOf(s.split(",")[2]);
double arr_lon=Double.valueOf(s.split(",")[5]);
double arr_lat=Double.valueOf(s.split(",")[6]);
Position lat=Position.fromDegrees(dep_lat,dep_lon);
Position lon=Position.fromDegrees(arr_lat,arr_lon);
Polyline line=new Polyline(Arrays.asList(lat,lon),3e4);
line.setPathType(Polyline.RHUMB_LINE);
rl.addRenderable(line);
}
}
To achieve a globe with only the line and the shapefile ,remove all the layers from the globe.
wwd.getModel().getLayers().removeAll();
create a layerlist with only the renderable layer
LayerList layer=new LayerList();
layer.add(rl);
add the renderable layer
wwd.getModel().getLayers().addAll(layer);
Working with the Shapefiles.
Using the ShapefileLoader class is quite easy but you cannot set any visual attributes ,so i extend the ShapefileLoader class and override the createPolygonAttributes method,this what i did
public class KenyaShapeFile extends ShapefileLoader{
Shapefile shapefile;
ShapeColor(String s){
this.shapefile=new Shapefile(new File(s));
}
public void createMyPolygon(RenderableLayer rl){
while(this.shapefile.hasNext()){
ShapefileRecord record =this.shapefile.nextRecord();
ShapeAttributes attrs = this.createPolygonAttributes(record);
attrs.setOutlineMaterial(Material.YELLOW);
attrs.setOutlineOpacity(1);
attrs.setInteriorMaterial(Material.BLACK);
attrs.setInteriorOpacity(1);
this.createPolygon(record, attrs, rl);
}
}
}
adding the shapefile to the wwd
KenyaShapeFile kenya_shape_file=new KenyaShapeFile("kenya_outside_boundary.shp");
kenya_shape_file.createMyPolygon(rl);
The scale on the top_right its a flowpane with vertical orientation and children as text, rectangles and labels all in javafx.
The Results
Comments
Post a Comment