You are on page 1of 54

GeoSpatial

GeoSpatialfor
forJava
Java
Introduction
IntroductiontotoGIS
GISfor
forthe
theJava
JavaDeveloper
Developer

How
How to
to cope
cope with
with Geospatial
Geospatial 11
GeoSpatial for Java
This is a quick introduction to Geospatial concepts and ideas
for the Java developer
We will make use of number of Java projects
However the focus is on the ideas
(we just happen to be using running code)

How
How to
to cope
cope with
with Geospatial
Geospatial 22
Schedule
We have three hours; and a break for caffeine

Introduction
Quickstart 30 min
Feature 25 min
Geometry and CRS 25 min
Caffeine
Filter 25 min
Image 25 min
Style 25 min

How
How to
to cope
cope with
with Geospatial
Geospatial 33
Introduction Jody
Jody Garnett
Australia
GeoTools since 2003 Australia
Spent the first 2 months Founded 1994
being unable to compile Integration
Decided to contribute to End to end
documentation
Solutions
Not done yet
Services
Support

How
How to
to cope
cope with
with Geospatial
Geospatial 44
Introduction Justin
Justin DeOlivera
Canada
GeoTools since 2005 Commercial arm of the
Spends his time pruning Open Planning Project
complicated api OpenGeo Stack
Strangely enough Justin Responsible for the majority
is not done yet either of GeoTools development
at present

How
How to
to cope
cope with
with Geospatial
Geospatial 55
Geographic Information Systems
Humans have been doing this for a long time
Cave Art or map to the best hunting ground?
A common theme is representation of walking time rather
than distance. Allows map to be used as a planning tool.

How
How to
to cope
cope with
with Geospatial
Geospatial 66
Navigation and Problem Solving
Polynesian stick maps
Used for navigating in the pacific ocean.
Depicted islands, wave patterns and current direction.
1854 Broad Street cholera outbreak
John Snow discovered the source of the outbreak by
mapping cases of cholera.
Cholera victims all used the same water source

How
How to
to cope
cope with
with Geospatial
Geospatial 77
GeoTools Java GIS Toolkit
Open Source 1994 - Present
LGPL (Really old for Java)
Open Development Started in Leads University
Public Process OSGeo Project in 2006
Anyone can Play Active / Diverse committers

How
How to
to cope
cope with
with Geospatial
Geospatial 88
GeoTools and Standards
GeoTools 1 had more users then documentation
Solution was to fire the users
... and GeoTools 2 was formed

GeoTools 2 leans on the OGC standards


OGC provides public standards anyone can download
Easier to follow standards than having to invent names
So the best docs are often the standards

Standards are not intended to as a limitation


Only a common starting point
Get it Done

How
How to
to cope
cope with
with Geospatial
Geospatial 99
GeoTools and Collaboration
In the spirit of Get it Done
We make use of existing projects early and often
This is the Do not repeat yourself principle in action
The project practices open development
Easy to take part
However we are LGPL so we get lots of forks
(mostly buried in commercial apps)
We will introduce these other projects as we go
using code as often as possible
This does however mean that we will use a lot of jars
Maven is the tool we use to manage jars
Do you use maven for your project?

How
How to
to cope
cope with
with Geospatial
Geospatial 10
10
This is Hands On Programming
1) Recommend you pair up
with a friend
(or make a new friend)
2) The machines have the
software we are using +
today already downloaded
3) There is a DVD being
passed around; copy the
GeospatialForJava folder
4) If you succeed raise your +
hand and you will get a
Quickstart workbook!

How
How to
to cope
cope with
with Geospatial
Geospatial 11
11
Eclipse or Netbeans Quickstart
Start when ready
You have about 30 mins Maven

NetBeans
Quickstart Jars

Eclipse M2Eclipse
Quickstart
Maven
Jars

How
How to
to cope
cope with
with Geospatial
Geospatial 12
12
Feature
Feature

