Introduction to GIS

Download Report

Transcript Introduction to GIS

Serving Geographic Data
A Paul R Cooper
MAGIC
Introduction
Paul Cooper
House-Keeping
One day course
4 sessions
1000 – 1100
• Coffee
1115 – 1230
• Lunch
1330 – 1500
• Tea/Coffee
1530 – 1700
Course Outline
Introduction
Overview of System
Standards
Data Stores
Introduction to Tomcat
Geoserver
Client side software
Exercise
Close
What’s in it for You!
Allows you to put data on the web.
Standards compliant techniques.
Makes your data accessible to a large
audience.
Handouts, notes and questions
Handouts:
Copies of PowerPoint slides
Space for notes
Exercise plans
Please ask questions at the end of
sections
Text-books and manuals available
System Overview
Overview of Web services
User interfaces with
Client Software.
Client Software talks to
Server software.
Server software
contained by Web
server.
Server Software gets
data from Data Store.
Client
Web Server
Geoserver
Datastore
Standards
Why should we be bothered?
Everyone in my field uses <insert data
format>
International standards allow crossdiscipline data sharing.
NERC is an interdisciplinary organization.
Environmental scientists need to share
data across disciplinary boundaries
Discipline specific formats do not promote
data sharing across disciplines
Standards
All web services depend on standards
Geographic data use OGC standards
(Open Geospatial Consortium)
ISO TC211 standards also important
OGC and ISO are convergent
Both depend on W3C standards
XML, CSS, HTML, XHTML, DOM
OGC standards:
Web Feature Service
http://www.opengeospatial.org/standards/wfs
Web Map Service
http://www.opengeospatial.org/standards/wms
Styled Layer Descriptor
http://www.opengeospatial.org/standards/sld
GML (also ISO 19136)
http://www.opengeospatial.org/standards/gml
Filter Encoding
http://www.opengeospatial.org/standards/filter
ISO Standards
Plenty to choose from!
Full list at http://www.isotc211.org/
Ones that are of interest to us are:
ISO 19110 (Feature Cataloguing).
ISO 19111 (Spatial Referencing by Coordinates)
ISO 19112 (Spatial Referencing by Geographic
identifier)
ISO 19115 and ISO 19139 (Metadata)
Plus lots more.
ISO standards not free, unfortunately.
Web standards
XML
http://www.w3.org/XML/
HTML and XHTML
http://www.w3.org/MarkUp/
CSS
http://www.w3.org/Style/CSS/
Document Object Model (DOM)
http://www.w3.org/DOM/
Other standards
ECMAScript
Javascript implements ECMAScript.
Depends on DOM.
Unfortunately widely extended.
http://www.ecmainternational.org/publications/standards/Ecma262.htm
Java, JavaServer Pages, etc.
SQL (ISO 9075 with OGC extensions)
KML (Google proprietary standard)
Demystifying XML
A brief guide to XML
XML is a mark up language
Always starts:
<?xml version="1.0" encoding="UTF-8"?>
<myTag>this is
some
data</myTag>
<myTag
myAttribute=
“Paul” />
Uses tags to define elements.
Tags may have attributes.
Must have opening and closing tags
or have “/” before closing “>”.
<myTag>
Attribute values must be in quotes.
<myName>
Tags must be nested correctly.
Paul
Must have single “Root” tag.
</myName>
More!
</myTag>
Datastores
Datastores
Any means of storing geographic information
Spatially enabled RDBMS
•
•
•
•
PostGIS/PostgreSQL
MySQL
Oracle (Oracle Spatial not required)
ArcSDE (We do have this, but proprietary)
File based
• Shapefiles
• Images
• GML
Service based – other WFS servers
PostGreSQL
This course will use PostgreSQl/PostGIS
Respected OpenSource database
Stable and reliable fully featured SQL
RDBMS
http://www.postgresql.org/
http://postgis.refractions.net/
PostgreSQL utilities
psql – SQL command line
pgAdmin III
GUI interface for managing database.
Shp2pgsql
Utility to import shapefiles into PostGIS
Gshp2pgsql
GUI interface for shp2pgsql
psqlODBC
ODBC driver – used for connecting to Access etc.
Creating PostGIS Data Source
Standard SQL database
Need one or more columns of “geometry”
type
Geometry columns must be registered in
“geometry_columns” table.
Simplest way is to create the table then
use the “addgeometrycolumn” function.
May be necessary to insert entry manually
into “geometry_columns” table.
Example
CREATE TABLE penguins (
penguin_id INTEGER,
penguin_name VARCHAR,
penguin_type VARCHAR,
latitude DOUBLE, longitude DOUBLE);
SELECT AddGeometryColumn('penguins',
'penguin_point', 3031, 'POINT', 2 );
Geometry Types
POINT
LINESTRING
POLYGON
MULTIPOINT
MULTILINESTRING
MULTIPOLYGON
GEOMETRYCOLLECTION
Spatial reference ID (SRID)
This is a reference to a “Well Known”
set of identifiers for projections and
other spatial reference systems.
The only one in widespread use is the
EPSG database (http://www/epsg.org)
An SRID should be prefaced with a
namespace identifier (e.g. EPSG::3031),
but often isn’t!
Useful SRIDs
4326: Geographic coordinates on
WGS84 datum
7405: British National Grid
3031: Standard Antarctic Polar
Stereographic projection
3204-3293: “North Up” projections for
each IMW map tile in Antarctica
Geometry Constructors
Geometry columns are binary
You can’t insert data directly into them
Use geometry constructor functions
E.G. INSERT INTO myTable (my_geom)
values (GeomFromText(‘POINT(-50 60)',4326));
Exercises 1 & 2
Import spatial data into PostGreSQL
Psql –h localhost WebCoursen ogcn
Maintaining Geometry
Maintaining a Geometry column
Geometry columns are binary and not
editable.
You need to input and edit latitude and
longitude
Geometry is updated with UPDATE and
INSERT trigger functions.
Trigger functions can make use of the
geometry functions of PostGIS
PGPLSQL to convert lat/long to
point
NEW.the_geom :=
ST_GeomFromText('POINT('||NEW.lond
ec||' '||NEW.latdec||')',4326);
OR, if you want to use a different SRID:
NEW.the_geom := ST_Transform(
ST_GeomFromText('POINT('||NEW.lond
ec||' '||NEW.latdec||')',4326),3031);
SQL to build lines and polygons
Select ST_MakeLine(the_geom) as
the_line from (select the_geom from
MyPoints where lineid=1234 order by
timestamp) pnt;
Several polygon creation functions:
ST_MakePolygon(linestring, [linestring[]])
ST_BuildArea(geometry)
ST_Polygonize(geometry set)
More on geometry_columns table
Created by the system to store
metadata about geometry fields.
Used by other software to determine
the properties of geometry fields.
Geoserver won’t detect geometry fields
unless this is correctly maintained.
Using Views with PostGIS
Create View using usual SQL commands
Can include geometry manipulation
functions
MANUALLY add entry to
“geometry_columns” table
Example
CREATE VIEW penguin_tracks as Select
pnt.penguin_name,
ST_MakeLine(penguin_point) as penguin_line
from (select penguin_name, penguin_point
from penguins order by penguin_id) pnt
group by pnt.penguin_name;
INSERT into geometry_columns values
(‘’,’public’,’penguin_tracks’,’penguin_line’,2,30
31,’LINESTRING’);
Exercise 3 & 4
Maintaining Geometry Columns
Creating lines from points
Introduction to TOMCAT
Introduction to TOMCAT
Tomcat is a web server
Provided by Apache Foundation
Free/Open-Source software
Can work alongside Apache web server
Provides additional technologies
Java Servlet container
Java Server Pages
TOMCAT file structure
Root
CATALINA_HOME
Lots of others!
webapps
conf
Contains server.xml
geoserver
Your Application
Contains HTML, JSP etc, files
Other applications
WEB-INF
Contains web.xml
classes
The root for any Java
classes you create
lib
Any Java libraries
Tomcat Management
Application
Management
Start, Stop
Reload
• Restarts an application
• Reloads Java classes
Undeploy
Expire session
• Timeout for inactive
session
Load new
applications
Geoserver
Geoserver
Geoserver is a Java application that runs in a
Java servlet container.
We run it in Tomcat; it can run on other servers
that provide support for Java servlets.
Provides OGC compliant
Web Map Service (WMS 1.1.1)
Web Feature Service (WFS 1.0)
Web Coverage Service (WCS 1.0)
The reference implementation for WFS 1.0
More information at www.geoserver.org
Geoserver File Structure
geoserver
images
Type title here
logs
data
featureTypeName
A directory for every
Feature type that
is defined
info.xml
XML file defining the
Feature type
data
shapefiles
Contains shapefiles
supplied with
Geoserver
schemas
styles
Contains SLD
descriptions for every
style used
management
several others!
WEB-INF
Geoserver Management
Status!
Done through Web
pages
Important bits!
Configuration
(Password
protected)
Demonstration
Steps to create a feature source
1.
2.
3.
4.
Namespace
Data Source
Style
Feature Types
Namespace
A namespace makes your feature
names unique
“Coast” is unlikely to be unique
“MyNameSpace::Coast” will be unique
Namespace definitions have two parts
• A name (e.g. add)
• A URL, which need not exist but should be in a
domain you control (e.g. www.add.scar.org)
A standard XML technique.
Namespace creation tool
First
Second
Data Source
Basic capability:
PostGIS
Shapefiles
Web Feature
Server
Optional download
Indexed Shapefile
DB2
Oracle
ArcSDE
MySQL (β)
VPF (β)
MapInfo (β)
Setting up PostGIS DataSource
You need to supply:
A name for this data source
A namespace to use with this data source
The PostGreSQL host machine address
• Use Localhost on the teaching PCs
• postgres.nerc-bas.ac.uk is the BAS server
The name of the database
A userid and password for the database
Set up screen for PostGres
Database
Styled Layer Descriptors (SLD)
Unfortunately, no simple tools!
Utility to create them from ArcGIS.
Generally, use a programmer’s editor
File is XML
Many editors can apply XML schema’s.
jEdit, Notepad++ and NetBeans work well.
Geoserver has editing tool.
Easiest to create SLD by adapting existing
ones!
General principles of SLD
An SLD contains a number or “Rules”
Each “Rule” consists of:
A filter to select features to be processed
by the rule
Symbolizers for the selected features
Simple Example: Structure
<?xml version="1.0" encoding="UTF-8"?>
<StyledLayerDescriptor version="1.0.0"
xsi:schemaLocation="http://www.opengis.net/sld StyledLayerDescriptor.xsd"
xmlns="http://www.opengis.net/sld"
xmlns:ogc="http://www.opengis.net/ogc"
xmlns:xlink="http://www.w3.org/1999/xlink"
xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance">
<NamedLayer>
<Name>Surface</Name>
<UserStyle>
<Title>Rock, ice, lake and moraine styling</Title>
<Abstract>Surface types boundary style and fill</Abstract>
<FeatureTypeStyle>
<FeatureTypeName>Feature</FeatureTypeName>
RULES
</FeatureTypeStyle>
</UserStyle>
</NamedLayer>
</StyledLayerDescriptor>
Simple example: Rules
<Rule>
<Name>Rock outcrop</Name>
<Title>Rock outcrop</Title>
<ogc:Filter>
<ogc:PropertyIsEqualTo>
<ogc:PropertyName>rck00srf</ogc:PropertyName>
<ogc:Literal>rock</ogc:Literal>
</ogc:PropertyIsEqualTo>
</ogc:Filter>
<PolygonSymbolizer>
<Fill>
<CssParameter name="fill">#aa5500</CssParameter>
</Fill>
</PolygonSymbolizer>
</Rule>
<Rule>
<Name>Everything else</Name>
<ElseFilter/>
<PolygonSymbolizer>
<Fill>
<CssParameter name="fill">#ff0000</CssParameter>
</Fill>
</PolygonSymbolizer>
</Rule>
SLD Filter Syntax
<ogc:Operator>
<ogc:operand />
<ogc:operand />
...
</ogc:Operator>
Complete specification in WFS
documentation
Adding Style to Geoserver
Creating a new FeatureType
Select source from drop down list
Enter FeatureType editor
Select Style from drop down list
Ensure SRS is correct
Some datastores need this to be entered
Generate Bounding Box
Must be edited if the Pole is within the area
Additional FeatureType options
You can add the path to a metadata file
FGDC or ISO 19115 format
You can change visibility of fields
Facility in development to allow external
schemas
You can enable caching
Only useful for fairly static data.
Other methods available
Seeing if it all worked!
Geoserver provides preview facility
Exercise 5 & 6
Creating SLDs
Making FeatureTypes
Client Software
Client Software
Many options of varying complexity
Simple image, using a suitable URL
Custom JavaScript
OpenLayers
Google Earth
GIS Software
Using an IMG tag
Provides a static view
No interactive facilities
E.G Ship track in static context
Uses a URL specifying:
The
The
The
The
features to be displayed
area to be displayed
bounding box
SRID
Example
http://www.add.scar.org:8080/geoserver/wms?
bbox= -82876.5,4533.29,82813.5,119388.293
&styles=
&Format=image/png
&request=GetMap
&layers=sggis:bathy_poly,sggis:coastline2007_
extended
&width=800&height=520
&srs=EPSG:2007056
Example explained!
URL of server
Bbox: Bounding Box in SRID specified
Styles: Specify non-default styles here
Format: Format of the data
Request: Command to WMS
Layers: Features to be displayed
Width & height: Size of returned image
Srs: SRID
How can I find out valid values?
Use GetCapabilities call.
E.g.
http://www.add.scar.org:8080/geoserver/
wms?service=WMS&request=GetCapabiliti
es
Returns XML document that tells all!
Same syntax works for WFS and WCS.
Javascript based clients
WMS Calls can be scripted in JavaScript
The ADD uses this approach
Advantages
Very customizable
Can be adapted to suit your environment
Disadvantages
No support
Gets complicated quite quickly!
Only supports WMS
OpenLayers
An AJAX system
Can use wide variety of data sources
WMS
WFS
Images
Actively being developed
Stable and widely used.
Documentation not wonderful!
Basic Structure
An OpenLayers.Map object contains
OpenLayers.Layer
Many possible types of layer
WMS is the one we’ll use
WFS is useful
Image connects to web-accessible image
Each object has MANY attributes!
HTML structure for OpenLayers
<html xmlns="http://www.w3.org/1999/xhtml">
<head>
<title>OpenLayers Example</title>
<script src="http://openlayers.org/api/OpenLayers.js"></script>
<script type="text/javascript">
var map=null;
function init(){
FUNCTION to CREATE MAP HERE
};
</script>
</head>
<body onload="init()">
<h1 id="title">OpenLayers Example</h1>
<div id="tags"></div>
<p id="shortdesc">
Demonstrate a simple map with an overlay that includes layer switching controls.
</p>
<div id="map" class="smallmap" style="width:550; height:550"></div>
<div id="docs"></div>
</body>
</html>
Javascript Function
<script type="text/javascript">
var map=null;
function init(){
map = new OpenLayers.Map('map', {projection: "EPSG:3031", units: 'm',maxResolution: 28331.333586554192,
maxExtent: new OpenLayers.Bounds(-3000000, -3000000, 3000000, 3000000)});
var addcst = new OpenLayers.Layer.WMS("Antarctic Coastline“, "http://www.add.scar.org:8080/geoserver/wms",
{layers: 'add:cst10_polygon,add:cst10_linestring',width:550,height:550 } );
var addcnt = new OpenLayers.Layer.WMS("Antarctic Contours“,"http://www.add.scar.org:8080/geoserver/wms",
{layers: 'add:cnt10_linestring',transparent: true,width:550,height:550 } );
addcnt.isBaseLayer=false;
var addgrat = new OpenLayers.Layer.WMS("Antarctic Rock“, "http://www.add.scar.org:8080/geoserver/wms",
{layers: 'add:graticule',transparent: true,width:550,height:550 } );
addgrat.isBaseLayer=false;
map.addLayers([addcst,addcnt,addgrat]);
map.addControl(new OpenLayers.Control.LayerSwitcher());
map.addControl(new OpenLayers.Control.NavToolbar());
map.zoomToMaxExtent();
};
</script
Demo of example code
http://www.add.scar.org/test.html
OpenLayers
Much more than I can show
See http://www.openlayers.org
Documentation is NOT good
Getting good results may mean
experimenting
Rapidly evolving software
New capabilities coming all the time
Google Earth
Google Earth is widely available.
Very popular.
Can access data from a WMS.
Some WMS have KML as output format.
KML is a visualization format.
NOT Data transfer format.
GIS Packages
Most mainstream GIS has at least
limited capability to use WMS/WFS.
ArcGIS can get data from WFS
Interoperabilty extension gives wider
capabilities
Exercise 7
Creating a client to view your data
Summary and close
What have you learnt
Principles of creating GI web services
Data management techniques
How to style a map
How to create simple web clients
Put it all into practise
That’s All Folks!