SlideShare ist ein Scribd-Unternehmen logo
1 von 29
Downloaden Sie, um offline zu lesen
Java Open Source GIS
          Development

From 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                 ngineering
HydroloGIS S.r.l. - Via Siemens, 19 - 39100 Bolzano   www.hydrologis.com
Who am I?
Andrea Antonello

      Environmental Engineer, graduated with GRASS development thesis

      PhD in Environmental Sciences, working on development of digital
      field mapping tools

GIS development

      Involved for years in open source GIS development, mainly GRASS,

      JGrass, uDig, BeeGIS, Geopaparazzi

HydroloGIS

      Work for HydroloGIS, a company that writes and uses GFOSS

      products    for   environmental   analyses,   mostly   hydrology   and

      geomorphology.
Buzzwords: Java, Maven and Eclipse
Java

        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.
Buzzwords: GeoTools, JTS and OGC
GeoTools

      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.
Buzzwords: uDig, OMS and JGrasstools
User-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 uDig's

      Spatial Toolbox.
Useful spatial links


Spatial:

 • GeoTools Homepage

 • uDig Homepage

 • OMS3 Homepage

 • JGrasstools Homepage

 • Imageio-ext Homepage

 • JTS Homepage
Useful development links


Java 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
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
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 uDig's Spatial Toolbox

• introduction to jgrasstools

• create example OMS GeoTools based modules
Preparing the development environment

                              Java Installation

Perform the following installations, based on the download and instructions

links 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:
Eclipse Installation

1. 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.
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/workspace

8. On the Welcome view press Workbench along the right hand side and we
   can get started
Maven Installation

The maven build tool can work on the command line and includes a plugin

for 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):
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/bin




4. Open up a terminal

5. Type the following command to confirm you are set up correctly:

    mvn -version
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"
Setting up the example project in Eclipse

To get started quickly we will use a template project that already contains the

dependencies we will need. The example project can be downloaded from:

http://jgrasstools.googlecode.com/files/jgt-dev-example.tar.gz

Create the folder /home/moovida/giscourse/code/ that will hold all the

code we will write during the course. Extract the downloaded package into

the code folder (tar zcvf jgt-dev-example.tar.gz). You now have

the folder: /home/moovida/giscourse/code/jgt-dev-example.
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=tutorial



and after that we would have added the dependencies to the project's

configuration file.


Starting with an existing project helps to how the dependencies rules work,

without the need to understand all of maven.
Dependencies

The downloaded project is a maven project that already contains all the

needed dependencies (the references).


Everything needed is defined inside the pom.xml file in the root of the

project.


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.
Repositories

Most of the packages are kept in a central maven repository. GeoTools'

packages are hosted by the Open Source Geospatial Foundation (Osgeo

Homepage).


Any repository can be added to the pom.xml project file. In our example we

find:

        <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>
Create the Eclipse project

To actually get the dependencies downloaded, we can proceed like the

following:

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 Eclipse

3. Use Windows -> Preferences to open the Preference Dialog. Using
   the tree on the left navigate to the Java -> Build path ->

   Classpath Variables preference page.
Load the Eclipse project


4. 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 ->

   Import

6. Choose Existing Projects into Workspace from the list, and

   press Next
7. Select the project you created in:
   /home/moovida/giscourse/code/jgt-dev-example.

8. Press Finish to import your project
Testing the development environment

                          Download a test dataset

The 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 Earth

data project is a place we can get some freely available datasets. It is

supported by the North American Cartographic Information Society.


Let's download 110m-cultural.zip, which contains various vector layers of

countries, boundaries and cities of the whole world.


create a datafolder: /home/moovida/giscourse/data


and unzip them into it in order to have:

/home/moovida/giscourse/data/110m_cultural
Write and run your first GIS application

• copy the following code snippet
import   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)
• 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.shp

You should see the following map:
The first (and most boring) step is left behind.
              Take a deep breath.


                QUESTIONS?
This work is released under Creative Commons Attribution Share
Alike (CC-BY-SA)

Much of the knowledge needed to create this training material has
been produced by the sparkling knights of the GeoTools, JTS and
uDig community. Another essential source has been the Wikipedia
community effort.

