0
Java Open Source GIS          DevelopmentFrom the building blocks to extending    an existing GIS application. Geoinformat...
Who am I?Andrea Antonello      Environmental Engineer, graduated with GRASS development thesis      PhD in Environmental S...
Buzzwords: Java, Maven and EclipseJava        The Java technology is a programming language and a platform.Maven        Ma...
Buzzwords: GeoTools, JTS and OGCGeoTools      GeoTools is an open source (LGPL) Java code library which provides      stan...
Buzzwords: uDig, OMS and JGrasstoolsUser-friendly Desktop Internet GIS      uDig is an open source (LGPL) desktop GIS, bui...
Useful spatial linksSpatial: • GeoTools Homepage • uDig Homepage • OMS3 Homepage • JGrasstools Homepage • Imageio-ext Home...
Useful development linksJava and friends: • Java Downloads / Java Instructions • JAI Core Homepage / JAI Core Downloads / ...
Contents of the course                  Part 1: Introduction and main tools• setup of java, eclipse, maven• introduction t...
Part 2: Introduction of the main Geo-Objects• geometry objects• projections• vector objects• raster objects• filters• style
Part 3: Vector data• vector basics, handling shapefiles• geometry basics   • predicates   • functions   • tips and tricks
Part 4: Raster data• reading/writing raster data• processing rasters• image vs. world space
Part 5: Integrating with uDig• introduction to OMS• introduction to uDig• introduction to uDigs Spatial Toolbox• introduct...
Preparing the development environment                              Java InstallationPerform the following installations, b...
Eclipse Installation1. Visit the Eclipse HomePage and download Eclipse IDE for Java   developers.2. Eclipse does not provi...
7. When you start up eclipse for the first time it will prompt you for a   workspace. To keep our java work in one spot yo...
Maven InstallationThe maven build tool can work on the command line and includes a pluginfor generating eclipse .project a...
JAVA_HOME             /home/moovida/java/jdk1.6.0_16  M2_HOME               /home/moovida/giscourse/apache-maven-2.2.1/  P...
6. This should produce something like:    Apache Maven 2.2.1 (r801777; 2009-08-06 21:16:01+0200)    Java version: 1.6.0_14...
Setting up the example project in EclipseTo get started quickly we will use a template project that already contains thede...
If starting from scratch, we would have created a new maven project inside/home/moovida/giscourse/ with the command: mvn a...
DependenciesThe downloaded project is a maven project that already contains all theneeded dependencies (the references).Ev...
RepositoriesMost of the packages are kept in a central maven repository. GeoToolspackages are hosted by the Open Source Ge...
Create the Eclipse projectTo actually get the dependencies downloaded, we can proceed like thefollowing:1. From within /ho...
Load the Eclipse project4. Add an M2_REPO classpath variable pointing to your local repository,   which is created automat...
Testing the development environment                          Download a test datasetThe best way to check if the developme...
Write and run your first GIS application• copy the following code snippetimport   java.io.File;import   org.geotools.data....
• run the application by right clicking on the class and run as -> java   application • browse in the filechooser to selec...
The first (and most boring) step is left behind.              Take a deep breath.                QUESTIONS?
This work is released under Creative Commons Attribution ShareAlike (CC-BY-SA)Much of the knowledge needed to create this ...
Upcoming SlideShare
Loading in...5
×

Opensource gis development - part 1

2,181

Published on

0 Comments
1 Like
Statistics
Notes
  • Be the first to comment

No Downloads
Views
Total Views
2,181
On Slideshare
0
From Embeds
0
Number of Embeds
1
Actions
Shares
0
Downloads
76
Comments
0
Likes
1
Embeds 0
No embeds

No notes for slide

