Presentation is loading. Please wait.

Presentation is loading. Please wait.

Programming for Geographical Information Analysis: Advanced Skills Lecture 7: Libraries I: Visualisation Dr Andy Evans.

Similar presentations


Presentation on theme: "Programming for Geographical Information Analysis: Advanced Skills Lecture 7: Libraries I: Visualisation Dr Andy Evans."— Presentation transcript:

1 Programming for Geographical Information Analysis: Advanced Skills Lecture 7: Libraries I: Visualisation Dr Andy Evans

2 Libraries Graphing Geographical data Processing

3 Libraries Code put together for others to use. Usually in the form of jar files. May contain native dynamically linked libraries (dll) and others, but more usually just jar files. Consult notes, as dlls etc. sometimes needed, but more usually these are libraries for other languages.

4 Managing Libraries Download the library. Make sure it is in your CLASSPATH when compiling and running. java -classpath ".;c:\libraries\lib.jar" YourClass [any problems, see http://en.wikipedia.org/wiki/Classpath_(Java) ] Alternatively, you can use a class management system.

5 Eclipse

6 Build automation tools GNU Make: Old UNIX system for installing complex programs on UNIX. Not pleasant to use. Apache Maven: XML based. Downloads required libraries. Organises compilation and creation of jar files. Demands a specific project structure. Eclipse : File → New → Project → Maven Apache Ant: XML version of Make. More flexible / harder to get a grip on.

7 Libraries Graphing Geographical data Processing

8 Graphing JFreeChart http://www.jfree.org/jfreechart/

9 Setting up a Graph Set up a dataset. JFreeChart chart = ChartFactory.createXChart(dataset); XPlot plot = (XPlot) chart.getPlot(); Adjust form, colour, etc. of plot if necessary. ChartPanel chartPanel = new ChartPanel(chart); Add chartPanel to Frame or similar

10 Example DefaultPieDataset data = new DefaultPieDataset(); data.setValue("Cherry", 30); data.setValue("Steak and Kidney", 25); data.setValue("Stargazy", 45); JFreeChart chart = ChartFactory.createPieChart3D ("Favourite Pies", data, true, true, false); PiePlot3D plot = (PiePlot3D) chart.getPlot(); plot.setForegroundAlpha(0.5f); ChartPanel chartPanel = new ChartPanel(chart);

11

12 Other graphing packages InfoVis (Javascript + JSON) http://philogb.github.io/jit/ D3 (DOM styling) http://d3js.org/ Raphael http://raphaeljs.com/

13 Libraries Graphing Geographical data KML Free mapping services GeoTools Cartograms Processing

14 Geographical data Keyhole Markup Language (KML) http://www.opengeospatial.org/standards/kml/ https://developers.google.com/kml/documentation/

15 Google KML can be combined with GoogleMaps. Can be used to overlay information on GoogleEarth. Test suite: https://kml- samples.googlecode.com/svn/trunk/interactive/index.html GoogleMaps can also pull in GeoRSS streams.

16 KML OGS specification. At simplest, a little like the XML we looked at last lecture: 10,10,1 10,20,1 20,20,1 20,10,1 10,10,1

17 Other free mapping services Google WebGL Globe http://www.chromeexperiments.com /globe PhiloGL http://www.senchalabs.org/ philogl/

18 Geographical data GeoTools (Leeds et al.): http://geotools.org/

19 Features Mapping Includes simple Swing components for showing maps. GML/XML conversion Web service setup Interaction with databases Shapefile read and write Graph and Network tools Spatial queries

20 Data formats Raster formats and data access: arcsde, arcgrid, geotiff, grassraster, gtopo30, image (JPEG, TIFF, GIF, PNG), imageio-ext-gdal, imagemoasaic, imagepyramid, JP2K, matlab Database jdbc support: db2, h2, mysql, oracle, postgis, spatialite, sqlserver Vector formats and data access: app-schema, arcsde, csv, dxf, edigeo, excel, geojson, org, property, shapefile, wfs XML Bindings: Java data structures and bindings provided for the following: xsd- core (xml simple types), fes, filter, gml2, gml3, kml, ows, sld, wcs, wfs, wms, wps, vpf. Additional Geometry, Filter and Style parser/encoders available for DOM and SAX applications.

21 Example FileDataStore store = FileDataStoreFinder.getDataStore(file); SimpleFeatureSource featureSource = store.getFeatureSource(); MapContent map = new MapContent(); map.setTitle("Quickstart"); Style style = SLD.createSimpleStyle(featureSource.getSchema()); Layer layer = new FeatureLayer(featureSource, style); map.addLayer(layer); JMapFrame.showMap(map);

22 GML http://docs.geotools.org/latest/userguide/library/xml/geometry.html http://docs.geotools.org/latest/userguide/library/xml/faq.html See org.geotools.gml in docs Also parses/produces KML.

23 Cartograms WorldMapper (Sheffield Geography): http://www.worldmapper.org/about. html Cartogram Geoprocessing Tool (Tom Gross): http://arcscripts.esri.com/details.asp? dbid=15638

24 Cartograms ScapeToad (Java: Chôros Laboratory) http://scapetoad.choros.ch/ Takes in shapefiles; exports shapefiles or SVG. You can download the src here: http://sourceforge.net/projects/scapetoad/files/scapetoad/ ScapeToad%201.1/ Nothing to stop you using it in other GNU General Public License, version 2, code.

25 Libraries Graphing Geographical data Processing

26 Processing http://processing.org/ MIT Media Lab Libraries for visualisation. Wraps a simple visualisation scripting language inside java classes. Also javascript /Android / iPhone javascript versions. Excellent community with a positive attitude to open sourcing good code.

27 Processing Development Environment Small put perfectly formed IDE. Saves as Applications, MPEG, SVG and PDFs. Bundles everything (data, libraries) into jars. Constructs executables.

28

29 Coding Two important methods: void setup(){ } Runs once at start. void draw(){} Runs each frame until stopped (60 frames s -1 ; but can be changed).

30 Coding float xCoor = 0; float yCoor = 100; float speed = 1; void setup() { size(200,200);// Size has to be first thing in setup } void draw() { background(255);// Wipe the background white xCoor = xCoor + speed;// Change x location if (xCoor > width) {// Reset if it runs of the screen. xCoor = 0; } fill(0);// Paint a rectangle rect(xCoor,yCoor,30,10); }

31 Objects In the PDE you can put code in different tabs. However, you can also just put multiple classes in one tab. Processing will wrap them all inside its own class, as ‘inner classes’.

32 Java development Extend the Processing wrapper PApplet. Add in your Processing code. If you want it to run as an application, add: public static void main(String args[]) { PApplet.main(new String[] { "--present", "MyProcessingSketch“ }); } For multiple classes you need to get a reference to the Papplet class into your class then call, e.g. papplet.draw();

33 Eclipse There is an Eclipse plugin: http://wiki.processing.org/w/Eclipse_Plug_In However, you can write just as well without it: http://processing.org/learning/eclipse/ If you run as an applet in Eclipse and want to run as an application, go into File -> Properties and delete the Launch Configuration or use the arrow on the run button to “Run As”.

34 Processing tips Processing creates a project ‘sketchbook’ directory called after the main file for each project. It expects to find all data in a data directory in here. Libraries should also be in a ‘libraries’ directory, though better to just ‘Add File’ them. Avoid variable names it might already use, like pixels, x, y, and z. http://forum.processing.org/topic/reserved-keywords-wiki-page If you separate classes into other files, call them, e.g. “Car” rather than “Car.java” – the latter signals that Processing should treat it as Java, and you’ll need to import the classes etc.

35 Other Processing Libraries for: XML / GPS interaction / Network communications Mapping Connections with Ruby/Python/Javascript Video / Sound Communications with hardware Webcam and motion recognition Spinoff projects: Wiring/ Arduino – chipboards for hardware development

36 Other versions The preferred option now is to generate a javascript version of the code. You can do this by adding the javascript mode to version 2 and changing to it (need to reboot). Unfortunately this is doesn’t work well with libraries, so you may want 1.5 for web work. Also an Android option. 1.5 rather nicely generates a webpage for you with the source code and an applet version embedded in it.

37 Book Great book on processing, but also modelling real systems more generally, is:

38 Visualisation inspiration http://visual.ly/ http://www.visualisingdata.com/ Books: JFreeChart developer guide. Processor books (see website) Visualisation books by Edward Tufte

39 Next Lecture Libraries II: Scientific libraries Practical JFreeChart Processing


Download ppt "Programming for Geographical Information Analysis: Advanced Skills Lecture 7: Libraries I: Visualisation Dr Andy Evans."

Similar presentations


Ads by Google