Particular thanks go to those friends that directly or indirectly helped
out in the creation and review of this developer's handbook: Jody
Garnett from the uDig/GeoTools community and the TANTO team.

This tutorial was written with the support of the Geoinformation
Research Group of the University of Potsdam and HydroloGIS.

Weitere ähnliche Inhalte

Ähnlich wie Opensource gis development - part 1

Writing Android Libraries
Writing Android LibrariesWriting Android Libraries
Writing Android Librariesemanuelez
 
Android training in Noida
Android training in NoidaAndroid training in Noida
Android training in NoidaSeoClass
 
Vipul divyanshu mahout_documentation
Vipul divyanshu mahout_documentationVipul divyanshu mahout_documentation
Vipul divyanshu mahout_documentationVipul Divyanshu
 
SenchaCon 2016: Building Enterprise Ext JS Apps with Mavenized Sencha Cmd - F...
SenchaCon 2016: Building Enterprise Ext JS Apps with Mavenized Sencha Cmd - F...SenchaCon 2016: Building Enterprise Ext JS Apps with Mavenized Sencha Cmd - F...
SenchaCon 2016: Building Enterprise Ext JS Apps with Mavenized Sencha Cmd - F...Sencha
 
Elements of Java Language
Elements of Java Language Elements of Java Language
Elements of Java Language Hitesh-Java
 
WebObjects Developer Tools
WebObjects Developer ToolsWebObjects Developer Tools
WebObjects Developer ToolsWO Community
 
01 04 - android set up and creating an android project
01  04 - android set up and creating an android project01  04 - android set up and creating an android project
01 04 - android set up and creating an android projectSiva Kumar reddy Vasipally
 
The Diabolical Developer's Guide to Surviving Java 9
The Diabolical Developer's Guide to Surviving Java 9The Diabolical Developer's Guide to Surviving Java 9
The Diabolical Developer's Guide to Surviving Java 9jClarity
 
Session 02 - Elements of Java Language
Session 02 - Elements of Java LanguageSession 02 - Elements of Java Language
Session 02 - Elements of Java LanguagePawanMM
 
Netbeans
NetbeansNetbeans
Netbeansacosdt
 
Java language: a gentle introduction
Java language: a gentle introductionJava language: a gentle introduction
Java language: a gentle introductionFabio Ferraguto
 
JAVA ALL 5 MODULE NOTES.pptx
JAVA ALL 5 MODULE NOTES.pptxJAVA ALL 5 MODULE NOTES.pptx
JAVA ALL 5 MODULE NOTES.pptxDrPreethiD1
 
Maven: Managing Software Projects for Repeatable Results
Maven: Managing Software Projects for Repeatable ResultsMaven: Managing Software Projects for Repeatable Results
Maven: Managing Software Projects for Repeatable ResultsSteve Keener
 

Ähnlich wie Opensource gis development - part 1 (20)

Gap search system
Gap search systemGap search system
Gap search system
 
Maven Introduction
Maven IntroductionMaven Introduction
Maven Introduction
 
Writing Android Libraries
Writing Android LibrariesWriting Android Libraries
Writing Android Libraries
 
InitiateAEv2.pdf
InitiateAEv2.pdfInitiateAEv2.pdf
InitiateAEv2.pdf
 
Android training in Noida
Android training in NoidaAndroid training in Noida
Android training in Noida
 
Vipul divyanshu mahout_documentation
Vipul divyanshu mahout_documentationVipul divyanshu mahout_documentation
Vipul divyanshu mahout_documentation
 
SenchaCon 2016: Building Enterprise Ext JS Apps with Mavenized Sencha Cmd - F...
SenchaCon 2016: Building Enterprise Ext JS Apps with Mavenized Sencha Cmd - F...SenchaCon 2016: Building Enterprise Ext JS Apps with Mavenized Sencha Cmd - F...
SenchaCon 2016: Building Enterprise Ext JS Apps with Mavenized Sencha Cmd - F...
 
Elements of Java Language
Elements of Java Language Elements of Java Language
Elements of Java Language
 