How
How to
to cope
cope with
with Geospatial
Geospatial 13
13
Feature Definition
Definition
a prominent or conspicuous part or characteristic
When drawing a person you will often draw the features of
a persons face (nose, ears, eyes, mouth)
When drawing a map we draw the features that make up
the landscape
When mapping a real world object
We draw the shape (the Geometry)
We also record where the object is

How
How to
to cope
cope with
with Geospatial
Geospatial 14
14
Feature for Java Developers
Explaining the concept of a Feature to Java Developers is
easy
A Feature is an Object
Just like an Object (ie an instance) that represents an entity
in the real world
Feature is an instance
You can record information about the real world entity
Feature attributes record information
You can group several features that are similar into classes
and form these classes into a hierarchy
Feature Type is a class
Like Java Objects, features can be ideas or concepts
(like a urban growth or rainfall)

How
How to
to cope
cope with
with Geospatial
Geospatial 15
15
Feature for Java cheatsheet
Here is a handy table showing the similarities
This is a dynamic type system

GeoSpatial Java

Feature Object
Attribute Field
properties{
Operation method
FeatureType Class

How
How to
to cope
cope with
with Geospatial
Geospatial 16
16
Feature Model
Here is what that looks like in Java
Lots of ways to access attributes
SimpleFeature for a flat record / tuple data structure

How
How to
to cope
cope with
with Geospatial
Geospatial 17
17
GeoAPI
Originally started to promote collaboration between GeoTools
and the deegree project
Mostly failed at this objective
Collaboration requires both parties to have funding at the
same time
Adopted as an OGC working group to promote the
development of common Java API
GeoAPI javadocs are an alternative to reading standards
Summary
GeoAPI defines the Interfaces
GeoTools implements the Objects

How
How to
to cope
cope with
with Geospatial
Geospatial 18
18
Feature Workbook
CSV2SHP
Great example of building features by hand
Data Model
Feature, FeatureType
Data Acess
DataStore / FeatureSource / FeatureStore

How
How to
to cope
cope with
with Geospatial
Geospatial 19
19
Geometry
Geometryand
andCRS
CRS

How
How to
to cope
cope with
with Geospatial
Geospatial 20
20
JTS Topology Suite
Remember we need both:
The shape to draw (ie the Geometry)
The location to draw the shape in
Geometry is provided by the JTS project
Implementation of OGC Simple Features for SQL
Numerically stable
This is the rocket science of GIS
Literally the foundation of our open source spatial industry
Team made up of a single canadian developer
Martin Davis
http://tsusiatsoftware.net/jts/main.html

How
How to
to cope
cope with
with Geospatial
Geospatial 21
21
Geometry - Point
In the beginning
Point
A single coordinate of two to four dimensions

x=151.211111
y=-33.859972

How
How to
to cope
cope with
with Geospatial
Geospatial 22
22
GeometryFactory and WKT

GeometryFactorygeometryFactory=
JTSFactoryFinder.getGeometryFactory(null);

Coordinatecoord=newCoordinate(151.211111,33.859972);
Pointpoint=geometryFactory.createPoint(coord);

GeometryFactorygeometryFactory=
JTSFactoryFinder.getGeometryFactory(null);

WKTReaderreader=newWKTReader(geometryFactory);
Stringwkt="POINT(151.211111,33.859972)";

Pointpoint=(Point)reader.read(wkt);

How
How to
to cope
cope with
with Geospatial
Geospatial 23
23
Geometry - LineString
A set of two of more coordinates linear interpretation of a
path between coordinates
Translation:
Java String is a string of characters
LineString is a string of straight line segments

How
How to
to cope
cope with
with Geospatial
Geospatial 24
24
Geometry - Polygon
A set of one or more linestrings
One ring defines the exterior boundary
The remaining rings define the holes in the polygon
Represents an Area

How
How to
to cope
cope with
with Geospatial
Geospatial 25
25
Concept - Coverage
Polygons that share an edge, completely covering an area
Examples: Land use, Soil types, Zones
Often represented as a collection of features
Efficient wing edge data structures to represent a coverage
I don't know a good implementation in Java

How
How to
to cope
cope with
with Geospatial
Geospatial 26
26
What is the Point
With Geometry we can draw the shape of our feature
We are still missing an important bit of information
Where the feature is!
This is similar to the idea of distance
Q: how far?
A: 3
We really need to know 3 what

The units of distance are important


We really need the meaning of a shape

How
How to
to cope
cope with
with Geospatial
Geospatial 27
27
Coordinate
Coordinate ordered list of measurements
X/Y
Latitude / Longitude
Longitude / Latitude

An important part is defining what is being measured


Latitude and Longitude in degrees
Distances measured in meters

Coordinatecoord=newCoordinate(151.211111,33.859972);

How
How to
to cope
cope with
with Geospatial
Geospatial 28
28
Coordinate Reference System
CRS is the definition of what coordinates are measuring
Positions are always in 3D space
We often cheat and only write down two numbers
(the ordinates in co-ordinates)

How is this possible?


We treat the numbers as measurements against a model of
the earth

Earth model? (ie Geodetic Datum)


Ellipsoid shape kind of like a sphere
Geoid gravity field kind of like sea level

How
How to
to cope
cope with
with Geospatial
Geospatial 29
29
Where to measure from
Easy on a flat surface Not as straight forward Start with a point of origin
on a sphere

Latitude degrees north


or south of the Equator Longitude degrees east or
west of the Prime Meridian

How
How to
to cope
cope with
with Geospatial
Geospatial 30
30
Axis order Issue
Map makers have been recording information using
northing/easting order ... because of Sextant
However Computer GIS systems often expect x/y order
But the map makers never really agreed
So there is confusion
You need to check the data

How
How to
to cope
cope with
with Geospatial
Geospatial 31
31
Feature and Geometry Standards
Simple Complex
Point Point
Line Curve
Polygon Surface

Standards Standards
GML2 GML3
SFSQL ISO19107

Implementation Implementation
JTS data structure only

How
How to
to cope
cope with
with Geospatial
Geospatial 32
32
Geometry CRS Lab
The Shape of GIS
And what it means

How
How to
to cope
cope with
with Geospatial
Geospatial 33
33
Filter
Filter

How
How to
to cope
cope with
with Geospatial
Geospatial 34
34
Filter used to Select information
Filter is used as part of a Query to select information
Think of it as the WHERE clause in an SQL statement
Several formats
XML (used by WFS)
Common Query Langague (CQL)
You can run the resulting Filter object yourself
filter.evaulate( object )
Makes use of Filter Expressions used to access data
expression.evaualte( object, String.class )
Both filter and expression work on Feature and Java Beans

How
How to
to cope
cope with
with Geospatial
Geospatial 35
35
Filter Workbook
This is where it get's cool; add hock query against
Shapefile
PostGIS
WFS
Using the
same code!

How
How to
to cope
cope with
with Geospatial
Geospatial 36
36
Raster
RasterData
Data

How
How to
to cope
cope with
with Geospatial
Geospatial 37
37
Grid Coverage
Remember a Coverage is a collection of features that
complete cover an area
A grid coverage is a special case the coverage forms a
regular grid of features
This looks so much like pixels we end up using the same
file formats (jpeg, png, tiff, etc..) with a text file for location
Spatial formats record location in file metadata (ecw, geotiff)

How
How to
to cope
cope with
with Geospatial
Geospatial 38
38
Not Pixels but Measurements
Grid Coverages are used to record measurements
Height (called a Digital Elevation Model or DEM)
Height and Depth Bathymetry
Vegetation Index
Some have Red, Green, Blue measurements
The file metadata can tell you what the values are for

How
How to
to cope
cope with
with Geospatial
Geospatial 39
39
Image Lab
Working with raster files
Grayscale
Color
Multi-band

How
How to
to cope
cope with
with Geospatial
Geospatial 40
40
Style
Style

How
How to
to cope
cope with
with Geospatial
Geospatial 41
41
Cartography - Scale
Cartography is the practice of map making
Focus on purpose
What is the map trying to communicate?
Who will be using it?
What projection, scale and symbology are best?
Scale
Appropriate for task at hand
(floor plan vs interstate)
Graphical Representation of Scale
works even when altered/printed

How
How to
to cope
cope with
with Geospatial
Geospatial 42
42
Cartography Projection and Symbols
Choosing projection is hard
(equal area to measure distance or WGS84 to show world)
Choose symbols appropriate to audience (and their training)
MIL2525B symbols for tactical response
Happy Face for planning lunch

T_10_2
Happy
Surface and Hostile
Planned
-=Reduced
North Direction
East Direction
Velocity = Red
9 _ Task Force No
Quantity 9
Nuclear - Yes

How
How to
to cope
cope with
with Geospatial
Geospatial 43
43
Cartography - Color
http://colorbrewer2.org/
Qualitative
Sequential
Diverging
Color brewer palettes built-in to
GeoTools

How
How to
to cope
cope with
with Geospatial
Geospatial 44
44
Map Definition and Style
MapContext
Layer data and style used to draw
StyleLayerDescriptor
FeatureTypeStyle instructions for how to draw features
Rule choose which features
PolygonSymbolizer
PointSymbolizer
LineSymbolizer
TextSymbolizer
RasterSymbolizer

How
How to
to cope
cope with
with Geospatial
Geospatial 45
45
Style Layer Descriptor Mostly Ignore

How
How to
to cope
cope with
with Geospatial
Geospatial 46
46
FeatureTypeStyle the Good Stuff

How
How to
to cope
cope with
with Geospatial
Geospatial 47
47
FeatureTypeStyle line symbolizer

surface=hiway
constraint Rule
type=Road

max scale: 50k line symbolizer

Features Rule

text symbolizer
capital=true
point
NAME
FeatureTypeStyle symbolizer
Rule

constraint text symbolizer


Pop > 500000
point
NAME
type=City max scale: 50k symbolizer
Raster Rule

Rule
point
Other
symbolizer
Queanbeyan

Content Style Portrayal (ie Drawing) Composition

How
How to
to cope
cope with
with Geospatial
Geospatial 48
48
Style Lab
Going to work on putting a Style together
Using a simple dialog
From an XML file
By hand
Advanced
Dynamically Generate a Style to Show Selection

How
How to
to cope
cope with
with Geospatial
Geospatial 49
49
Other
OtherJava
JavaProjects
Projects

Friendly
Friendly Survey
Survey -- Tour
Tour 50
50
Much More to Do
Graph module Processes
Shortest route RasterToVector
Web Formats
GML
GeoJson
SVG

Friendly
Friendly Survey
Survey -- Tour
Tour 51
51
There are Many More Java Projects
Projects using GeoTools Also at FOSS4G
52North deegree (LGPL)
Atlas Styler gvSig (GPL)
GeoPublisher Open Jump
Geomajas
GeoServer
OpenTripPlanner
uDig

Friendly
Friendly Survey
Survey -- Tour
Tour 52
52
Questions
Questions

Friendly
Friendly Survey
Survey -- Tour
Tour 53
53
Thanks!
Thanks!
Thanks
ThanksforforAttending
Attendingthis
thisWorkshop
Workshop
Shout
Shoutout
outtotoMicheal
MichealBedward
Bedwardwho whowrote
wrote
many
manyofofthe
thesource
sourcecode
codeexamples
examples
Thanks
Thankstotoco-workers
co-workerswhowhoreviewed
reviewed

Friendly
Friendly Survey
Survey -- Tour
Tour 54
54

You might also like