Transcript of "Opensource gis development - part 1"

  1. 1. Java Open Source GIS DevelopmentFrom the building blocks to extending an existing GIS application. Geoinformation Research Group, Department of Geography University of Potsdam August 2011 Part 1: Introduction and main tools Tutor: Andrea Antonello ydroloGIS nvironmental ngineeringHydroloGIS S.r.l. - Via Siemens, 19 - 39100 Bolzano www.hydrologis.com
  2. 2. Who am I?Andrea Antonello Environmental Engineer, graduated with GRASS development thesis PhD in Environmental Sciences, working on development of digital field mapping toolsGIS development Involved for years in open source GIS development, mainly GRASS, JGrass, uDig, BeeGIS, GeopaparazziHydroloGIS Work for HydroloGIS, a company that writes and uses GFOSS products for environmental analyses, mostly hydrology and geomorphology.
  3. 3. Buzzwords: Java, Maven and EclipseJava The Java technology is a programming language and a platform.Maven Maven is build system for Java which is very good at managing dependencies.Eclipse IDE Eclipse is a popular integrated development environment most often used for all kinds of Java development.Eclipse RCP The rich client platform used to build applications like uDig, but also the eclipse IDE itself.
  4. 4. Buzzwords: GeoTools, JTS and OGCGeoTools GeoTools is an open source (LGPL) Java code library which provides standards compliant methods for the manipulation of geospatial data, for example to implement Geographic Information Systems (GIS).Java Topology Suite The JTS Topology Suite is a library of spatial predicates and functions for processing geometry.Open Geospatial Consortium The OGC is a non-profit, international, voluntary consensus standards organization that is leading the development of standards for geospatial and location based services.
  5. 5. Buzzwords: uDig, OMS and JGrasstoolsUser-friendly Desktop Internet GIS uDig is an open source (LGPL) desktop GIS, built with Eclipse Rich Client (RCP) technology.Object Modeling System The OMS object-oriented modeling framework. OMS allows model construction and model application based on components.JGrasstools A geospatial processing library based on OMS that works in uDigs Spatial Toolbox.
  6. 6. Useful spatial linksSpatial: • GeoTools Homepage • uDig Homepage • OMS3 Homepage • JGrasstools Homepage • Imageio-ext Homepage • JTS Homepage
  7. 7. Useful development linksJava and friends: • Java Downloads / Java Instructions • JAI Core Homepage / JAI Core Downloads / JAI Core Instructions • JAI ImageIO Homepage / JAI ImageIO Downloads / JAI ImageIO Instructions • Maven Homepage • Eclipse HomePage
  8. 8. Contents of the course Part 1: Introduction and main tools• setup of java, eclipse, maven• introduction to the GeoTools project• introduction to the Natural Earth project• creation of a simple GeoTools based project• visualization of a map
  9. 9. Part 2: Introduction of the main Geo-Objects• geometry objects• projections• vector objects• raster objects• filters• style
  10. 10. Part 3: Vector data• vector basics, handling shapefiles• geometry basics • predicates • functions • tips and tricks
  11. 11. Part 4: Raster data• reading/writing raster data• processing rasters• image vs. world space
  12. 12. Part 5: Integrating with uDig• introduction to OMS• introduction to uDig• introduction to uDigs Spatial Toolbox• introduction to jgrasstools• create example OMS GeoTools based modules
  13. 13. Preparing the development environment Java InstallationPerform the following installations, based on the download and instructionslinks supplied in the previous section: • Java Development Kit (JDK) • Java Advanced Imaging (JAI core), used by GeoTools for raster support • JAI ImageIO, used to read and write raster files • ImageIO-ext, used to support raster formats through gdal drivers:
  14. 14. Eclipse Installation1. Visit the Eclipse HomePage and download Eclipse IDE for Java developers.2. Eclipse does not provide an installer, just unzip to a directory run.3. To start out create a folder /home/moovida/giscourse/ somewhere on your disk to keep all our java development in one spot. To keep an existing reference we will use /home/moovida/ as base, which should be substituted with a folder of choice.4. Unzip the downloaded file to your /home/moovida/giscourse/ folder, which will create /home/moovida/giscourse/eclipse/.5. Open up the eclipse.ini file and changing the Xmx argument to -Xmx2000m, if you have enough RAM.6. Run the eclipse executable.
  15. 15. 7. When you start up eclipse for the first time it will prompt you for a workspace. To keep our java work in one spot you can type in: /home/moovida/giscourse/eclipse/workspace8. On the Welcome view press Workbench along the right hand side and we can get started
  16. 16. Maven InstallationThe maven build tool can work on the command line and includes a pluginfor generating eclipse .project and .classpath files.1. Download Maven from the Maven Homepage During the course we will use Maven 2.2.1.2. Unzip the file apache-maven-2.2.1-bin.zip to /home/moovida/giscourse/apache-maven-2.2.1/.3. You need to have a couple of environmental variables set for maven to work. Open inside your favourite text editor the .bashrc file inside you home folder and add the following lines at the end (if similar ones are not there already):
  17. 17. JAVA_HOME /home/moovida/java/jdk1.6.0_16 M2_HOME /home/moovida/giscourse/apache-maven-2.2.1/ PATH $PATH:$JAVA_HOME/bin:$M2_HOME/bin4. Open up a terminal5. Type the following command to confirm you are set up correctly: mvn -version
  18. 18. 6. This should produce something like: Apache Maven 2.2.1 (r801777; 2009-08-06 21:16:01+0200) Java version: 1.6.0_14 Java home: /home/moovida/SOFTWARE/JAVA/JDKS/jdk1.6.0_14/jre Default locale: en_US, platform encoding: UTF-8 OS name: "linux" version: "2.6.38-8-generic" arch: "amd64" Family: "unix"
  19. 19. Setting up the example project in EclipseTo get started quickly we will use a template project that already contains thedependencies we will need. The example project can be downloaded from:http://jgrasstools.googlecode.com/files/jgt-dev-example.tar.gzCreate the folder /home/moovida/giscourse/code/ that will hold all thecode we will write during the course. Extract the downloaded package intothe code folder (tar zcvf jgt-dev-example.tar.gz). You now havethe folder: /home/moovida/giscourse/code/jgt-dev-example.
  20. 20. If starting from scratch, we would have created a new maven project inside/home/moovida/giscourse/ with the command: mvn archetype:create -DgroupId=org.geotools -DartifactId=tutorialand after that we would have added the dependencies to the projectsconfiguration file.Starting with an existing project helps to how the dependencies rules work,without the need to understand all of maven.
  21. 21. DependenciesThe downloaded project is a maven project that already contains all theneeded dependencies (the references).Everything needed is defined inside the pom.xml file in the root of theproject.A dependency definition looks like: <dependency> <groupId>org.jgrasstools</groupId> <artifactId>jgt-jgrassgears</artifactId> <version>0.7.1</version> </dependency>To find such dependencies when you have no template, websites like:http://mvnrepository.com/ get handy.
  22. 22. RepositoriesMost of the packages are kept in a central maven repository. GeoToolspackages are hosted by the Open Source Geospatial Foundation (OsgeoHomepage).Any repository can be added to the pom.xml project file. In our example wefind: <repository> <id>maven2-repository.dev.java.net</id> <name>Java.net repository</name> <url>http://download.java.net/maven/2</url> </repository> <repository> <id>osgeo</id> <name>Open Source Geospatial Foundation Repository</name> <url>http://download.osgeo.org/webdav/geotools/</url> </repository>
  23. 23. Create the Eclipse projectTo actually get the dependencies downloaded, we can proceed like thefollowing:1. From within /home/moovida/giscourse/code/jgt-dev-example And ask for our project to be set up for eclipse: mvn eclipse:eclipse This will generate the eclipse project files and download the needed jars for you.2. Return to Eclipse3. Use Windows -> Preferences to open the Preference Dialog. Using the tree on the left navigate to the Java -> Build path -> Classpath Variables preference page.
  24. 24. Load the Eclipse project4. Add an M2_REPO classpath variable pointing to your local repository, which is created automatically by maven itself and by default is located in: /home/moovida/.m2/repository.5. We can now import your new project into eclipse using File -> Import6. Choose Existing Projects into Workspace from the list, and press Next7. Select the project you created in: /home/moovida/giscourse/code/jgt-dev-example.8. Press Finish to import your project
  25. 25. Testing the development environment Download a test datasetThe best way to check if the development environment is properly installed,is to show a map. First we need some data to work with. The Natural Earthdata project is a place we can get some freely available datasets. It issupported by the North American Cartographic Information Society.Lets download 110m-cultural.zip, which contains various vector layers ofcountries, boundaries and cities of the whole world.create a datafolder: /home/moovida/giscourse/dataand unzip them into it in order to have:/home/moovida/giscourse/data/110m_cultural
  26. 26. Write and run your first GIS application• copy the following code snippetimport java.io.File;import org.geotools.data.*;import org.geotools.data.simple.SimpleFeatureSource;import org.geotools.map.*;import org.geotools.styling.*;import org.geotools.swing.JMapFrame;import org.geotools.swing.data.JFileDataStoreChooser;public class Quickstart { public static void main( String[] args ) throws Exception { File file = JFileDataStoreChooser.showOpenFile("shp", null); FileDataStore store = FileDataStoreFinder.getDataStore(file); SimpleFeatureSource featureSource = store.getFeatureSource(); MapContext map = new MapContext(); map.setTitle("Quickstart"); Style style = SLD.createSimpleStyle(featureSource.getSchema()); Layer layer = new FeatureLayer(featureSource, style); map.addLayer(layer); JMapFrame.showMap(map); }}• select the org.jgrasstools.part1 package in the project• paste the code in (eclipse will create the right class for it)
  27. 27. • run the application by right clicking on the class and run as -> java application • browse in the filechooser to select the file: 110m_admin_0_countries.shpYou should see the following map:
  28. 28. The first (and most boring) step is left behind. Take a deep breath. QUESTIONS?
  29. 29. This work is released under Creative Commons Attribution ShareAlike (CC-BY-SA)Much of the knowledge needed to create this training material hasbeen produced by the sparkling knights of the GeoTools, JTS anduDig community. Another essential source has been the Wikipediacommunity effort.Particular thanks go to those friends that directly or indirectly helpedout in the creation and review of this developers handbook: JodyGarnett from the uDig/GeoTools community and the TANTO team.This tutorial was written with the support of the GeoinformationResearch Group of the University of Potsdam and HydroloGIS.
  1. A particular slide catching your eye?

    Clipping is a handy way to collect important slides you want to go back to later.

×