WebObjects Developer Tools
WebObjects Developer ToolsWebObjects Developer Tools
WebObjects Developer Tools
 
01 04 - android set up and creating an android project
01  04 - android set up and creating an android project01  04 - android set up and creating an android project
01 04 - android set up and creating an android project
 
Java part 1
Java part 1Java part 1
Java part 1
 
Class 1
Class 1Class 1
Class 1
 
Class 1
Class 1Class 1
Class 1
 
Microservices in Java
Microservices in JavaMicroservices in Java
Microservices in Java
 
The Diabolical Developer's Guide to Surviving Java 9
The Diabolical Developer's Guide to Surviving Java 9The Diabolical Developer's Guide to Surviving Java 9
The Diabolical Developer's Guide to Surviving Java 9
 
Session 02 - Elements of Java Language
Session 02 - Elements of Java LanguageSession 02 - Elements of Java Language
Session 02 - Elements of Java Language
 
Netbeans
NetbeansNetbeans
Netbeans
 
Java language: a gentle introduction
Java language: a gentle introductionJava language: a gentle introduction
Java language: a gentle introduction
 
JAVA ALL 5 MODULE NOTES.pptx
JAVA ALL 5 MODULE NOTES.pptxJAVA ALL 5 MODULE NOTES.pptx
JAVA ALL 5 MODULE NOTES.pptx
 
Maven: Managing Software Projects for Repeatable Results
Maven: Managing Software Projects for Repeatable ResultsMaven: Managing Software Projects for Repeatable Results
Maven: Managing Software Projects for Repeatable Results
 

Mehr von Andrea Antonello

GEOPAPARAZZI: STATE OF THE ART OF THE DIGITAL FIELD MAPPING APPLICATION
GEOPAPARAZZI: STATE OF THE ART OF THE DIGITAL FIELD MAPPING APPLICATIONGEOPAPARAZZI: STATE OF THE ART OF THE DIGITAL FIELD MAPPING APPLICATION
GEOPAPARAZZI: STATE OF THE ART OF THE DIGITAL FIELD MAPPING APPLICATIONAndrea Antonello
 
GEOPAPARAZZI STATE OF THE ART OF THE DIGITAL FIELD MAPPING APPLICATION
GEOPAPARAZZI STATE OF THE ART OF THE DIGITAL FIELD MAPPING APPLICATIONGEOPAPARAZZI STATE OF THE ART OF THE DIGITAL FIELD MAPPING APPLICATION
GEOPAPARAZZI STATE OF THE ART OF THE DIGITAL FIELD MAPPING APPLICATIONAndrea Antonello
 
Geopaparazzi Survey Server workshop
Geopaparazzi Survey Server workshopGeopaparazzi Survey Server workshop
Geopaparazzi Survey Server workshopAndrea Antonello
 
Geopaparazzi Survey Server Installation
Geopaparazzi Survey Server InstallationGeopaparazzi Survey Server Installation
Geopaparazzi Survey Server InstallationAndrea Antonello
 
Modelling natural hazards in gvSIG with the HortonMachine plugins
Modelling natural hazards in gvSIG with the HortonMachine pluginsModelling natural hazards in gvSIG with the HortonMachine plugins
Modelling natural hazards in gvSIG with the HortonMachine pluginsAndrea Antonello
 
GEOPAPARAZZI: STATE OF THE ART
GEOPAPARAZZI: STATE OF THE ARTGEOPAPARAZZI: STATE OF THE ART
GEOPAPARAZZI: STATE OF THE ARTAndrea Antonello
 
Geopaparazzi - NEVER OUT OF DATA IN THE FIELD
Geopaparazzi - NEVER OUT OF DATA IN THE FIELDGeopaparazzi - NEVER OUT OF DATA IN THE FIELD
Geopaparazzi - NEVER OUT OF DATA IN THE FIELDAndrea Antonello
 
The HortonMachine, for data analysis to help scientists... and not only
The HortonMachine, for data analysis to help scientists... and not onlyThe HortonMachine, for data analysis to help scientists... and not only
The HortonMachine, for data analysis to help scientists... and not onlyAndrea Antonello
 
