790 likes | 936 Views
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. Introduction Overview of System Standards Data Stores Introduction to Tomcat Geoserver
E N D
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
Introduction Overview of System Standards Data Stores Introduction to Tomcat Geoserver Client side software Exercise Close Course Outline
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
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
Why should we be bothered? • Everyone in my field uses <insert data format> • International standards allow cross-discipline 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.ecma-international.org/publications/standards/Ecma-262.htm • Java, JavaServer Pages, etc. • SQL (ISO 9075 with OGC extensions) • KML (Google proprietary standard)
A brief guide to XML <myTag>this is some data</myTag> • XML is a mark up language • Always starts: • <?xml version="1.0" encoding="UTF-8"?> • Uses tags to define elements. • Tags may have attributes. • Must have opening and closing tags or have “/” before closing “>”. • Attribute values must be in quotes. • Tags must be nested correctly. • Must have single “Root” tag. • More! <myTagmyAttribute= “Paul” /> <myTag> <myName> Paul </myName> </myTag>
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 mustbe 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 localhostWebCoursenogcn
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.londec||' '||NEW.latdec||')',4326); • OR, if you want to use a different SRID: • NEW.the_geom := ST_Transform( ST_GeomFromText('POINT('||NEW.londec||' '||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,3031,’LINESTRING’);
Exercise 3 & 4 Maintaining Geometry Columns Creating lines from points
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 Management • Application Management • Start, Stop • Reload • Restarts an application • Reloads Java classes • Undeploy • Expire session • Timeout for inactive session • Load new applications
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
Status! Geoserver Management • Done through Web pages • Important bits! Configuration (Password protected) Demonstration
Steps to create a feature source • 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 PostGISDataSource • 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