Geopaparazzi & gvSIG Mobile - state of the art
Geopaparazzi & gvSIG Mobile - state of the artGeopaparazzi & gvSIG Mobile - state of the art
Geopaparazzi & gvSIG Mobile - state of the artAndrea Antonello
 
PART 6: FROM GEO INTO YOUR REPORT
PART 6: FROM GEO INTO YOUR REPORTPART 6: FROM GEO INTO YOUR REPORT
PART 6: FROM GEO INTO YOUR REPORTAndrea Antonello
 
PART 4: GEOGRAPHIC SCRIPTING
PART 4: GEOGRAPHIC SCRIPTINGPART 4: GEOGRAPHIC SCRIPTING
PART 4: GEOGRAPHIC SCRIPTINGAndrea Antonello
 
PART 3: THE SCRIPTING COMPOSER AND PYTHON
PART 3: THE SCRIPTING COMPOSER AND PYTHONPART 3: THE SCRIPTING COMPOSER AND PYTHON
PART 3: THE SCRIPTING COMPOSER AND PYTHONAndrea Antonello
 
Foss4g2016 Geopaparazzi Workshop
Foss4g2016 Geopaparazzi WorkshopFoss4g2016 Geopaparazzi Workshop
Foss4g2016 Geopaparazzi WorkshopAndrea Antonello
 
New tools for LiDAR, forestry, river management and hydro-geomorphology in gvSIG
New tools for LiDAR, forestry, river management and hydro-geomorphology in gvSIGNew tools for LiDAR, forestry, river management and hydro-geomorphology in gvSIG
New tools for LiDAR, forestry, river management and hydro-geomorphology in gvSIGAndrea Antonello
 
Digital field mapping with Geopaparazzi and gvSIG
Digital field mapping with Geopaparazzi and gvSIGDigital field mapping with Geopaparazzi and gvSIG
Digital field mapping with Geopaparazzi and gvSIGAndrea Antonello
 
Geopaparazzi, history of a digital mapping kid
Geopaparazzi, history of a digital mapping kidGeopaparazzi, history of a digital mapping kid
Geopaparazzi, history of a digital mapping kidAndrea Antonello
 
Geopaparazzi, state of the art
Geopaparazzi, state of the artGeopaparazzi, state of the art
Geopaparazzi, state of the artAndrea Antonello
 
Geographic scripting in uDig
Geographic scripting in uDigGeographic scripting in uDig
Geographic scripting in uDigAndrea Antonello
 
LESTO - a GIS toolbox for LiDAR empowered sciences
LESTO - a GIS toolbox for LiDAR empowered sciencesLESTO - a GIS toolbox for LiDAR empowered sciences
LESTO - a GIS toolbox for LiDAR empowered sciencesAndrea Antonello
 

Mehr von Andrea Antonello (20)

GEOPAPARAZZI: STATE OF THE ART OF THE DIGITAL FIELD MAPPING APPLICATION
GEOPAPARAZZI: STATE OF THE ART OF THE DIGITAL FIELD MAPPING APPLICATIONGEOPAPARAZZI: STATE OF THE ART OF THE DIGITAL FIELD MAPPING APPLICATION
GEOPAPARAZZI: STATE OF THE ART OF THE DIGITAL FIELD MAPPING APPLICATION
 
GEOPAPARAZZI STATE OF THE ART OF THE DIGITAL FIELD MAPPING APPLICATION
GEOPAPARAZZI STATE OF THE ART OF THE DIGITAL FIELD MAPPING APPLICATIONGEOPAPARAZZI STATE OF THE ART OF THE DIGITAL FIELD MAPPING APPLICATION
GEOPAPARAZZI STATE OF THE ART OF THE DIGITAL FIELD MAPPING APPLICATION
 
Geopaparazzi Survey Server workshop
Geopaparazzi Survey Server workshopGeopaparazzi Survey Server workshop
Geopaparazzi Survey Server workshop
 
Geopaparazzi Survey Server Installation
Geopaparazzi Survey Server InstallationGeopaparazzi Survey Server Installation
Geopaparazzi Survey Server Installation
 
Modelling natural hazards in gvSIG with the HortonMachine plugins
Modelling natural hazards in gvSIG with the HortonMachine pluginsModelling natural hazards in gvSIG with the HortonMachine plugins
Modelling natural hazards in gvSIG with the HortonMachine plugins
 
GEOPAPARAZZI: STATE OF THE ART
GEOPAPARAZZI: STATE OF THE ARTGEOPAPARAZZI: STATE OF THE ART
GEOPAPARAZZI: STATE OF THE ART
 
Geopaparazzi - NEVER OUT OF DATA IN THE FIELD
Geopaparazzi - NEVER OUT OF DATA IN THE FIELDGeopaparazzi - NEVER OUT OF DATA IN THE FIELD
Geopaparazzi - NEVER OUT OF DATA IN THE FIELD
 
The HortonMachine, for data analysis to help scientists... and not only
The HortonMachine, for data analysis to help scientists... and not onlyThe HortonMachine, for data analysis to help scientists... and not only
The HortonMachine, for data analysis to help scientists... and not only
 
Geopaparazzi & gvSIG Mobile - state of the art
Geopaparazzi & gvSIG Mobile - state of the artGeopaparazzi & gvSIG Mobile - state of the art
Geopaparazzi & gvSIG Mobile - state of the art
 
PART 6: FROM GEO INTO YOUR REPORT
PART 6: FROM GEO INTO YOUR REPORTPART 6: FROM GEO INTO YOUR REPORT
PART 6: FROM GEO INTO YOUR REPORT
 
PART 5: RASTER DATA
PART 5: RASTER DATAPART 5: RASTER DATA
PART 5: RASTER DATA
 
PART 4: GEOGRAPHIC SCRIPTING
PART 4: GEOGRAPHIC SCRIPTINGPART 4: GEOGRAPHIC SCRIPTING
PART 4: GEOGRAPHIC SCRIPTING
 
PART 3: THE SCRIPTING COMPOSER AND PYTHON
PART 3: THE SCRIPTING COMPOSER AND PYTHONPART 3: THE SCRIPTING COMPOSER AND PYTHON
PART 3: THE SCRIPTING COMPOSER AND PYTHON
 
Foss4g2016 Geopaparazzi Workshop
Foss4g2016 Geopaparazzi WorkshopFoss4g2016 Geopaparazzi Workshop
Foss4g2016 Geopaparazzi Workshop
 
New tools for LiDAR, forestry, river management and hydro-geomorphology in gvSIG
New tools for LiDAR, forestry, river management and hydro-geomorphology in gvSIGNew tools for LiDAR, forestry, river management and hydro-geomorphology in gvSIG
New tools for LiDAR, forestry, river management and hydro-geomorphology in gvSIG
 
Digital field mapping with Geopaparazzi and gvSIG
Digital field mapping with Geopaparazzi and gvSIGDigital field mapping with Geopaparazzi and gvSIG
Digital field mapping with Geopaparazzi and gvSIG
 
Geopaparazzi, history of a digital mapping kid
Geopaparazzi, history of a digital mapping kidGeopaparazzi, history of a digital mapping kid
Geopaparazzi, history of a digital mapping kid
 
Geopaparazzi, state of the art
Geopaparazzi, state of the artGeopaparazzi, state of the art
Geopaparazzi, state of the art
 
Geographic scripting in uDig
Geographic scripting in uDigGeographic scripting in uDig
Geographic scripting in uDig
 
LESTO - a GIS toolbox for LiDAR empowered sciences
LESTO - a GIS toolbox for LiDAR empowered sciencesLESTO - a GIS toolbox for LiDAR empowered sciences
LESTO - a GIS toolbox for LiDAR empowered sciences
 

Opensource gis development - part 1

  • 1. Java Open Source GIS Development From 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 ngineering HydroloGIS S.r.l. - Via Siemens, 19 - 39100 Bolzano www.hydrologis.com
  • 2. Who am I? Andrea Antonello Environmental Engineer, graduated with GRASS development thesis PhD in Environmental Sciences, working on development of digital field mapping tools GIS development Involved for years in open source GIS development, mainly GRASS, JGrass, uDig, BeeGIS, Geopaparazzi HydroloGIS Work for HydroloGIS, a company that writes and uses GFOSS products for environmental analyses, mostly hydrology and geomorphology.
  • 3. Buzzwords: Java, Maven and Eclipse Java 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. Buzzwords: GeoTools, JTS and OGC GeoTools 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. Buzzwords: uDig, OMS and JGrasstools User-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 uDig's Spatial Toolbox.
  • 6. Useful spatial links Spatial: • GeoTools Homepage • uDig Homepage • OMS3 Homepage • JGrasstools Homepage • Imageio-ext Homepage • JTS Homepage
  • 7. Useful development links Java 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. 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. Part 2: Introduction of the main Geo-Objects • geometry objects • projections • vector objects • raster objects • filters • style
  • 10. Part 3: Vector data • vector basics, handling shapefiles • geometry basics • predicates • functions • tips and tricks
  • 11. Part 4: Raster data • reading/writing raster data • processing rasters • image vs. world space
  • 12. Part 5: Integrating with uDig • introduction to OMS • introduction to uDig • introduction to uDig's Spatial Toolbox • introduction to jgrasstools • create example OMS GeoTools based modules
  • 13. Preparing the development environment Java Installation Perform the following installations, based on the download and instructions links 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. Eclipse Installation 1. 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. 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/workspace 8. On the Welcome view press Workbench along the right hand side and we can get started
  • 16. Maven Installation The maven build tool can work on the command line and includes a plugin for 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. 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/bin 4. Open up a terminal 5. Type the following command to confirm you are set up correctly: mvn -version
  • 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. Setting up the example project in Eclipse To get started quickly we will use a template project that already contains the dependencies we will need. The example project can be downloaded from: http://jgrasstools.googlecode.com/files/jgt-dev-example.tar.gz Create the folder /home/moovida/giscourse/code/ that will hold all the code we will write during the course. Extract the downloaded package into the code folder (tar zcvf jgt-dev-example.tar.gz). You now have the folder: /home/moovida/giscourse/code/jgt-dev-example.
  • 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=tutorial and after that we would have added the dependencies to the project's configuration file. Starting with an existing project helps to how the dependencies rules work, without the need to understand all of maven.
  • 21. Dependencies The downloaded project is a maven project that already contains all the needed dependencies (the references). Everything needed is defined inside the pom.xml file in the root of the project. 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. Repositories Most of the packages are kept in a central maven repository. GeoTools' packages are hosted by the Open Source Geospatial Foundation (Osgeo Homepage). Any repository can be added to the pom.xml project file. In our example we find: <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. Create the Eclipse project To actually get the dependencies downloaded, we can proceed like the following: 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 Eclipse 3. 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. Load the Eclipse project 4. 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 -> Import 6. Choose Existing Projects into Workspace from the list, and press Next 7. Select the project you created in: /home/moovida/giscourse/code/jgt-dev-example. 8. Press Finish to import your project
  • 25. Testing the development environment Download a test dataset The 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 Earth data project is a place we can get some freely available datasets. It is supported by the North American Cartographic Information Society. Let's download 110m-cultural.zip, which contains various vector layers of countries, boundaries and cities of the whole world. create a datafolder: /home/moovida/giscourse/data and unzip them into it in order to have: /home/moovida/giscourse/data/110m_cultural
  • 26. Write and run your first GIS application • copy the following code snippet import 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. • 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.shp You should see the following map:
  • 28. The first (and most boring) step is left behind. Take a deep breath. QUESTIONS?
  • 29. This work is released under Creative Commons Attribution Share Alike (CC-BY-SA) Much of the knowledge needed to create this training material has been produced by the sparkling knights of the GeoTools, JTS and uDig community. Another essential source has been the Wikipedia community effort. Particular thanks go to those friends that directly or indirectly helped out in the creation and review of this developer's handbook: Jody Garnett from the uDig/GeoTools community and the TANTO team. This tutorial was written with the support of the Geoinformation Research Group of the University of Potsdam and HydroloGIS.