Introduction to The OpenGeo Suite

150
Introduction to The OpenGeo Suite Release March 18, 2012 OpenGeo March 18, 2012

Transcript of Introduction to The OpenGeo Suite

Page 1: Introduction to The OpenGeo Suite

Introduction to The OpenGeo SuiteRelease March 18, 2012

OpenGeo

March 18, 2012

Page 2: Introduction to The OpenGeo Suite
Page 3: Introduction to The OpenGeo Suite

Contents

I Workshop Outline 1

1 Welcome to the Workshop 3

2 Data, Software and Documentation Package 5

3 Chapter 1: The OpenGeo Suite 73.1 Introducing the OpenGeo Suite . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 73.2 Installing the OpenGeo Suite . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 83.3 The OpenGeo Suite Dashboard . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 15

4 Chapter 2: PostGIS 214.1 Introducing PostGIS . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 214.2 Spatial Databases . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 224.3 Spatial Data Types . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 234.4 Spatial Functions . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 234.5 Spatial Indexes . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 254.6 Creating a PostGIS Spatial Database . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 274.7 The PostGIS Table Schema . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 304.8 Loading Data into PostGIS . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 324.9 Viewing Spatial Data in PostGIS . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 344.10 Basic Spatial Queries and Functions . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 36

5 Chapter 3: GeoServer 395.1 Introducing GeoServer . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 395.2 Server Basics . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 405.3 Web Mapping Servers . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 415.4 GeoServer . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 425.5 Web Map Service (WMS) . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 425.6 Web Feature Service (WFS) . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 445.7 GeoServer’s Admin Interface . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 465.8 GeoServer Concepts . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 495.9 Creating a Workspace . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 525.10 Publishing Data from the File-System . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 535.11 Loading Many Shapefiles . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 585.12 Importing a Directory of Files . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 605.13 Importing Data from PostGIS . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 645.14 Other Supported Data Formats . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 695.15 Styling Layers in GeoServer . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 70

i

Page 4: Introduction to The OpenGeo Suite

5.16 Creating a Layer Group . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 745.17 Other protocols . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 76

6 Chapter 4: GeoExplorer 796.1 Introducing GeoExplorer . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 796.2 The GeoExplorer Interface . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 806.3 Navigation Tools . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 816.4 Layer Panel and Legend . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 836.5 Start Composing Your Map . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 846.6 Logging-In to GeoExplorer . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 866.7 Styling Layers in GeoExplorer . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 866.8 Editing Features in GeoExplorer . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 926.9 Saving Map Layouts . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 966.10 Publishing Map Widgets . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 986.11 Printing Static Maps . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 1056.12 Uploading Features through GeoExplorer . . . . . . . . . . . . . . . . . . . . . . . . . . . 107

7 Chapter 5: GeoWebCache 1117.1 Introducing GeoWebCache . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 1117.2 Caching Concepts . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 1127.3 Seeding A Tile-Cache . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 1167.4 Caching On-Demand . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 119

8 Chapter 6: Custom Web-Map Clients 1278.1 Introducing OpenLayers and GeoExt . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 1278.2 OpenLayers Tutorial . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 1298.3 GeoExt Tutorial . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 136

9 Getting Support for the OpenGeo Suite 1459.1 Two Types of Support . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 1459.2 Community Support . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 1459.3 Enterprise Support . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 146

ii

Page 5: Introduction to The OpenGeo Suite

Part I

Workshop Outline

1

Page 6: Introduction to The OpenGeo Suite
Page 7: Introduction to The OpenGeo Suite

CHAPTER 1

Welcome to the Workshop

Welcome! This workshop will introduce you to the tools and concepts needed to make and use acomplete geo-spatial software architecture.

This architecture will be built on your local machines, and include the following components:

1. A Spatial Database - PostGIS

• Short introduction

• Create a spatial database

• Load shapefiles into database tables,

• Introduce some basic functions and operations

2. A Spatial Data Server - GeoServer

• Review GeoServer concepts

• Learn and perform some core GeoServer administration tasks

• Load data into GeoServer from PostGIS tables and files on disk

• Make those data available through web-services.

3. A Browser-Based Map Management Tool - GeoExplorer

• Review GeoExplorer

• Use it to view, compose and publish maps, and

• Edit geospatial data.

4. A Map Tile Cache - GeoWebCache

• Introduce tile caching concepts.

• Discuss strategies for tile caching.

• Accelerate map rendering using tile-caching tools.

5. Web Map Client Frameworks - OpenLayers & GeoExt

• We’ll learn some HTML, CSS and JavaScript basics,

• Use the OpenLayers and GeoExt libraries to create a desktop-like map application in a webbrowser.

6. Support - Resources for support and recepies for success!

• More information and support for future adventures with the OpenGeo Suite.

3

Page 8: Introduction to The OpenGeo Suite

Introduction to The OpenGeo Suite, Release March 18, 2012

4 Chapter 1. Welcome to the Workshop

Page 9: Introduction to The OpenGeo Suite

CHAPTER 2

Data, Software and DocumentationPackage

All of the data, software, documents and template files needed for this workshop are here:suite_intro_package.zip. Unzip this packages to a folder named suiteintro2012_package on yourdesktop.

(We might call this <workshop> at various times in the course).

In some cases, we’ll be adding and/or saving files to a Tomcat virtual directory. This is located at:

<user>\.opengeo\data_dir\www\

In both cases <user> is your local user’s home directory. In a typical windows installation, this isusually:

C:\Documents and Settings\OpenGeo\

For example:

C:\\Documents and Settings\\OpenGeo\\Desktop\\suiteintro2012_package\\

C:\\Documents and Settings\\OpenGeo\\.opengeo\\data_dir\\www\\

Package Overview:

• <workshop>\Data contains all the spatial data we’ll need for our examples.

• <workshop>\HTML contains template HTML files, images and JS libraries we’ll need.

• <workshop>\Software contains the Suite installer, and a few utilities that might be helpful.

• <workshop>\SQL contains two .SQL files that we can use in the PostGIS section.

• <workshop>\Styles contains styling instructions for the spatial data we’ll be using.

5

Page 10: Introduction to The OpenGeo Suite

Introduction to The OpenGeo Suite, Release March 18, 2012

6 Chapter 2. Data, Software and Documentation Package

Page 11: Introduction to The OpenGeo Suite

CHAPTER 3

Chapter 1: The OpenGeo Suite

3.1 Introducing the OpenGeo Suite

In this section, we’ll introduce the OpenGeo Suite and illustrate a few of the terms and concepts in-volved in setting up a geo-spatial “stack”.

3.1.1 What is This “Stack” of Which You Speak?

A “stack” is industry jargon for a software system that comprises many indiviudal applications. Thestack analogy implies that the individual components stack or build up on each other.

In theory, the stack is vertical. The more fundamental components are (buried) at the bottom, with themore tangible, visible pieces at the top.

In practice, we all know that in the best stacks things bolt on to the sides, and ooze out from the edges.

3.1.2 What is the OpenGeo Suite?

The OpenGeo Suite is a fully open geospatial software stack for publishing your data on the web.

The Suite includes the following software:

1. PostGIS - PostGIS is a robust spatial database system.

2. GeoServer - GeoServer is a map and geospatial data server.

3. GeoExplorer - GeoExplorer is browser-based tool commonly used to view, navigate, and managedata from Suite components (locally and remote).

7

Page 12: Introduction to The OpenGeo Suite

Introduction to The OpenGeo Suite, Release March 18, 2012

4. GeoWebCache - GeoWebCache is a tool that speeds up your Suite maps by pre-drawing andcaching map images.

Figure 3.1: The OpenGeo Suite

There are some more tools packaged into the Suite - either directly or within one (or more) of thecomponents listed above - but these are the key pieces we’ll be using in this workshop.

3.2 Installing the OpenGeo Suite

In this section we will install the OpenGeo Suite on your workshop machine.

3.2.1 Installation Steps

The OpenGeo Suite executable file is located in the workshop package in the Software folder.

Note: During this installation, please keep all of the default settings.

1. Double-click the file OpenGeoSuite-ee-<version>.exe to begin the installation.

2. On some systems, you might see a Windows Security Warning. The Suite software is safe, clickRun to launch the Suite installer.

8 Chapter 3. Chapter 1: The OpenGeo Suite

Page 13: Introduction to The OpenGeo Suite

Introduction to The OpenGeo Suite, Release March 18, 2012

Figure 3.2: Windows Security Warning

3. At the Welcome screen, click Next.

Figure 3.3: OpenGeo Suite installation Welcome screen

4. Read the License Agreement, then click I Agree.

3.2. Installing the OpenGeo Suite 9

Page 14: Introduction to The OpenGeo Suite

Introduction to The OpenGeo Suite, Release March 18, 2012

Figure 3.4: License Agreement

5. Select the Destination Folder where you would like to install the OpenGeo Suite, and click Next.

Figure 3.5: Destination Folder for the Suite installation

6. Select the name and location of the Start Menu Folder that will be created for the Suite components,and click Next.

10 Chapter 3. Chapter 1: The OpenGeo Suite

Page 15: Introduction to The OpenGeo Suite

Introduction to The OpenGeo Suite, Release March 18, 2012

Figure 3.6: Start Menu Folder to be created for the Suite installation

7. Choose the components you wish to install.

Figure 3.7: Component selection

Note: All components are installed by default except for the optional ArcSDE and Oracle Spatialextensions. As these extensions require additional files to function, we will not be using them inthis workshop.

8. When you are ready, click Install to start the installation.

3.2. Installing the OpenGeo Suite 11

Page 16: Introduction to The OpenGeo Suite

Introduction to The OpenGeo Suite, Release March 18, 2012

Figure 3.8: Ready to install

9. Please wait while the installation proceeds.

Figure 3.9: Installation progress monitor

10. After installation, click Finish to start the OpenGeo Suite and launch the Dashboard. If you wouldlike to start the OpenGeo Suite at a later time, uncheck the Launch ... box.

12 Chapter 3. Chapter 1: The OpenGeo Suite

Page 17: Introduction to The OpenGeo Suite

Introduction to The OpenGeo Suite, Release March 18, 2012

Figure 3.10: The OpenGeo Suite has been installed

The Dashboard is presented in detail the next section.

However, to complete this installation process, we’re going to review a few of the initialization stepsthat need to be performed when you run the OpenGeo Suite Dashboard for the first time.

1. This Welcome screen confirms your (default) credentials for authenticating to GeoServer. ClickClose to proceed. You can uncheck the Show ... box to prevent this dialog from launching in thefuture.

Figure 3.11: GeoServer Administration credentials

Although the OpenGeo Suite has been installed, it’s not actually running yet. In fact, if you ever re-startyour machine, the Suite does not run automatically. Whenever the Suite isn’t running, the Dashboardwill display a green Start button in the top right corner.

1. Click Start to launch the service components that make up the OpenGeo Suite. A ‘spinner’ pop-upwill let you know how things are moving along.

3.2. Installing the OpenGeo Suite 13

Page 18: Introduction to The OpenGeo Suite

Introduction to The OpenGeo Suite, Release March 18, 2012

Starting-up the OpenGeo Suite from the Dashboard

2. On certain operating systems, you might be presented with a Security Alert about your PostgreSQLServer. You can click OK here. PostgreSQL is the database server that sits underneath PostGIS;we trust it. Optionally, you can check the box to not show this message again.

Figure 3.12: Security Alert for PostgreSQL Server

3. Again, on certain operating systems, you might see a Security Alert about your Java Platformtrying to poke tiny holes in your local firewall. You can click Unblock here. The Java plat-form is (among other things) the web application container that GeoServer and other Suite web-applications run in; we also trust this component.

14 Chapter 3. Chapter 1: The OpenGeo Suite

Page 19: Introduction to The OpenGeo Suite

Introduction to The OpenGeo Suite, Release March 18, 2012

Figure 3.13: Security Alert for the Java Platform

4. When this initial run of the Suite is complete, you’ll be back at the main Dashboard interface withthe Suite up and running.

Figure 3.14: The OpenGeo Suite Dashboard (Running)

3.3 The OpenGeo Suite Dashboard

In this section, we’ll dig a bit deeper and familiarize you with the Dashboard’s functions and content.

As we introduce the Dashboard, take some time to explore it - Click away to your hearts’ content.

We had a quick look at the Dashboard at the end of the previous section when it launched automatically(and initialized) following our installation of the Suite.

• The Dashboard provides a central interface for accessing the various components of the OpenGeoSuite.

• The Suite Dashboard also provides links to a variety of documents and information sources forSuite users at all levels.

3.3. The OpenGeo Suite Dashboard 15

Page 20: Introduction to The OpenGeo Suite

Introduction to The OpenGeo Suite, Release March 18, 2012

The Dashboard should already be open; however, if it is not, you can always launch it manually fromthe Start Menu at Start → Programs → OpenGeo Suite 2.4.3 → OpenGeo Suite Dashboard.

3.3.1 The Dashboard Main Screen

The (default) Dashboard tab is divided into two sections:

• At a Glance panel, and

• Components panel.

Figure 3.15: The OpenGeo Suite Dashboard

At a Glance Panel

The At a Glance panel provides quick access to a set of Suite tools that allow you to:

1. Load and manage data in PostGIS and GeoServer (Datastores),

2. Style, edit, and optimize the presentation of your map layers (Layers), and

3. Compose maps and mapping applications through inspiring examples (Maps).

Components Panel

The Components panel presents a list of links and launchers to tools and documents for each of the Suitecomponents.

Mousing over rows in this list exposes the links/launchers available for each component; hovering overa link/launcher pops-up a tool-tip with the name of the target application or document.

Components Sub-Tab

The Dashboard > Components sub-tab reiterates the list of Suite components, with more detailed descrip-tions of the applications.

16 Chapter 3. Chapter 1: The OpenGeo Suite

Page 21: Introduction to The OpenGeo Suite

Introduction to The OpenGeo Suite, Release March 18, 2012

Figure 3.16: The OpenGeo Suite Dashboard Components sub-tab

Logs Sub-Tab

The Dashboard > Logs sub-tab presents the log files for your Suite installation. These logs generally justkeep you posted about the status of various Suite services; however, if there are ever issues with yoursoftware, the content in this section can provide you with valuable troubleshooting information.

Figure 3.17: The OpenGeo Suite Dashboard Logs sub-tab

Preferences Sub-Tab

The Dashboard > Preferences sub-tab is an interface for viewing and configuring some of the Suite set-tings.

3.3. The OpenGeo Suite Dashboard 17

Page 22: Introduction to The OpenGeo Suite

Introduction to The OpenGeo Suite, Release March 18, 2012

Figure 3.18: The OpenGeo Suite Dashboard Preferences sub-tab

1. Service Ports lists the Primary Port and Shutdown Port on which GeoServer and (servlet container)web-applications are running. (Values in this section can only be changed when the Suite is Shut-down.)

2. GeoServer lists the Data Directory base path that GeoServer uses for spatial files, and the Usernameand Password used to authenticate to GeoServer for administration.

3. PostGIS lists the Port on which PostGIS is accessible. (Values in this section can only be changedwhen the Suite is Shutdown.)

We won’t make any changes here, but if you ever choose to just remember to click the Save button towrite your changes into configuration files, and then re-start (Shutdown and Start) the Suite to effectthe changes.

If everything starts to go sideways, and you want everything back the way it was, just click the Resetbutton.

Note: The reset button only applies to the OpenGeo Suite. It cannot reverse arguments with yourspouse, little lies you told to your mum when you were 11, or ANYTHNG that happened in ‘Vegas.

3.3.2 Documentation Tab

The Documentation tab (on the left, under the Dashboard tab) presents a variety of links to informationdesigned to help you get started using the OpenGeo Suite. For example, the Getting Started page de-scribes a common, a high-level workflow for getting your data served and published on the web usingthe Suite stack.

18 Chapter 3. Chapter 1: The OpenGeo Suite

Page 23: Introduction to The OpenGeo Suite

Introduction to The OpenGeo Suite, Release March 18, 2012

Figure 3.19: A quick-start for getting your data served on the web using the Suite stack

Explore the other links to get more detailed information about the Suite and its various components.Note that many of the links will launch your browser and take you to the appropriate configurationand/or demonstration web pages.

Note: The OpenGeo Suite must be online in order to view documentation through the Dashboard.If you would like to view the documentation when the Suite is offline, you can use the shortcuts inthe Start Menu at Start Menu → All Programs → OpenGeo Suite 2.4.3 → Documentation → <ApplicationName>.

3.3.3 Accessing Suite Components without the Dashboard

The OpenGeo Suite Dashboard is designed as a convenience to Suite users, but it is not the only way toaccess the Suite components.

• Desktop tools that ship with the suite can be launched through the Start Menu under Start Menu→ All Programs → OpenGeo Suite 2.4.3 → <Application Name>. (Eg. pgAdmin.)

• All Suite web applications can be accessed directly through the browser. The OpenGeo Suiteruns locally at the port where it was installed (the default is 8080). Some helpful URLs for thisworkshop are:

– GeoServer - http://localhost:8080/geoserver

– GeoWebCache - http://localhost:8080/geowebcache

– GeoExplorer - http://localhost:8080/geoexplorer

3.3. The OpenGeo Suite Dashboard 19

Page 24: Introduction to The OpenGeo Suite

Introduction to The OpenGeo Suite, Release March 18, 2012

20 Chapter 3. Chapter 1: The OpenGeo Suite

Page 25: Introduction to The OpenGeo Suite

CHAPTER 4

Chapter 2: PostGIS

4.1 Introducing PostGIS

4.1.1 What is PostGIS?

PostGIS is a spatial database. More accurately, PostGIS is an extension that turns the PostgreSQLdatabase system into a spatial database..

PostGIS is very similar in functionality to spatial support in SQL Server 2008 , Oracle Spatial, and DB2Spatial Extender.

Providing optimized access to large amounts of spatial data, PostGIS is a fundamental component ofthe OpenGeo Suite.

To reinforce this notion, we’ll put it down near the bottom of our architecture diagram, and build therest of the stack out on top of it.

21

Page 26: Introduction to The OpenGeo Suite

Introduction to The OpenGeo Suite, Release March 18, 2012

Figure 4.1: PostGIS in the OpenGeo Suite stack

4.2 Spatial Databases

In this section we’ll have a really quick look at the factors that make a spatial database special.

4.2.1 What is a Spatial Database?

What makes an ordinary database a spatial database?

The short answer, is ...

Spatial databases store and manipulate spatial objects like any other object in the database.

22 Chapter 4. Chapter 2: PostGIS

Page 27: Introduction to The OpenGeo Suite

Introduction to The OpenGeo Suite, Release March 18, 2012

The long(er) answer is ...

Three factors allow spatial objects to exist natively in a database:

1. Spatial data types store shapes like points, lines, and polygons in geometry columns

2. Spatial functions, posed in SQL, for querying spatial properties and relationships

3. Multi-dimensional spatial indexes are used for efficient processing of spatial operations

We’ll have a look at these concepts in more detail in the next three sections.

4.3 Spatial Data Types

Spatial data types store shapes like points, lines, and polygons in geometry columns.

4.3.1 Spatial Data Types

Spatial data types can be understood simply as a binary representation of a shapes in a database row(with location).

Spatial data types are organized in a type hierarchy. Each sub-type inherits the structure (properties)and the behavior (methods or functions) of its super-type.

4.4 Spatial Functions

Spatial functions, posed in SQL, for querying spatial properties and relationships.

4.3. Spatial Data Types 23

Page 28: Introduction to The OpenGeo Suite

Introduction to The OpenGeo Suite, Release March 18, 2012

4.4.1 Base Type Functions

To manipulate data during a query, an ordinary database provides functions for:

• Doing mathematics on numbers

• Extracting information from dates, and

• Working with strings,

• Etc!

4.4.2 Spatial Functions

In addition to base-type functions, a spatial database provides a functions for operating on geometries.

Spatial functions are commonly categorized by function:

• Management

– Make me a new geometry column in a table! AddGeometryColumn()

– Update all of my existing geometry columns Populate_Geometry_Columns()

• Conversion

– Show me the text representation of this point ST_AsText()

– Convert this text into a PostGIS geometry ST_GeomFromText()

• Retrieval

– How long is this line? ST_Length()

– What is the perimeter of Uzbekistan? ST_Perimeter()

• Comparison

– Is France next to Finland? ST_Touches()

– Is Paris in China? ST_Contains()

• Generation Functions

– Calculate a 20 km exclusion limit around Moose Factory! ST_Buffer()

– Consolidate New York and New Jersey! ST_Union()

24 Chapter 4. Chapter 2: PostGIS

Page 29: Introduction to The OpenGeo Suite

Introduction to The OpenGeo Suite, Release March 18, 2012

4.5 Spatial Indexes

Multi-dimensional spatial indexes are used for efficient processing of spatial operations.

4.5.1 Natural Sort Order

Indexes for basic data types are ~relatively~ easy to compute and understand.

The natural sort order of numbers, strings, and dates is simple to determine – every value is less than,greater than or equal to every other value.

A decent analogy is an indexing system that we likely use daily:

4.5. Spatial Indexes 25

Page 30: Introduction to The OpenGeo Suite

Introduction to The OpenGeo Suite, Release March 18, 2012

4.5.2 Indexing Geometries with Bounding Boxes

Indexes for geometries are not so simple. Since polygons can overlap, can be contained in one another,and are arrayed in a two-dimensional (or greater) space, the notion of a natural sort order doesn’t reallyapply.

Spatial indexes very basically compute and compare each feature’s bounding box (BBOX) which is thesmallest size rectangle capable of containing a given feature.

Even the most complex polygons and linestrings can be represented by a simple bounding box.

26 Chapter 4. Chapter 2: PostGIS

Page 31: Introduction to The OpenGeo Suite

Introduction to The OpenGeo Suite, Release March 18, 2012

Bounding boxes are used to answer questions like “What countries are next to France?” since the questionis very computationally intensive for polygons and complex lines, but very fast in the case of rectangles.

However, the comparison of bounding rectangles isn’t as accurate as comparing exact geometries.

Spatial indexes provide approximate results in a first pass, which are then honed to an exact result.

With large, complex datasets, it is much faster to compute exact results from this sub-set of approximatecandidates, than to sequentially scan relationships between entire feature-sets in one pass.

4.6 Creating a PostGIS Spatial Database

In this section, with some spatial database concepts under our belts, we’ll use the GUI client pgAdminto connect to the PostGIS server and create a spatially-enabled database.

4.6.1 Start PostGIS and Connect PgAdmin

1. Make sure the Dashboard is open on your desktop.

2. If it isn’t already, we need to start up the OpenGeo Suite - This will also start our PostGIS database.Click the green Start button in the top right corner of the Dashboard.

3. When the Suite is started, you can click the Manage option under the PostGIS component to startthe pgAdmin utility.

4.6. Creating a PostGIS Spatial Database 27

Page 32: Introduction to The OpenGeo Suite

Introduction to The OpenGeo Suite, Release March 18, 2012

4. You should have a server entry for PostGIS (localhost:54321) already configured in pgAdmin.Double-click the entry, and enter anything you like at the password prompt to connect to thedatabase.

Note: For this workshop, the PostGIS database has been installed with unrestricted access for localusers (users connecting from the same machine on which the database is running). That means that itwill accept any password you provide. If you need to connect from a remote computer, the passwordfor the postgres user has been set to postgres.

Note: If you have a previous installation of PgAdmin on your computer, you will not have an entryfor (localhost:54321). You will need to create a new connection. Go to File > Add Server, and register anew server at localhost and port 54321 (note the non-standard port number) in order to connect to thePostGIS that comes bundled with the OpenGeo Suite.

Note: PostgreSQL has a number of administrative front-ends. psql is a command-line tool for enteringSQL queries. pgAdmin, is a free and open source tool PostgreSQL popular because of it’s graphicalfront-end. In this workshop, we’re going to use pgAdmin, but all of the queries that can be done inpgAdmin can also be done on the command line with psql.

4.6.2 Create a Database

PostgreSQL has the notion of a template database that can be used to initialize a new database. Asyou might expect, the new database automatically gets a copy of everything from the template. Whenyou installed PostGIS, a spatially-enabled database called template_postgis was created. If we usetemplate_postgis as a template when creating our new database, the new database will be spatiallyenabled.

1. Open the Databases tree item and have a look at the available databases. The postgresdatabase is the user database for the default postgres user and is not too interesting to us. Thetemplate_postgis database is what we are going to use to create spatial databases.

2. Right-click the Databases item and select New Database.

28 Chapter 4. Chapter 2: PostGIS

Page 33: Introduction to The OpenGeo Suite

Introduction to The OpenGeo Suite, Release March 18, 2012

3. Fill in the New Database form as shown below and click OK.

Name SuiteWorkshopOwner postgresEncoding UTF8Template template_postgis

4.6. Creating a PostGIS Spatial Database 29

Page 34: Introduction to The OpenGeo Suite

Introduction to The OpenGeo Suite, Release March 18, 2012

Note: If you receive an error indicating that the source database (template_postgis) is beingaccessed by other users, this is likely because instead of just looking at it with your eyes (previ-ously), you clicked and selected it. All is not lost ...

(a) Select the database postgres.

(b) Right-click on the PostGIS (localhost:54321) item and select Disconnect.

(c) Double-click PostGIS (localhost:54321) to reconnect and try again.

4. Select the new SuiteWorkshop database and open it up to display the tree of objects. You’ll seethe public schema, a node called Tables, and under that a couple of PostGIS-specific metadatatables – geometry_columns and spatial_ref_sys.

4.7 The PostGIS Table Schema

Let’s have a (really) quick look at the key features creating the new PostGIS database did for us.

Based on the template_postgis database, our new database automatically contains all 780 of the PostGISfunctions as well as two tables:

• geometry_columns, and

• spatial_ref_sys.

30 Chapter 4. Chapter 2: PostGIS

Page 35: Introduction to The OpenGeo Suite

Introduction to The OpenGeo Suite, Release March 18, 2012

4.7.1 Spatial_Ref_Sys Table

The table, spatial_ref_sys, defines the Spatial Reference systems known to the database.

4.7.2 Geometry_Columns Table

The table, geometry_columns defines the dimension, geometry, and spatial reference system for eachfeature table in PostGIS (if they are spatially-enabled).

4.7.3 Relating the Components

4.7. The PostGIS Table Schema 31

Page 36: Introduction to The OpenGeo Suite

Introduction to The OpenGeo Suite, Release March 18, 2012

Bonus / Discussion

• Expand the Functions item among our new database’s objects. Have a look inside.

• Which of the three tenets of a spatial database was not created from the template database? Whynot? Are we there yet?

4.8 Loading Data into PostGIS

This section focuses on the basic task of loading shapefiles into our database using the graphical PostGISshapefile loading tool.

PostGIS is supported by a wide variety of libraries and applications, and provides many other optionsfor loading data in a variety of formats.

4.8.1 Using pgAdmin’s Shapefile Loader Plugin

1. First, return to the Dashboard, and click on the Import Shapefiles link in the PostGIS section. TheGUI shapefile importer pgShapeLoader will launch.

postgis/img/pgshapeloader_dashboard.png

Note: Alternatively, the PostGIS Shapefile (and DBF) loader can be launched from within pgAd-min. Click (menu) > Plugins > PostGIS Shapefile and DBF Loader to fire it up!

2. Next, open the Shape File browser and navigate to the Data directory in the workshop package.Select the cities.shp file.

32 Chapter 4. Chapter 2: PostGIS

Page 37: Introduction to The OpenGeo Suite

Introduction to The OpenGeo Suite, Release March 18, 2012

3. Fill in the details for the PostGIS Connection section (as follows), and click on the Test Connection...button.

Username postgresPassword postgresServer Host localhost 54321Database SuiteWorkshop

Note: Setting the port number to 54321 is very important! The OpenGeo PostGIS runs on port54321, not the default PostgreSQL port of 5432.

4. Next, fill in the details for the Configuration section.

Destination Schema publicSRID 4326Destination Table citiesGeometry Column the_geom

5. Click the Options button and select “Load data using COPY rather than INSERT.” This will makethe data load process a little faster.

4.8. Loading Data into PostGIS 33

Page 38: Introduction to The OpenGeo Suite

Introduction to The OpenGeo Suite, Release March 18, 2012

6. Finally, click the Import button to launch the import process.

7. Repeat the import process for the 2 remaining shapefiles in the data directory. Except for the inputfile and output table name (which is automatically updated), all the other fields in pgShapeLoadershould remain the same:

• countries.shp

• ocean.shp

8. When all of the files are loaded, click the “Refresh” button in pgAdmin to update the tree view.You should see your three new tables show up in the Tables section of the tree.

4.9 Viewing Spatial Data in PostGIS

4.9.1 What do Data in PostGIS Look Like?

Geometries in PostGIS look a little something like this ...

34 Chapter 4. Chapter 2: PostGIS

Page 39: Introduction to The OpenGeo Suite

Introduction to The OpenGeo Suite, Release March 18, 2012

SELECT the_geom from countries;

This ~binary~ isn’t really readable by humans! So, we need something not human to help us interpretand view our PostGIS data.

Many applications can connect to a PostGIS database, and display and edit data in a more appealingmanner.

Installing a fresh GIS client on your workstations is a bit beyond the scope of this workshop, but if youdo have something handy.

4.9. Viewing Spatial Data in PostGIS 35

Page 40: Introduction to The OpenGeo Suite

Introduction to The OpenGeo Suite, Release March 18, 2012

Figure 4.2: Vive la France!

Bonus / Discussion

Note: We snuck a copy of uDig into your <workshop>\Software folder.

• If you have a client capable of connecting to PostGIS, go ahead and give it a quick try. Recall theconnection parameters from earlier:

Username postgresPassword postgresServer Host localhost 54321Database SuiteWorkshop

4.10 Basic Spatial Queries and Functions

PostGIS adds several hundred (~780) geometry-specific functions to PostgreSQL.

Discussing all of them is beyond the scope of this workshop!

In this section we’ll work through a short example to introduce function syntax, and add another tableto our SuiteWorkshop database.

4.10.1 Accessing Spatial Functions

Accessing PostGIS’ spatial functions is no different than accessing string, number or date functions inan ordinary database.

Functions are expressed in Structured Query Language (SQL) statements. For example:

SELECT postgis_full_version();

4.10.2 Creating a Spatially-Enabled Table

A short example shows us how to spatially enable a newly-created table in our PostGIS database usingthe AddGeometryColumn function.

1. If it isn’t already, open up your pgAdmin SQL Query window.

36 Chapter 4. Chapter 2: PostGIS

Page 41: Introduction to The OpenGeo Suite

Introduction to The OpenGeo Suite, Release March 18, 2012

2. Open the file <workshop>\SQL\smallworld_create.sql, or copy and paste the followingblock into the SQL Query Editor.

CREATE TABLE "smallworld" (gid serial PRIMARY KEY, "placename" varchar(50), "comment" varchar(255), "year" numeric);

SELECT AddGeometryColumn(’’,’smallworld’,’the_geom’,’4326’,’POINT’,2);

3. Click the Play button to execute the commands.

The first line in the code-block CREATE TABLE ..., created a table with the specified columns and keys.This is stock SQL.

The second line is our spatial part. AddGeometryColumn does exactly what it’s name suggests, and alittle bit more. This function:

1. Inserts an entry to the geometry_columns table, identifying:

• The table that has a geometry column smallworld

• The name of that geometry column the_geom

• The SRID of the geometries 4326

• The geometry type of the geometries POINT, and

• The dimensionality of the geometries 2.

2. Adds a Geometry column (called the_geom) to the feature table using an SQL ALTER TABLEstatement;

3. Adds a set of constraints to the feature table make sure new features are:

• In SRID 4326,

• Geometry type POINT, and

• Of 2 dimensions.

If we have a look at the entries in the geometry_colums table, we can see the row for the spatiallyenabled smallworld table.

Furthermore if we have another look at our smallworld table, we can see the newly created geometrycolumn the_geom, and in the table properties the constraints.

Figure 4.3: It’s a spatially-enabled small world after all

Finally, let’s add some features to our smallworld table.

1. If it isn’t already, open up your pgAdmin SQL Query window.

4.10. Basic Spatial Queries and Functions 37

Page 42: Introduction to The OpenGeo Suite

Introduction to The OpenGeo Suite, Release March 18, 2012

2. Open up the file <workshop>\SQL\smallworld_insert.sql, or copy and paste the follow-ing block into the SQL Query Editor.

INSERT INTO smallworld (the_geom, placename, comment, year) VALUES (ST_GeomFromText(’POINT(-147.68920897258 64.8302537436281)’,4326), ’Fairbanks’, ’Into the Wild ...’, 1992);

INSERT INTO smallworld (the_geom, placename, comment, year) VALUES (ST_GeomFromText(’POINT(174.807586609872 -41.2530324129332)’,4326), ’Wellington’, ’Discovery’, 2011);

INSERT INTO smallworld (the_geom, placename, comment, year) VALUES (ST_GeomFromText(’POINT(51.833333 12.25)’,4326), ’Dessau’, ’FOSSGIS’, 2211);

INSERT INTO smallworld (the_geom, placename, comment, year) VALUES (ST_GeomFromText(’POINT(-77.414217 38.975892)’,4326), ’Dulles’, ’Pixia’, 2211);

3. Click the Play button to execute the commands.

4. Have a look at the newly created smallworld table back in pgAdmin:

Right-click Tables > Refresh

Right-click smallworld > View Data > View All Rows

Those commands provided SQL instructions for adding data to our smallworld table.

In an upcoming section, we’ll add more data to that same table in a more interactive and memorablemanner.

38 Chapter 4. Chapter 2: PostGIS

Page 43: Introduction to The OpenGeo Suite

CHAPTER 5

Chapter 3: GeoServer

5.1 Introducing GeoServer

5.1.1 What is GeoServer?

GeoServer is an open source software server written in Java that allows users to share and edit geospa-tial data. Designed for interoperability, GeoServer publishes data from any major spatial data sourceusing open standards.

We’ll look at server/service concepts in more detail in another section.

For now, just think of GeoServer as a ~gateway~ to collections of geospatial data in files, databases, orother services on a server (or servers).

In the evolving diagram of our OpenGeo Suite architecture GeoServer sits over-top of PostGIS, sharingdata from the database to clients.

39

Page 44: Introduction to The OpenGeo Suite

Introduction to The OpenGeo Suite, Release March 18, 2012

Figure 5.1: GeoServer in the OpenGeo Suite stack

5.2 Server Basics

GeoServer is a server of geospatial data through the web.

In this section, we’ll have a brief discussion of what a web server is and how it works.

5.2.1 Web Servers

A web server is a program that serves content (web pages, images, files, data, etc.) using HTTP (Hyper-text Transfer Protocol). When you use your browser to connect to a website, you contact a web server.The web server takes the request, interprets it, and returns a response, which the browser renders onthe screen.

40 Chapter 5. Chapter 3: GeoServer

Page 45: Introduction to The OpenGeo Suite

Introduction to The OpenGeo Suite, Release March 18, 2012

For example, when you request a web page, your request takes the form of a URL:

http://example.com/some/path/page.html

The web server looks to its file system, and if that request points to a valid file (if page.html existsin some/path), the contents of that file will be returned via HTTP. Usually these calls come from abrowser, in which case the result is rendered in the browser.

It is possible to request many different kind of files through HTTP, not just HTML pages:

http://example.com/some/path/image.jpghttp://example.com/some/path/archive.ziphttp://example.com/some/path/data.xml

If your browser is configured to display the type of file, it will be displayed, otherwise you will usuallybe asked to download the file to your host system.

The most popular web servers used today are Apache HTTP Server and Internet Information Services(IIS).

5.3 Web Mapping Servers

A web mapping server is a specialized subset of the web server model. Like a web server, requests aresent to the server, they are interpreted and responded to.

The key differences between a web-mapping server and a ~standard~ web-server are that:

• Responses aren’t neccessarily a document or file (in the .HTML, .ZIP, .MP3 sense of the word), butgeographic data.

• The request is a bit more specific than http://server/file.extension

Because it wouldn’t be realistic or useful to simply say ~”Give me all the geography ever”~, we usespecific, structured protocols to request discrete portions of geography from the web-mapping server.

Protocols that can be employed to make requests for geographic data include:

• Web Map Service (WMS)

• Web Feature Service (WFS)

Some popular web mapping servers:

• GeoServer

• MapServer

• Mapnik

• ArcGIS Server

5.3. Web Mapping Servers 41

Page 46: Introduction to The OpenGeo Suite

Introduction to The OpenGeo Suite, Release March 18, 2012

5.4 GeoServer

GeoServer is a specific implementation of a web-mapping server, offering access to data in a known setof formats and sources (files and databases), using specific protocols.

In a way, GeoServer acts as an abstraction layer. It allows standards-based methods of accessing geospa-tial data regardless of the source data type.

5.4.1 Data Sources

GeoServer can read from many different data sources, from files on the local disk to external databases.

The following is a list of the most common data formats supported by GeoServer. This list is by nomeans exhaustive.

• Files

– Shapefile

– GeoTIFF

– ArcGrid

– JPEG2000

– GDAL formats

• Databases

– PostGIS

– ArcSDE

– Oracle Spatial

– DB2

– SQL Server

5.4.2 OGC Protocols

GeoServer implements standard open web protocols established by the Open Geospatial Consortium(OGC)), a standards organization.

GeoServer contains a high-performance certified compliant Web Map Service (WMS), and is in fact thereference implementation of the OGC Web Feature Service (WFS) and Web Coverage Service (WCS)standards.

The next sections will provide an overview of the two protocols most commonly used by GeoServer.

5.5 Web Map Service (WMS)

A fundamental component of the web map (and likely the simplest to understand) is the map image.The Web Map Service (WMS) is a standard protocol for serving georeferenced map images generatedby a map server.

In short, WMS is a way for a client to request map images from a server. The client sends a request toa map server, then the map server generates an image based on parameters passed to the server in therequest and finally returns an image.

The source material from which the image is generated need not be an image. The WMS generatesan image from whatever source material is requested, which could be vector data, raster data, or acombination of the two.

42 Chapter 5. Chapter 3: GeoServer

Page 47: Introduction to The OpenGeo Suite

Introduction to The OpenGeo Suite, Release March 18, 2012

Figure 5.2: A diagram showing how a WMS turns data into a map image

5.5.1 Sample WMS request

The following is a sample WMS request, rendered as a HTTP GET request (with line breaks added forclarity) to a hosted GeoServer instance:

http://suite.opengeo.org/geoserver/wms?SERVICE=WMS&VERSION=1.3.0&REQUEST=GetMap&LAYERS=usa:states&SRS=EPSG:4326&BBOX=24.956,-124.731,49.372,-66.97&FORMAT=image/png&WIDTH=600&HEIGHT=255

While the details of the WMS protocol are beyond the scope of this course, a quick scan of this requestshows that the following information is being requested:

• Server details (a WMS 1.3.0 request)

• Request type (a WMS GetMap request)

• Layer name (usa:states)

• Projection (EPSG:4326)

• Bounding box (in this case, latitude/longitude coordinates)

• Image properties (600x255 PNG)

If you paste the request into a browser, the result would be:

5.5. Web Map Service (WMS) 43

Page 48: Introduction to The OpenGeo Suite

Introduction to The OpenGeo Suite, Release March 18, 2012

Figure 5.3: An image generated by a WMS request

5.5.2 Other WMS requests

A WMS request can ask for more than just a map image (“GetMap”).

An example of another such request is a request for information about the WMS server itself.

The request is called GetCapabilities, and the response is known as the capabilities document.

The capabilities document is an XML response that details the supported image formats, projections,and map layers being served by that WMS.

The following is a WMS GetCapabilities request given to the same WMS used above:

http://suite.opengeo.org/geoserver/wms?SERVICE=WMS&VERSION=1.3.0&REQUEST=GetCapabilities

If you want, you can paste this request into a browser to see the result.

5.5.3 More Information

For more information, please see the OGC site on the Web Map Service protocol athttp://www.opengeospatial.org/standards/wms.

5.6 Web Feature Service (WFS)

A web mapping server can also return the actual geographic data that comprise the map images. Thisallows users to create their own maps and applications from the data, to convert data between certainformats, and be able to do raw geographic manipulations of served data. The protocol used to returngeographic feature data is called Web Feature Service (WFS).

44 Chapter 5. Chapter 3: GeoServer

Page 49: Introduction to The OpenGeo Suite

Introduction to The OpenGeo Suite, Release March 18, 2012

Figure 5.4: A diagram showing how a WFS turns a request into a response

5.6.1 Sample WFS request

The following is a sample WFS request, rendered as a HTTP GET request (with line breaks added forclarity) to a hosted GeoServer instance:

http://suite.opengeo.org/geoserver/wfs?SERVICE=wfs&VERSION=1.1.0&REQUEST=GetFeature&TYPENAME=usa:states&FEATUREID=states.39

While the details of the WFS protocol are beyond the scope of this course, a quick scan of this requestshows that the following information is being requested:

• Server details (WFS 1.1.0 request)

• Request type (GetFeature)

• Layer name (usa:states)

• Feature ID (states.39)

This particular request polls the WFS for a single feature in a specific layer.

Note: A feature is a single unit of geographic data, such as a polygon or point. The above featurerequested is the multipolygon for the state of New York.

Paste the request into a browser to see the result. The response contains the coordinates for each vertexin the feature in question, along with the attributes associated with this feature. Scroll down to thebottom to see the feature attributes.

5.6. Web Feature Service (WFS) 45

Page 50: Introduction to The OpenGeo Suite

Introduction to The OpenGeo Suite, Release March 18, 2012

Figure 5.5: XML generated by a WFS request

While XML is difficult for us to read, it is easy for computers to parse, which makes WFS responsesideal for use in software. GeoServer offers other output formats as well, such as JSON, CSV, and zippedshapefile.

5.6.2 Other WFS requests

A WFS request can ask for more than just feature data. An example of another request is to requestinformation about the WFS server. The request is called GetCapabilities, and the response is known asthe capabilities document. The capabilities document is an XML response that details the supporteddata layers, projections, bounding boxes, and functions available on the server.

The following is a sample WFS GetCapabilities request:

http://suite.opengeo.org/geoserver/wfs?SERVICE=WFS&VERSION=1.1.0&REQUEST=GetCapabilities

You can paste this request into a browser to see the result.

5.6.3 More Information

Please see the OGC site on the Web Feature Service protocol athttp://www.opengeospatial.org/standards/wfs.

5.7 GeoServer’s Admin Interface

GeoServer includes a web-based administration interface through which most data/service configura-tions can be made. This interface lessens the need to edit configuration files by hand.

This section will give a brief overview to the web interface.

5.7.1 Viewing

The default location of the GeoServer admin interface is http://localhost:8080/geoserver. The initialpage is called the Welcome page.

46 Chapter 5. Chapter 3: GeoServer

Page 51: Introduction to The OpenGeo Suite

Introduction to The OpenGeo Suite, Release March 18, 2012

Figure 5.6: GeoServer Welcome page

5.7.2 Authentication

For security reasons, most GeoServer configuration tasks require that you log in. By default, theGeoServer administration credentials are admin and geoserver. These can be changed.

1. If you haven’t already, launch the GeoServer admin interface http://localhost:8080/geoserver.

2. Log in using the default credentials.

Figure 5.7: Logging in with default credentials

3. After logging in, many more options will be displayed.

Figure 5.8: GeoServer Welcome page with administrative options

5.7.3 Navigation & Layout

The links in the left-hand column load management pages for specific features of GeoServer:

• Status

• Data

• Services

• Security

5.7. GeoServer’s Admin Interface 47

Page 52: Introduction to The OpenGeo Suite

Introduction to The OpenGeo Suite, Release March 18, 2012

• Etc.

Links in the right-hand column of the main page lead to the capabilities documents for each service(WFS, WMS, WCS).

We will be using the links on the left under Data (Workspaces, Stores, Layers, etc.) predominently inthis workshop, so it is a good idea to familiarize yourself with their location.

5.7.4 Layer Preview

You can use the Layer Preview link to easily view layers currently being served by GeoServer. TheLayer Preview page includes quick links for viewing layers using OpenLayers, and other services.

1. Click on the Layer Preview link, located on the left side under Data.

Figure 5.9: Navigating to the Layer Preview page

2. Preview a few layers by clicking on the OpenLayers link next to each layer.

Figure 5.10: The Layer Preview page

48 Chapter 5. Chapter 3: GeoServer

Page 53: Introduction to The OpenGeo Suite

Introduction to The OpenGeo Suite, Release March 18, 2012

Figure 5.11: Viewing the usa:states layer

Note: Take a look at the contents of the URL in the browser address bar when viewing an OpenLayersmap. It is similar in construction to the sample WMS requests made in the geoserver.overview.wms sec-tion. The salient difference is the use of format=application/openlayers as the output format.

Bonus / Discussion

Spend some time exploring this interface and its features by clicking through the links on the left.The Demos link in particular contains some helpful utilities for testing and learning about the inner-workings of GeoServer functionality.

5.8 GeoServer Concepts

GeoServer uses lots of terminology, that can be confusing if you are not used to web-mapping. Thissection introduces the GeoServer terms that we will use in upcoming sections.

5.8.1 Workspace

A workspace is the name for a notional container used to group similar data together. It is designed tobe a separate, isolated space relating to a certain project. Using workspaces, it is possible to use layerswith identical names (in other workspaces) without conflict.

Workspaces are usually used as a prefix to a layer or store. For example, a layer called streets in aworkspace called nyc would be referred to by nyc:streets.

Stores and layers must all have an associated workspace.

Note: Technically, the name of a workspace is a URI, not the short prefix. A URI is a Uniform ResourceIdentifier, which is similar to a URL, but does not need to resolve to a web site. In the above example, thefull workspace could have been http://opengeo.org/nyc in which case the full layer name wouldbe http://opengeo.org/nyc:streets GeoServer intelligently replaces the workspace prefix withthe full workspace URI, but it can be useful to know the difference.

5.8.2 Store

A store is the name for a container of geographic data. A store refers to a specific data source, be it ashapefile, database, or any other data source that GeoServer supports.

• A store can contain many layers, as in the case of a database that contains many tables.

• A store can also have a single layer, such as in the case of a GeoTIFF, which can only contain onelayer.

5.8. GeoServer Concepts 49

Page 54: Introduction to The OpenGeo Suite

Introduction to The OpenGeo Suite, Release March 18, 2012

• A store must contain at least one layer.

GeoServer saves the connection parameters to each store (such as a path to the shapefile, or credentialsto connect to the database).

Each store is associated with one (and only one) workspace.

5.8.3 Layer

A layer is a collection of geospatial features or a coverage.

• Typically a layer contains one geometry type (points, lines, polygons, raster), and

• Has a single type of content (streets, houses, country boundaries, etc.).

Aside from individual features, a layer is the smallest grouping of geospatial data.

A layer corresponds to a table or view from a database, or an individual file.

GeoServer stores information associated with a layer, such as projection information, bounding box,associated styles, and more. Each layer must be associated with one (and only one) workspace.

5.8.4 Layer Group

A layer group, as its name suggests, is a grouping of layers. A layer group makes it possible to requestmultiple layers with a single WMS request.

A layer group contains information about the layers that comprise the layer group, the order in whichthey are rendered, the projection, associated styles, and more. This information can be different fromthe defaults for each individual layer.

Layer groups do not respect the concept of workspace, and are relevant only to WMS requests.

50 Chapter 5. Chapter 3: GeoServer

Page 55: Introduction to The OpenGeo Suite

Introduction to The OpenGeo Suite, Release March 18, 2012

5.8.5 All Together Now

Figure 5.12: Relationships between workspaces, stores, layers, and layer groups

5.8.6 Style

A style is a visualization directive for rendering geographic data.

A style can contain basic instructions for color, shape, and size, along with advanced rules for renderingfeatures differently based on attributes and zoom-levels.

Every layer must be associated with at least one style (GeoServer applies a default style to each newlayer).

GeoServer recognizes styles in Styled Layer Descriptor (SLD) format.

5.8. GeoServer Concepts 51

Page 56: Introduction to The OpenGeo Suite

Introduction to The OpenGeo Suite, Release March 18, 2012

5.9 Creating a Workspace

The first step in data loading is usually to create a workspace. This creates a virtual container for yourproject data. Multiple layers from multiple sources can be contained inside a workspace, with theprovision that each layer name is unique within the workspace.

1. Navigate to the main geoserver.webadmin page.

2. Click on the Workspaces link on the left column, under Data.

Figure 5.13: Click to go to the Workspaces page

3. Click the “Add new workspace” link at the top center of the page.

Figure 5.14: Workspaces page

4. A workspace is comprised of a Name (also sometimes known as a “namespace prefix”), repre-sented by a few characters, and a Namespace URI. These two fields must uniquely identify theworkspace. Fill in the following information:

Name earthNamespace URI http://geoserver.org/earthDefault workspace Checked

52 Chapter 5. Chapter 3: GeoServer

Page 57: Introduction to The OpenGeo Suite

Introduction to The OpenGeo Suite, Release March 18, 2012

Figure 5.15: Creating a new workspace

5. When done, click Submit.

With our workspace created, we can load our data files.

5.10 Publishing Data from the File-System

In this section, we will load a single GeoTIFF from the file-system. This GeoTIFF contains shaded relieffor land area, using standard tri-band RGB values (0-255).

5.10.1 Adding a store

A GeoTIFF is a store that contains a single layer.

1. From the geoserver.webadmin page, click on the Stores link on the left side, under Data.

Figure 5.16: Click this link to go to the Stores page

2. Click on Add new store.

5.10. Publishing Data from the File-System 53

Page 58: Introduction to The OpenGeo Suite

Introduction to The OpenGeo Suite, Release March 18, 2012

Figure 5.17: Stores page

3. Select GeoTIFF under Raster Data Sources.

Figure 5.18: Adding a GeoTIFF store

4. Fill out the form as follows:

Workspace earth Should be the default.Data SourceName

shadedrelief This can be anything, but it makes sense to match this withthe name of the file.

Enabled Checked Ensures the layer is published. Unchecking will saveconfiguration information only.

Description Add any layerdescription.

Layer metadata is recommended but not required.

5. In the box marked URL, type in the full path to the GeoTIFF, or click the Browse button to navigateto the file. This may be something like:

<workshop>\data\shadedrelief.tif

54 Chapter 5. Chapter 3: GeoServer

Page 59: Introduction to The OpenGeo Suite

Introduction to The OpenGeo Suite, Release March 18, 2012

Figure 5.19: Configuring a GeoTIFF store

6. When finished, click Save.

5.10.2 Publishing a layer

After the store is loaded, we need to configure how it is published as a layer.

1. On the next screen, a list of layers in the store is displayed. Since we are working with a GeoTIFF,there is only a single layer. Click the Publish link to configure the layer.

Figure 5.20: Selecting a layer to publish

2. This is the layer configuration page. There are many settings on this page, most of which we don’tneed to work with just now. We will return to some of these settings later. Fill out the form withthe following information:

(a) Set the Declared SRS to EPSG:4326 if it isn’t already.

(b) Set the SRS handling to Force declared, again if not already set.

5.10. Publishing Data from the File-System 55

Page 60: Introduction to The OpenGeo Suite

Introduction to The OpenGeo Suite, Release March 18, 2012

(c) In the Bounding Boxes section, click on the Compute from data and Compute from nativebounds links to set the bounding box of the layer.

56 Chapter 5. Chapter 3: GeoServer

Page 61: Introduction to The OpenGeo Suite

Introduction to The OpenGeo Suite, Release March 18, 2012

Figure 5.21: Configuring a layer to publish

5.10. Publishing Data from the File-System 57

Page 62: Introduction to The OpenGeo Suite

Introduction to The OpenGeo Suite, Release March 18, 2012

3. When finished, click Save. Your GeoTIFF is now published in GeoServer!

5.10.3 Preview your Work

1. You can now view the layer using the integrated OpenLayers client (using WMS) via thegeoserver.webadmin.layerpreview as in previous sections. Clicking on the map will display the RGBvalues for that particular point.

Figure 5.22: Viewing the published layer in OpenLayers

Your GeoTIFF has been successfully published in GeoServer!

5.11 Loading Many Shapefiles

[[[ Intro ...

5.11.1 Create a Store from a Directory of Spatial Files

[[[]]] Flesh out the steps ...

58 Chapter 5. Chapter 3: GeoServer

Page 63: Introduction to The OpenGeo Suite

Introduction to The OpenGeo Suite, Release March 18, 2012

5.11. Loading Many Shapefiles 59

Page 64: Introduction to The OpenGeo Suite

Introduction to The OpenGeo Suite, Release March 18, 2012

5.12 Importing a Directory of Files

[[[ Intro ...

60 Chapter 5. Chapter 3: GeoServer

Page 65: Introduction to The OpenGeo Suite

Introduction to The OpenGeo Suite, Release March 18, 2012

5.12.1 Import From File-Based Store

5.12. Importing a Directory of Files 61

Page 66: Introduction to The OpenGeo Suite

Introduction to The OpenGeo Suite, Release March 18, 2012

62 Chapter 5. Chapter 3: GeoServer

Page 67: Introduction to The OpenGeo Suite

Introduction to The OpenGeo Suite, Release March 18, 2012

5.12. Importing a Directory of Files 63

Page 68: Introduction to The OpenGeo Suite

Introduction to The OpenGeo Suite, Release March 18, 2012

5.13 Importing Data from PostGIS

[[[ re-align this intro with new sections ...

In this section we’re going load several PostGIS tables simultaneously into GeoServer.

We could easily just follow the same steps we used to load our GeoTIFF, for each table in our PostGISstore; however, that would get a little repetitive.

The Suite version of GeoServer ships with an Importer Tool that streamlines the workflow down toa few steps for multiple tables in a database (and multiple Shapefiles in a directory).

Essentially, once pointed at it’s ~target~, the Importer creates a single, common store for the featuresin that target, pulls them in as individual layers, and assigns their properties (Name, SRID, etc) wherepossible from meta-data.

5.13.1 Import From PostGIS Store

1. From the GeoServer Admin page, click on the Import Data link on the left-hand side, under Data.

Figure 5.23: Click this link to go to the Import page

2. Click on PostGIS to select spatial tables from PostGIS as your data type.

64 Chapter 5. Chapter 3: GeoServer

Page 69: Introduction to The OpenGeo Suite

Introduction to The OpenGeo Suite, Release March 18, 2012

Figure 5.24: Import from data source

3. Fill out the following form. Many fields will be left as the default:

5.13. Importing Data from PostGIS 65

Page 70: Introduction to The OpenGeo Suite

Introduction to The OpenGeo Suite, Release March 18, 2012

Figure 5.25: PostGIS data store import parameters.

4. Click Next when you’re ready.

5. This screen asks you to select the layers to import from a list of all of the resources that exist in thestore.

66 Chapter 5. Chapter 3: GeoServer

Page 71: Introduction to The OpenGeo Suite

Introduction to The OpenGeo Suite, Release March 18, 2012

Figure 5.26: Select resources to import from the store.

6. Ensure that ALL layers checkboxes are checked, and click :Import Data.

7. A progress monitor marks the status of the import.

8. When the process is complete, you are redirected to the Import Results page.

Figure 5.27: Import results.

9. If the SRS is not populated automatically, check all of the layers and click Declare SRS.

10. This screen allows you to select the coordinate system that applies to your data.

5.13. Importing Data from PostGIS 67

Page 72: Introduction to The OpenGeo Suite

Introduction to The OpenGeo Suite, Release March 18, 2012

Figure 5.28: Declare SRS.

11. It’s a long list, but we can narrow the results down using the Search field. Enter ‘4326’, and pressenter.

12. The search results are narrowed to a single result: The coordinate system ‘(Geographic) WGS84’that describes our data.

That’s about it! In a consolidated number of steps, you have declared a store, and imported and pub-lished a handful of layers in GeoServer. This is the recommended approach when importing manylayers from PostGIS or a directory of Shapefiles.

Note: The top line of the Import Results page includes a small link to Undo import.

5.13.2 Layer Preview

As a final step to our bulk data load, let’s preview some of what we’ve done.

1. From the list of layers in the Import Results screen, find the countries layer.

Figure 5.29: Layer Preview page

2. Click the OpenLayers link to the right of the countries entry.

3. A new tab will open up in your browser, showing your layer inside an OpenLayers application.

68 Chapter 5. Chapter 3: GeoServer

Page 73: Introduction to The OpenGeo Suite

Introduction to The OpenGeo Suite, Release March 18, 2012

Figure 5.30: Viewing the published layer in OpenLayers

Note: If you’re wondering where the style/color is coming from, this will be discussed in thegeoserver.styling section.

1. Play around with this window. You can use your mouse to zoom and pan, and can also click onthe layer features to display attribute information.

Congratulations, your PostGIS data have been successfully published in GeoServer!

5.14 Other Supported Data Formats

We’ve only touched on two of the data formats that GeoServer supports. Here’s a quick look at someof the other data stores you can publish through GeoServer:

5.14. Other Supported Data Formats 69

Page 74: Introduction to The OpenGeo Suite

Introduction to The OpenGeo Suite, Release March 18, 2012

Figure 5.31: Current list of data stores supported by GeoServer.

5.15 Styling Layers in GeoServer

GeoServer can render geospatial data as images and return them for viewing in a browser. This is whatWMS is all about.

However, geospatial data has no inherent instructions for visualization. Therefore additional informa-tion, in the form of a style, needs to be applied to data for it to be displayed a certain way.

GeoServer uses the Styled Layer Descriptor (SLD) markup language to describe geospatial data.

In this section, we will:

1. Load an SLD file for (most of) our earth layers,

2. Have a quick look at the syntax of SLD, and

3. Apply those styles to our layers.

5.15.1 Loading Styles

1. From the GeoServer menu, click on the Styles link

70 Chapter 5. Chapter 3: GeoServer

Page 75: Introduction to The OpenGeo Suite

Introduction to The OpenGeo Suite, Release March 18, 2012

2. The list of all styles currently defined in GeoServer opens.

3. Find the earth_cities style in your list. Scroll, page and/or sort if you have to.

4. Click the entry to open the SLD Style Editor.

5.15. Styling Layers in GeoServer 71

Page 76: Introduction to The OpenGeo Suite

Introduction to The OpenGeo Suite, Release March 18, 2012

5. Two properties should be pretty evident here:

• The Name of the style,

• What/where the SLD is.

6. Have a look at the layout of the SLD. Without going too deep into the details what do we notice?

• It’s a subset of XML

• There are a few ~standard~ outer tags/attributes

• We do some specific symbology instructions in the middle

• We close up the XML (naturally)

7. This is a very basic SLD that universally renders a square in dark yellow.

8. We could start editing the SLD by hand to change some of this around, but there’s an easier wayto get more.

9. At the bottom of this page, click the Choose File button and locate the file<workshop>\Styles\Cities.sld. Select it and click Open.

10. Now click the Upload ... link.

72 Chapter 5. Chapter 3: GeoServer

Page 77: Introduction to The OpenGeo Suite

Introduction to The OpenGeo Suite, Release March 18, 2012

11. The contents of the SLD editor, are replaced by the contents of the SLD file which contains “farmore elegant” styling instructions than the default.

12. Click the Submit button to save the uploaded SLD into the current style definition.

Note: The updated definition is saved as an SLD file on your local machine in‘‘<user>\.opengeo\data_dir\styles\.

1. Repeat this process for the earth_countries and earth_ocean styles. The source SLDsshould be in your <workshop>\\Styles\\ directory.

2. Preview one/all/some of the layers ... How does it look now?

Now you’ve got style!

5.15. Styling Layers in GeoServer 73

Page 78: Introduction to The OpenGeo Suite

Introduction to The OpenGeo Suite, Release March 18, 2012

5.16 Creating a Layer Group

A layer group, as its name suggests, is a group of layers.

Grouping is useful when creating a “basemap”, or other situations when many single layers are re-quested simultaneously and frequently from a WMS.

Layer groups also let you combine data with different geometries and content.

In the previous sections, we loaded multiple layers from PostGIS. Now we’ll use a layer group to com-bine them into a single ~virtual~ layer.

1. From the geoserver.webadmin page, click on the Layer Groups link, under Data on the left side ofthe page.

Figure 5.32: Click to go to the Layer Groups page

2. Click on Add new layer group at the top of the page.

Figure 5.33: Layer Groups page

3. Enter earth in the Name field. Don’t click Save yet.

74 Chapter 5. Chapter 3: GeoServer

Page 79: Introduction to The OpenGeo Suite

Introduction to The OpenGeo Suite, Release March 18, 2012

Figure 5.34: Creating a new layer group

4. Now we will add layers to our layer group. (Skip the Bounds and other form fields for now).Click on the Add Layer link.

5. Select each of the following layers so that they appear in this order:

• earth:shadedrelief

• earth:ocean

• earth:countries

• earth:cities

Figure 5.35: Adding a layer to the layer group

Note: To make it easier to find the appropriate layers, type in earth in the search box to narrowthe listing.

Layer order in the group definition is important.

The top layer in the list will be drawn first, the bottom last. Make sure to match the order of theabove list.

Reorder the layers if necessary by clicking on the Position arrows for each layer.

5.16. Creating a Layer Group 75

Page 80: Introduction to The OpenGeo Suite

Introduction to The OpenGeo Suite, Release March 18, 2012

6. Check the Default Style box for all four layers.

7. Now, click the Generate Bounds button to determine the bounding box for the entire layer group.This button will also determine the projection of the layer group, equal to the top layer’s projectionby default. If the projection is not found automatically, enter EPSG:4326.

Figure 5.36: Completed layer group

8. Click Save when done.

9. Preview the layer by going to the Layer Preview.

Figure 5.37: Previewing the layer group

5.17 Other protocols

While beyond the scope of this workshop, it is worth noting that GeoServer offers limited support forother protocols in addition to geoserver.overview.wms and geoserver.overview.wfs.

5.17.1 Web Coverage Service (WCS)

The Web Coverage Service is a service that enables access to the underlying raster (or “coverage”) data.

In a sense, WCS is the raster analog to WFS, where you can access the actual raster data stored on aserver.

76 Chapter 5. Chapter 3: GeoServer

Page 81: Introduction to The OpenGeo Suite

Introduction to The OpenGeo Suite, Release March 18, 2012

GeoServer contains full support for WCS versions up to 1.1.1.

For more information on WCS, please see the OGC site on the Web Coverage Service protocol athttp://www.opengeospatial.org/standards/wcs.

5.17.2 Web Processing Service (WPS)

The Web Processing Service (WPS) is a service for publishing geospatial processes, algorithms, andcalculations.

WPS extends the web mapping server to provide geospatial analysis. WPS in GeoServer allows fordirect integration with other GeoServer services and the data catalog. This means that it is possible tocreate processes based on data served in GeoServer, including the results of a process to be stored asa new layer. In this way, WPS acts as a full browser-based geospatial analysis tool, capable of readingand writing data from and to GeoServer.

A much newer development in GeoServer, WPS is available only as an extension. Development contin-ues support for this protocol, though, and eventually support will be added to the standard build.

For more information on WPS, please see the OGC site on the Web Processing Service protocol athttp://www.opengeospatial.org/standards/wps.

5.17.3 REST Interface

GeoServer also has a RESTful API for loading and configuring GeoServer.

With this interface, one can create scripts (via bash, PHP, etc) to batch load any number of files.

Those interested in more information can read the REST section of the GeoServer documentation athttp://docs.geoserver.org/stable/en/user/restconfig/index.html.

5.17. Other protocols 77

Page 82: Introduction to The OpenGeo Suite

Introduction to The OpenGeo Suite, Release March 18, 2012

78 Chapter 5. Chapter 3: GeoServer

Page 83: Introduction to The OpenGeo Suite

CHAPTER 6

Chapter 4: GeoExplorer

6.1 Introducing GeoExplorer

6.1.1 What is GeoExplorer?

GeoExplorer is a browser-based interface for composing and publishing web-mapping applications.

Using the latest version of GeoExplorer you can also style your GeoServer layers and edit the data-sources underneath them - It is replacing the deprecated Styler and GeoEditor Suite components.

In our evolving diagram of the OpenGeo Suite architecture, GeoExplorer sits at the top consuminglayers from our local GeoServer whose data sources include the under-lying PostGIS database and file-system.

79

Page 84: Introduction to The OpenGeo Suite

Introduction to The OpenGeo Suite, Release March 18, 2012

Figure 6.1: GeoExplorer in the OpenGeo Suite stack

6.2 The GeoExplorer Interface

Let’s launch GeoExplorer and have a look at the user interface

1. You can access GeoExplorer directly from this URL http://localhost:8080/geoexplorer, or

2. You can launch GeoExplorer from the list of Components on the Suite Dashboard.

The interface is divided into the following sections:

1. The main Map Panel

2. The Button Bar

3. The Layers Panel

80 Chapter 6. Chapter 4: GeoExplorer

Page 85: Introduction to The OpenGeo Suite

Introduction to The OpenGeo Suite, Release March 18, 2012

Figure 6.2: The GeoExplorer Interface

In upcoming sections, we’ll review specific GeoExplorer tools grouped by the task(s) they are designedto perform.

6.3 Navigation Tools

Navigation tools allow you to zoom in and out, and pan around maps. These tools are located in twoplaces in the GeoExplorer interface:

1. Towards the right of other tools in the Button Bar, and

2. In the corners of the Map Panel

Figure 6.3: GeoExplorer Navigation Tools

Feel free to explore these controls as we review their definitions.

6.3. Navigation Tools 81

Page 86: Introduction to The OpenGeo Suite

Introduction to The OpenGeo Suite, Release March 18, 2012

6.3.1 Before You Click that Button!

There are some useful tips and tricks for map navigation:

• Shift + Drag - Zooms in with any other tool / mode active.

• Control + Drag - Pans the map with any other tool / mode active.

• Mouse-Scroll - Zooms in with a forward scroll, or out with a reverse scroll.

• Double-Click - Centers the map on the click-point and zooms in one level.

6.3.2 Button Bar Navigation Controls

But-ton

Name Description

Pan Map Drag the map with the mouse at the same zoom level.

Zoom-In Zoom-in by one zoom level.

Zoom-Out Zoom-out by one zoom level.

Zoom to previousextent

Zoom to the extent you were previously viewing.

Zoom to nextextent

After using the Zoom to previous extent button, click to zoomto the next extent.

Zoom to visibleextent

Click to view the largest possible area.

6.3.3 On-Map Navigation Controls

Control Name Description

Pan-Step

Pans the map in the direction of the arrow by a set step.

Zoom-Level

Zooms the map in (+) or out (-) by a set level.

Zoom-Slider

Zooms the map in (towards +) or out (towards -) by in asingle mouse ~slide~ (click and drag).

ScaleSelector

Zooms the map to the selected, predefined scale.

6.3.4 Other Tools

There are a few other tools in the Button Bar, that aren’t really ~navigation~ but that don’t really needtheir own page.

82 Chapter 6. Chapter 4: GeoExplorer

Page 87: Introduction to The OpenGeo Suite

Introduction to The OpenGeo Suite, Release March 18, 2012

Button Name Description

(About)GeoExplorer

Click this button to launch an information panel about GeoExplorer.

Feature Info Activate this tool, and then click a point on the map to returninformation about the features at that point.

Measure Activate this tool (in line or polygon mode) and draw a shape on themap alongside a pop-up of it’s length or area.

6.4 Layer Panel and Legend

6.4.1 Layer Panel

The Layer Panel lists each layer currently loaded on the map, and provides both a tool-set and contextmenu for interacting with them.

6.4.2 Layer Types

Layers are organized in two folders: Overlays and Base Layers.

• Overlays include any layer added from the local GeoServer or any other remote, WMS or WFSserver

• Base Layers include any layer added from a known tile-map server (Google, Bing, Yahoo,MapQuest, or OpenStreet Map)

6.4.3 Layer Tools

The Layer Tools are located in a smaller tool-bar at the top of the Layer Panel.

Button Name Description

Add Layer Opens a list of available layers for you to add to your map.

Remove Layer Removes the currently selected layer from your map.

Layer Properties Opens the layer properties dialog.

Edit Styles Opens a GUI-based layer style editor. (Requires Login.)

Note: You might notice that the Edit Styles button is visible but inactive. It is one of several tools thatusers must log in to use. We’ll review these in upcoming sections.

6.4.4 Layer Context Menu

The Layer Context Menu opens when you right-click an item in the Layer list.

6.4. Layer Panel and Legend 83

Page 88: Introduction to The OpenGeo Suite

Introduction to The OpenGeo Suite, Release March 18, 2012

It’s options mirror the Layer Tools (above) with the addition of the Zoom to layer extent option.

As its name implies, this tool zooms the map to the spatial extent of the selected layer.

6.4.5 Map Legend

The Map Legend displays styling information for any Overlay layers that are loaded into the LayerList. Its contents are updated automatically as layers are added, removed or re-styled.

6.5 Start Composing Your Map

Let’s start composing a custom map by adding some layers from our local GeoSever.

1. Click the Add Layer button. The Available Layers dialog opens.

Figure 6.4: Available Layers list

2. By default, the list of Available Layers is tuned to our local GeoSever instance. You should recognizesome of the layer names from previous chapters.

3. Making sure that Local GeoServer is selected in the data source drop-down.

4. Select the earthgroup group layer and the smallworld feature layer that we previously createdin GeoSever, and Add them to the map.

84 Chapter 6. Chapter 4: GeoExplorer

Page 89: Introduction to The OpenGeo Suite

Introduction to The OpenGeo Suite, Release March 18, 2012

Figure 6.5: Available Layers list

Note: Layers can be added individualy by simply double-clicking a row in the list of AvailableLayers. Alternately, you can Shift/Control + Click to select multiple layers, and then click theAdd Layers button at the bottom of the panel.

5. When your layers have been added, close the Available Layers dialog by clicking Done or X.

6. Back on your map, you can re-order your layers by selecting an item, and dragging and droppingit above or below another.

7. Re-order your layers, so they appear as follows:

• smallworld

• earth (group)

That’s not a bad map!

Figure 6.6: Our compiled map.

6.5. Start Composing Your Map 85

Page 90: Introduction to The OpenGeo Suite

Introduction to The OpenGeo Suite, Release March 18, 2012

6.5.1 Bonus

The Available Layers window includes our Local GeoSever and a selection of popular mapping servicesby default. You can add other WMS or WFS services that you know about by following these steps:

1. Click Add (layer) to open the Available Layers window.

2. Click the Add a New Server button.

geoexplorer/gx_addnewserver.png

3. Enter a valid URL to a WMS/WFS end-point, and click the Add Server button.

4. Select your new server’s name in the data source drop-down to list all of the layers available fromthat server that can be added to your map.

6.6 Logging-In to GeoExplorer

Thus far in the workshop, we’ve composed a map using the very layers we stored in PostGIS and thenpublished through GeoServer. I’m pretty excited.

However, if we log in to GeoExplorer, we can do some even more exciting things.

1. Click the Login button on the top right of the Button Bar

2. Enter your Username and Password as shown and click OK. These credentials are the same asfor GeoServer – ‘admin’ / ‘geoserver’, by default.

3. After logging in successfully, you’ll notice that we have a few more items on the Button Bar avail-able to us.

Additionally, if we select one of the Overlays in the Layer List, the Edit Styles button is now availableto us in both the Layer Tools bar and the layer’s context menu.

6.7 Styling Layers in GeoExplorer

We styled our earth vector layers in GeoServer using existing SLD files; however, our smallworldlayer remains stark and unattractive.

In this section we’ll use GeoExplorer’s graphic styling tool to apply cartographic styles to a layer.

86 Chapter 6. Chapter 4: GeoExplorer

Page 91: Introduction to The OpenGeo Suite

Introduction to The OpenGeo Suite, Release March 18, 2012

6.7.1 Interactive Styling

Warning: GeoExplorer makes changes directly to GeoServer SLDs, and will completely overwriteSLD files on the server. It is always a good idea to make a backup copy of your SLDs before usingGeoExplorer for styling.

1. If you aren’t logged in, click the login button and provide your GeoServer administrator creden-tials: admin / geoserver.

2. Select the smallworld layer and then click the Edit Styles button (palette icon).

Figure 6.7: Click to edit styles

3. The Edit Styles dialog opens.

Figure 6.8: Edit Styles dialog

4. In the Styles (upper) panel, click the Add (+) button – The User Style dialog opens.

5. The new style is automatically given a name based on the current layer and a unique identifier.Provide the style with a friendlier Title (Eg. ‘Smallworld Points’) and Abstract (Eg. ‘GeoExploreruser style for Smallworld point features’), and click Save.

6.7. Styling Layers in GeoExplorer 87

Page 92: Introduction to The OpenGeo Suite

Introduction to The OpenGeo Suite, Release March 18, 2012

Figure 6.9: User Style dialog

6. The Edit Styles dialog re-appears, displaying a single untitled style rule for the current layer.

Figure 6.10: Style Rule editor

7. Select this rule, and click Edit – The Style Rule editor opens.

8. Make some Basic changes to the rule.

(a) Give it a new Name.

(b) Change the Symbol type.

(c) Alter the Fill and Stroke (outline) properties.

88 Chapter 6. Chapter 4: GeoExplorer

Page 93: Introduction to The OpenGeo Suite

Introduction to The OpenGeo Suite, Release March 18, 2012

Figure 6.11: Updates to a layer style in GeoExplorer

9. Without closing the Style Rule editor, click the Labels tab. We’ll set our style to display the year ofour visit to each city.

(a) Check the box next to Label Features to enable labelling.

(b) In the expanded dialog, select Year from the Label Values drop-down.

(c) Optionally, experiment with the font, color and halo options for the label style.

6.7. Styling Layers in GeoExplorer 89

Page 94: Introduction to The OpenGeo Suite

Introduction to The OpenGeo Suite, Release March 18, 2012

10. Click Save to persist the SLD changes, and close (X) the Edit Styles dialog.

Now you’ve got style!

Bonus and Discussion

1. Explore the Advanced style rule options.

• Limit by scale

• Limit by condition

90 Chapter 6. Chapter 4: GeoExplorer

Page 95: Introduction to The OpenGeo Suite

Introduction to The OpenGeo Suite, Release March 18, 2012

Figure 6.12: GeoExplorer Advanced style rule options

2. You probably noticed that we can have more that one Rule within a style. How do you think wecould use that?

3. Navigate back to GeoServer, and have a look at the SLD code that GeoExplorer created.

Figure 6.13: SLD code generated by GeoExplorer

6.7. Styling Layers in GeoExplorer 91

Page 96: Introduction to The OpenGeo Suite

Introduction to The OpenGeo Suite, Release March 18, 2012

6.8 Editing Features in GeoExplorer

Two other options enabled when we logged in to GeoExplorer were the layer editing features. Thesepowerful tools allow authenticated users to Create, Edit and Delete features served through GeoServerusing their web-browser.

6.8.1 GeoExplorer Feature Editing Tools

But-ton

Name Description

Create NewFeature

Initiates the workflow to create a new feature in the selected layer.

Edit ExistingFeature

Initiates the workflow to edit and/or delete an existing feature in theselected layer.

6.8.2 Creating New Features

The intention of the smallworld layer is to capture a list of some of the places each of us has visited. Iknow we’ve all been to Denver, so we can leave that one where it is, but there must be more!

Use the following workflow to create points for several other cities you’ve been to.

1. You should be logged into GeoExplorer, and your smallworld layer should be loaded, visibleand selected.

2. Click the Create Feature button to make it active.

3. Navigate the map so that it displays a memorable destination.

92 Chapter 6. Chapter 4: GeoExplorer

Page 97: Introduction to The OpenGeo Suite

Introduction to The OpenGeo Suite, Release March 18, 2012

(Recall that you can Zoom and Pan, with any tool active by using the Shift and Control keys,respectively).

4. Once, you’ve found your destination, click the location on the map. GeoExplorer places a bluemarker on the map at your click point, and opens a small dialog box containing a table of at-tributes.

(Where did that list of attributes come from?)

5. Fill in the Name of the Place, Year visited, and a short Comment (Eg. the purpose of your visit).If you want, while you’re in edit mode, you can adjust your point on the map by dragging thetemporary marker elsewhere.

6. Once you’re satisfied, click Save.

7. Repeat this process for a few more places. Hit some other countries, continents, and hemispheres.Make places up.

6.8. Editing Features in GeoExplorer 93

Page 98: Introduction to The OpenGeo Suite

Introduction to The OpenGeo Suite, Release March 18, 2012

Note: Do you realize what you’ve just done? Yeah ... You’ve added spatial records to a PostGISdatabase table through a browser. Awesome!

6.8.3 Editing an Existing Feature

For the sake of example, let’s zoom into the pre-cooked location for Denver.

Hmmmm ... Something’s not quite right. We’re all here for FOSSGIS, but it’s 2012 not 2211, and thelocation of the point could be a bit closer to where we actually are.

We’ll use the following workflow to edit an existing feature.

1. You should be logged into GeoExplorer, and your smallworld layer should be loaded, visibleand selected. You should be zoomed in to Denver (at zoom-level 10 or thereabouts).

2. If it isn’t already, click the Edit Feature button to make it active.

3. Click on the feature you wish to edit. (Even though there are a few pixels of tolerance, clicking apoint sometimes takes a bit of finess.).

4. A familiar dialog will pop up listing the attributes of the selected feature and highlighting it’sgeometry.

5. Click the Edit button (at the bottom left of the dialog).

6. The pop-up changes to a mode where the field values can be edited.

94 Chapter 6. Chapter 4: GeoExplorer

Page 99: Introduction to The OpenGeo Suite

Introduction to The OpenGeo Suite, Release March 18, 2012

7. Change year to 2011, and move the point marker closer to the city center.

8. Click Save.

Note: Now do you realize what you’ve done? You’ve gone and edited the attributes and geometries offeatures in a spatial database over the web - Nice one!

6.8.4 Deleting Existing Features

Again for the sake of example, let’s assume that at least one of your destinations was bogus.

The steps to delete a feature borrow much from the feature editing workflow.

1. You should be logged into GeoExplorer, and your smallworld layer should be loaded, visibleand selected. You should be zoomed into Denver at zoom-level 10 or thereabouts.

2. Navigate to a point in smallworld that you’ve never been to or are trying to forget about.

3. If it isn’t already, click the Edit Feature button to make it active.

4. Click on the point you wish to delete – The feature edit dialog opens.

5. Next to the Edit button you’ll notice a Delete button that does exactly what it’s name implies.

6. Click the Delete button. This opens a prompt asking for confirmation that you do want to deletethe feature. Click Yes. Just do it.

6.8. Editing Features in GeoExplorer 95

Page 100: Introduction to The OpenGeo Suite

Introduction to The OpenGeo Suite, Release March 18, 2012

Note: Now we’ve round-tripped our in-browser spatial data editing experience!

6.9 Saving Map Layouts

Now that you’ve spent time configuring your map layout (adding, reordering, styling and editing lay-ers, etc.), it might be a good idea to save your layout.

Saving your composed map allows you to come back to the current layout without having to redo allof your work.

In this section, we’ll have a quick look at how to save map layouts, and return to them in anotherbrowser session.

6.9.1 GeoExplorer Save Map Tool

Button Name Description

Save Map Initiates the workflow to save your current map layout.

6.9.2 Create Permalinks to Saved Map Layouts

Note: The workflow for saving and loading maps is (pause for effect) ~transitional~. There isn’t reallya single UI for the process, and there isn’t an easy way to Delete or Copy (~Save As~) saved maps. Weare working on it. We promise.

Saving your map creates a Permalink to the current layout and adds an entry in a server-side databasecapturing the list of layers in your map, their order and their properties (styling, etc). Because of thisinteraction with GeoServer, you must be logged in to access this function.

1. Continuing the previous exercise, you should be logged into GeoExplorer, and working with amap that contains your earth and smallworld layers.

2. The map extent should be set to the area that you want to appear by default when you load yourmap.

96 Chapter 6. Chapter 4: GeoExplorer

Page 101: Introduction to The OpenGeo Suite

Introduction to The OpenGeo Suite, Release March 18, 2012

3. Click the Save Map button to trigger the process.

4. A Bookmark URL dialog opens presenting a Permalink to your saved layout.

5. The Permalink is highlighted in this dialog, so you can quickly Copy and Paste it into any numberof locations (Shortcuts, Documents, Emails, etc.)

6. If you look at your browser’s address bar, you’ll notice that when you hit Save Map the locationchanged to the same Permalink. You have a variety of options for adding this location to yourbrowser’s Favorites folder, Toolbar, Bookmarks, etc.

6.9.3 Loading Saved Map Layouts

Loading a saved map is a matter of opening a saved location in your browser.

1. Return to the default GeoExplorer window at <http://localhost:8080/geoexplorer/>_

6.9. Saving Map Layouts 97

Page 102: Introduction to The OpenGeo Suite

Introduction to The OpenGeo Suite, Release March 18, 2012

2. Access your saved map by clicking the link/shortcut/favorite/etc. you created previously.

3. Your pre-composed layout opens, ready for some more fine-tuning.

Bonus

• With your saved configuation re-loaded and possibly updated, what happens if you click the SaveMap button again? What doesn’t happen?

6.10 Publishing Map Widgets

Sharing links to our saved map configurations is one thing. Sure, other users can view and query datain your composed layouts, but they’re bound to the GeoExplorer interface.

It’s a pretty cool interface, and offers some great tools for editing both maps and layers, but it might notbe for everyone. Maybe it takes up too much room on your page? Maybe it offers too many tools foryour application?

In this section, we’ll use GeoExplorer’s Export Map tool to publish our composed layout as a custommap application that can be embedded on a web page.

6.10.1 GeoExplorer Export Map Tool

But-ton

Name Description

ExportMap

Initiates the workflow to export your current map layout to a customweb-map widget.

98 Chapter 6. Chapter 4: GeoExplorer

Page 103: Introduction to The OpenGeo Suite

Introduction to The OpenGeo Suite, Release March 18, 2012

6.10.2 Export Your Saved Map

Exporting your map to a web page is a quick process.

However, first we need a web page to export our map to.

Thankfully, there is a template HTML file in our <workshop>\HTML directory.

The unadorned template looks a little like this:

Figure 6.14: A sad web page. Without a map, it’s just a bunch of gibberish.

Since we’ll be saving this web page from mapless, hapless boredom, let’s have a quick look at the code.

1. Open the GNN.html file in your text editor.

6.10. Publishing Map Widgets 99

Page 104: Introduction to The OpenGeo Suite

Introduction to The OpenGeo Suite, Release March 18, 2012

Figure 6.15: The HTML page we’ll be editing.

2. Now back to publishing our map. Continuing the previous exercise, you should be logged in toGeoExplorer.

3. Open the map layout you saved previously.

4. Click the Export Map button to trigger the publishing process.

5. The Export Map dialog opens, presenting a list of tools that can be added to the toolbar in yourexported map. By default, all of the tool options are enabled.

100 Chapter 6. Chapter 4: GeoExplorer

Page 105: Introduction to The OpenGeo Suite

Introduction to The OpenGeo Suite, Release March 18, 2012

Figure 6.16: Export Map Step One - Select map tools.

6. If you want, adjust the selection of tools.

7. Once, you’ve selected the tools to include your published map’s toolbar, click the Next button toproceed.

8. This screen provides you with a code snippet to embed your map application into a web-pagetemplate. Copy the code in the <iframe>...</iframe> block to your clipboard.

Figure 6.17: Export Map Step Two - Published map code snippet.

9. Return to your text editor and scroll down to around line 32. Replace the comment shown belowwith GeoExplorer’s HTML block.

<!--Insert your exported HTML code from GeoExplorer here!-->

10. Your HTML file should now look something like this:

6.10. Publishing Map Widgets 101

Page 106: Introduction to The OpenGeo Suite

Introduction to The OpenGeo Suite, Release March 18, 2012

11. Save your HTML file, and return to your browser.

12. Refresh (F5) the page.

102 Chapter 6. Chapter 4: GeoExplorer

Page 107: Introduction to The OpenGeo Suite

Introduction to The OpenGeo Suite, Release March 18, 2012

Figure 6.18: A happy web page.

13. Congratulations, you have published your first map. Go ahead ... Zoom around, be one with yourmap.

How’s the performance? Laggy? In an upcoming section, we’ll look at how to accelerate map deliveryusing GeoWebCache.

6.10.3 Other Publishing Options

Is there anything else you should know?

The two key map export steps are ...

1. Select toolbar options, and

2. Generate the code snippet.

... But we have a few other options when publishing our maps.

Preview

At any time we can click the Preview button to get a glimpse of what our published map applicationwill look like.

1. Click the Preview button.

2. A preview of our mapping application pops-up in a new panel.

6.10. Publishing Map Widgets 103

Page 108: Introduction to The OpenGeo Suite

Introduction to The OpenGeo Suite, Release March 18, 2012

3. Close (X) the preview pop-up.

Dimensions

In the second step, we have controls to specify the dimensions of our map.

1. The Map Size drop-down lists several common map height/width pairs.

2. Alternately, you can enter values in the Height and Width fields directly. Change these values to750 and 650, respectively.

Note: Make sure to tab or click out of the Width field when you’re done.

3. Changing these values updates the code in the <iframe> block with the new map size.

Bonus

Change any of the map options that you’re not happy with. Use the Back and Next buttons to movebetween the ~toolbar~ and ~dimension~ option screens.

104 Chapter 6. Chapter 4: GeoExplorer

Page 109: Introduction to The OpenGeo Suite

Introduction to The OpenGeo Suite, Release March 18, 2012

Republish these changes into your GNN page, and confirm your changes.

6.11 Printing Static Maps

GeoExplorer provides a built-in tool for printing static maps to Adobe PDF format. Where a link to alive map application isn’t appropriate, PDFs maps can be emailed or printed in hard-copy for reference.

In this section we’ll walk you through the steps for printing a static map in GeoExplorer.

6.11.1 Printing Tools

Button Name Description

Print Map Opens a dialog for printing your map to Adobe PDF.

6.11.2 Printing a Map From GeoExplorer

Note: You do not need to be logged in to GeoExplorer to print a static map.

1. We assume GeoExplorer is running and displaying a composed map.

2. Click the Print button. The GeoExplorer Print Preview dialog opens.

3. Select your target Paper Size and image Resolution from the respective drop-downs.

6.11. Printing Static Maps 105

Page 110: Introduction to The OpenGeo Suite

Introduction to The OpenGeo Suite, Release March 18, 2012

4. The text in the upper and lower boxes can be replaced by a Map Title and Map Comments (ornothing).

5. If neccessary, reposition the map image in the map frame using the on-map navigation controls.

6. Click the Print button when you are satisfied with your print layout. This fires a command toGeoServer to generate a PDF and then send it back to the browser.

7. When your map has been prepared, your browser will prompt you to Save or Open (etc) the PDF.

Figure 6.19: A PDF map printed from GeoExplorer.

6.11.3 Layer Permissions

Did you see this pop up when you tried to print your map?

106 Chapter 6. Chapter 4: GeoExplorer

Page 111: Introduction to The OpenGeo Suite

Introduction to The OpenGeo Suite, Release March 18, 2012

This message is telling you that “None of your current map layers can be printed” (OK? OK!).

You’ll typically see this message when your composed map is only displaying a commerical tiles. Termsof use prevent Google, Bing, Yahoo!, etc maps from being printed under most circumstances. Otherwise,if you’ve got at least one overlay layer (or OpenStreetMap), it’ll pring with the commerical layers areignored.

6.12 Uploading Features through GeoExplorer

There’s one other useful feature tucked in behind GeoExplorer’s Login button: The ability to uploaddata to GeoServer on-the-fly when adding layers to a GeoExplorer Map.

6.12.1 GeoExplorer File Upload

GeoExplorer allows you to upload one or more Shapefiles or GeoTIFFs, provided they are packagedinto an archive (ZIP, GZ, TAR, TAR(.BZ2), TGZ, TBZ2).

Single GeoTIF files can actually be uploaded without an archive, however single SHPs cannot.

Recall that SHPs work with at least an associated DBF and SHX file, so these ~associated~ files need tobe packaged up alongside the base SHP.

Conveniently, the file <workshop>\\data\\rivers.zip contains just such a Shapefile ~collection~.

(You can upload this layer to a saved map, or to a brand new one.)

1. You’ll need to be logged in to GeoExplorer to do this. If not already, please launch GeoExplorerand log in now.

2. From the Layer Toolbar, click the Add Layer button.

3. We’ve seen this dialog before, but this time there’s an Upload Data button in the bottom leftcorner.

4. Click Upload Data.

5. Fill in the fields in the Upload Data dialog, as shown.

6.12. Uploading Features through GeoExplorer 107

Page 112: Introduction to The OpenGeo Suite

Introduction to The OpenGeo Suite, Release March 18, 2012

6. When you’re ready, click Upload.

7. The upload progress monitor ~spins~ while your layer is

(a) Uploaded to GeoServer

(b) Unzipped, if archived

(c) Located to the appropriate data-store.

(d) Registered as a layer (in a store, with a workspace)

(If these steps sound familiar, they should. Right?)

8. When your layer has uploaded successfully, it will automatically appear in the list of AvailableLayers ready to be added to your map.

9. Add the layer to your map, and click Done to close the Available Layers dialog.

108 Chapter 6. Chapter 4: GeoExplorer

Page 113: Introduction to The OpenGeo Suite

Introduction to The OpenGeo Suite, Release March 18, 2012

Figure 6.20: Mmmmm ... Rivers.

Bonus & Discussion

• Give your rivers a new, more appropriate style.

• Review the results of your upload in GeoServer (Workspace, Store, Layer, Style, SLD)

• If you uploaded this layer to a PostGIS store, confirm the results of the upload in the database

• Add a new WMS resource to GeoExplorer

6.12. Uploading Features through GeoExplorer 109

Page 114: Introduction to The OpenGeo Suite

Introduction to The OpenGeo Suite, Release March 18, 2012

110 Chapter 6. Chapter 4: GeoExplorer

Page 115: Introduction to The OpenGeo Suite

CHAPTER 7

Chapter 5: GeoWebCache

7.1 Introducing GeoWebCache

7.1.1 What is GeoWebCache?

GeoWebCache is a tool that boosts the performance of a WMS by pre-drawing and saving map imagesfor faster responses to client requests.

In our evolving diagram of the OpenGeo Suite architecture, GeoWebCache sits atop GeoServer’s mapservices brokering map tiles to web-mapping applications in the client tier.

111

Page 116: Introduction to The OpenGeo Suite

Introduction to The OpenGeo Suite, Release March 18, 2012

Figure 7.1: GeoWebCache in the OpenGeo Suite stack

7.2 Caching Concepts

In this section we’ll review three concepts that are pivotal to understanding map caching in general:

• Tile Proxy’ing - How GeoWebCache integrates with GeoServer’s WMS rendering proces.

• Map Tiles - How GeoWebCache saves pre-rendered map images.

• Tiling Strategies - How you can configure the areas are that are cached and when to do so.

7.2.1 Tile Proxy’ing

GeoWebCache acts like a proxy between clients and one or more WMS servers. It sits between theclient requesting the image and the server creating the image. When the client, say OpenLayers, makesa request, GeoWebCache first checks to see whether it already has the corresponding image ...

• If GeoWebCache has the image, it sends it to the client immediately.

• If not, the request is forwarded to the appropriate WMS server (e.g., GeoServer). When the WMSresponse comes back, GeoWebCache saves a copy (caches) and sends it on to the client.

To outline these steps:

112 Chapter 7. Chapter 5: GeoWebCache

Page 117: Introduction to The OpenGeo Suite

Introduction to The OpenGeo Suite, Release March 18, 2012

Figure 7.2: Workflow of the GeoWebCache Server

Simply delivering a cached image is much faster than:

• Polling the data,

• Interpreting styling instructions,

• Drawing the image

And then ...

• Delivering the image

There is an added benefit that this requires fewer resources on the WMS server.

7.2. Caching Concepts 113

Page 118: Introduction to The OpenGeo Suite

Introduction to The OpenGeo Suite, Release March 18, 2012

7.2.2 Map Tiling

Map tiling describes the way images are pre-rendered and saved in the tile-cache.

• Map images are not cached ~whole~. They’re cached as small same-size rectangular image tiles,which combine to form larger maps.

Figure 7.3: Tiling with a Longitude/Latitude Coordinate System

• Map tiles are not just cached at one (fine) resolution. They’re cached at more than one scale so thatusers can zoom in and out of tile levels without resampling.

Note: The cache is stored in your server cache directory. If you’re using the Suite, the cache is saved inGeoServer’s data directory in a folder called gwc.

7.2.3 Tiling Strategies

A Tiling strategy controls when your tiles are created and for what areas (geographic extents) they arecreated. Tile-sets can be created:

• Pro-actively (Seeded)

• On-demand

114 Chapter 7. Chapter 5: GeoWebCache

Page 119: Introduction to The OpenGeo Suite

Introduction to The OpenGeo Suite, Release March 18, 2012

Seeding a Tile-Cache

Seeding pre-creates tiles so that they will already be available when the first users start navigating themap. Because the images exist on the server, there is never any wait-time for the tile to be rendered - itis simply sent immediately to the client.

While pre-seeding is very responsive to the end-user, there are some disadvantages to the administra-tor(s):

• Planning the tile-strategy takes time.

• Creating the tiles takes some computing horse-power (and either scheduling, or parallel installa-tions)

• Storing the tiles takes disk space.

On-Demand Caching

If planning, seeding and storing cached tiles proactively isn’t really your thing, GeoWebCache cancreate map cache tiles “on-demand”.

In this case, the first user/client to navigate to an uncached area will wait while the corresponding tilesare drawn by the server, and then delivered to the browser.

Once rendered, the tiles are added to the service’s cache folder and remain on the server until updatedor deleted by the server administrator.

Subsequent visitors to that same area will not have to wait for the tile(s) to be rendered - Because theyexist, already they’ll just be delivered to their browser.

The main advantage to on-demand caching is that it requires no preprocessing, and because only thedata requested will be cached it can potentially save disk space.

The disadvantage on-demand caching is that because viewing will be slower and then intermittentlyaccelerated it can effect the quality of the user experience.

Which one do I choose?

A combination of both strategies is not uncommon:

• Certain areas will be pre-cached,

• Others (the remainder) will be rendered on-demand.

Some users will pre-cache tiles for heavily visited areas of their map, and create tiles on-demand forrarely visited areas

7.2. Caching Concepts 115

Page 120: Introduction to The OpenGeo Suite

Introduction to The OpenGeo Suite, Release March 18, 2012

Bonus and Discussion

• What happens if the data contributing to a pre-rendred tile changes? How can we get aroundthis?

7.3 Seeding A Tile-Cache

There are two steps in pro-actively seeding a tile cache:

1. Configuring the cache properties, and

2. Creating the tiles

7.3.1 Configuring and Creating Tiles

Let’s set the cache properties of our tiling schema for our earth base map.

1. To start open GeoWebCache

Figure 7.4: Linking to GeoWebCache from the Dashboard*

1. The interface of GeoWebCache lists all configured GeoServer feature types currently being servedby GeoServer. You’ll see our earth layers along with others that ship with the Suite.

116 Chapter 7. Chapter 5: GeoWebCache

Page 121: Introduction to The OpenGeo Suite

Introduction to The OpenGeo Suite, Release March 18, 2012

2. Locate our earth group layer in the list and click the OpenLayers [png] preview

OpenLayers on-demand cache in 4326

3. Get back to the GeoWebCache main page.

4. Locate our earth layer group, and click Seed this layer.

7.3. Seeding A Tile-Cache 117

Page 122: Introduction to The OpenGeo Suite

Introduction to The OpenGeo Suite, Release March 18, 2012

5. On the ~Cache Configuration~ page, we set our tiling schema, including the scale levels, tileboundaries, and image format for our earth cache.

6. Make your values look like these values.

• Number of threads: This should not be set any higher than the number of cores on yourGeoServer machine, so that you don’t bog down the server with too much load. If you’reworking locally, leave the number of threads at 1.

• Type of operation: Set this to Reseed.

– Reseed, generates all the tiles.

– Seed, fills in the gaps where tiles don?t already exist.

– Truncate, empties the cache.

• SRS: You need to choose the SRS into which to render your tiles. EPSG:4326 will do.

• Format: This setting determines what output image format the map service will use when itcreates the tiles. This determines:

– The size on disk of the tiles

– The image quality, and

– The ability to make the tile background transparent.

This can be left as image/png.

• Zoom start: The top zoom level, generally seeding everything from the highest zoom leveldown is a good idea. Leave this at 00.

118 Chapter 7. Chapter 5: GeoWebCache

Page 123: Introduction to The OpenGeo Suite

Introduction to The OpenGeo Suite, Release March 18, 2012

• Zoom stop: The lowest zoom level. The further down you go, the longer the process takes.Leave this at 12.

• Bounding box: As noted previously, you can choose to only pre-create only a a portion ofyour total area. We will seed the entire area, so leave these fields blank.

Your final properties should look like:

• Number of threads: 1

• Type of operation: Reseed

• Grid Set: EPSG:4326

• Format: png

• Zoom Start: 0

• Zoom Stop: 12

• Bounding Box: [empty]

7. The Submit button kicks off the seeding process. Your computer will grind away for a while asthe tiles are generated and placed in the cache directory.

8. Click Refresh List to see the count down for estimated time remaining. When the layer is fullycached, you will be redirected to the properties page.

Great! We’ve successfully seeded our first map.

Further details for how to configure your own tiling schema, including custom projections, can be foundin the GeoWebCache Documentation.

Bonus / Discussion

• Have a look in the cache folder <user>\.opengeo\data_dir\gwc at the directory structure /file names of the cached images.

• Why is everything so systematic?

7.4 Caching On-Demand

We don’t really need to do much to cache tiles on demand. We just need to request map images fromour WMS through the tile-proxy - GeoWebCache takes care of everything else.

In this section we’ll configure a GeoExplorer map to use cached images from GWC over-top of our localWMS, and then compare cached delivery times with full WMS requests, on our GNN web-page.

7.4. Caching On-Demand 119

Page 124: Introduction to The OpenGeo Suite

Introduction to The OpenGeo Suite, Release March 18, 2012

7.4.1 Adding a GWC Server

To publish a cached map, let’s return to GeoExplorer.

1. Make sure you’re logged in and working with a new map

2. Click the Add Layers button in the layers window pane.

3. In the Available Layers panel, click the Add a New Server button.

4. In the URL field, enter the URL of our cached layers:

http://localhost:8080/geoserver/gwc/service/wms

5. Click Add Server, to connect to the GeoWebCache server.

6. A familiar list of layers will display.

• The layers on the Suite GeoWebCache are the configured GeoServer Feature types currentlybeing served by GeoServer.

• This list of layers is identical to both the GeoWebCache configuration page AND theGeoServer WMS layer list.

7. Highlight the layers we added previously from the pure WMS (earthgroup, and smallworld,[rivers?]), click Add Layers and then Done.

120 Chapter 7. Chapter 5: GeoWebCache

Page 125: Introduction to The OpenGeo Suite

Introduction to The OpenGeo Suite, Release March 18, 2012

8. Right-click on the earth group, and select Zoom to Layer Extent.

9. You should see a happy map of the world.

7.4. Caching On-Demand 121

Page 126: Introduction to The OpenGeo Suite

Introduction to The OpenGeo Suite, Release March 18, 2012

10. Click the Export Map icon. The Export Map dialog opens.

11. Select your toolbar items, and then click Next to view HTML block used to embed your map in aweb page.

12. Copy the <iframe> HTML. We will be pasting this text (or something very similar) into ourGNN page:

<iframestyle="border: none;" height="400" width="600"src="http://localhost:8080/geoexplorer/viewer#maps/2">

</iframe>

13. Return to your text editor and scroll down to ~line 32. Above the previous iframe paste thelatest HTML code. You should now have two maps in your GNN page: the first served by Ge-oWebCache, the second served by GeoServer.

122 Chapter 7. Chapter 5: GeoWebCache

Page 127: Introduction to The OpenGeo Suite

Introduction to The OpenGeo Suite, Release March 18, 2012

14. Save your GNN page and refresh your browser.

7.4. Caching On-Demand 123

Page 128: Introduction to The OpenGeo Suite

Introduction to The OpenGeo Suite, Release March 18, 2012

Figure 7.5: An ever happier web page.

15. Get your two maps to roughly the same extent. Zoom and pan the first map. Zoom and pan thesecond map.

• You might notice a rendering delay the first time you request a new area on the map thatuses caching, but that delay won’t happen if you return to the same area.

• This is not the case with the orginal map, where rendering times remain consistently slower.

124 Chapter 7. Chapter 5: GeoWebCache

Page 129: Introduction to The OpenGeo Suite

Introduction to The OpenGeo Suite, Release March 18, 2012

Figure 7.6: Now you’re fast!

Bonus Discussion

• What else can we do to speed up our maps? (HINT, we ~may~ in fact already be doing it.)

Note: GeoWebCache is a very useful tool, but this section but can be omitted or postponed past a shortintroduction if the workshop is running long.

7.4. Caching On-Demand 125

Page 130: Introduction to The OpenGeo Suite

Introduction to The OpenGeo Suite, Release March 18, 2012

126 Chapter 7. Chapter 5: GeoWebCache

Page 131: Introduction to The OpenGeo Suite

CHAPTER 8

Chapter 6: Custom Web-Map Clients

8.1 Introducing OpenLayers and GeoExt

8.1.1 What are OpenLayers and GeoExt?

OpenLayers

OpenLayers is a JavaScript library for building mapping applications in a browser. Mapping applica-tions consist of map layers (raster- or vector-based, integrated from a variety of sources), and controlsfor operating on those layers.

Ext JS

Ext JS is a JavaScript library offering a range of user interface widgets such as grids, trees, menus, andpanels.

127

Page 132: Introduction to The OpenGeo Suite

Introduction to The OpenGeo Suite, Release March 18, 2012

GeoExt

GeoExt combines the geospatial controls of OpenLayers with the user interface components of Ext JSinto a framework that allows you to build rich desktop-style GIS applications for the browser.

Previous Examples

We’ve seen both OpenLayers and GeoExt applications in the preceding sections.

• The GeoServer/GeoWebCache layer preview tools are built using OpenLayers

• Our published map application (and GeoExplorer itself) use GeoExt

In our evolving diagram of the OpenGeo Suite architecture, applications built using OpenLayersand/or GeoExt sit right at the top consuming layers, with/without GeoWebCache, from our localGeoServer.

128 Chapter 8. Chapter 6: Custom Web-Map Clients

Page 133: Introduction to The OpenGeo Suite

Introduction to The OpenGeo Suite, Release March 18, 2012

Figure 8.1: OpenLayers/GeoExt web-mapping applications in the OpenGeo Suite stack

8.2 OpenLayers Tutorial

8.2.1 Creating a Basic OpenLayers Map

In OpenLayers, a map is a collection of data layers and various controls for dealing with user interac-tion.

A map is generated on a web page by four components:

1. Loading Libraries

2. Markup

3. Style Declarations

4. Map Initialization Code

Working Example

Let’s create and preview a simple, fully functional example of an OpenLayers map.

In the next section will go into the details of the code.

1 <html>2 <head>3 <title>OpenLayers Map 1</title>

8.2. OpenLayers Tutorial 129

Page 134: Introduction to The OpenGeo Suite

Introduction to The OpenGeo Suite, Release March 18, 2012

4 <script src="openlayers/OpenLayers.js"></script>5 <link rel="stylesheet" href="openlayers/theme/default/style.css" type="text/css">6 <style>7 #map-id {8 width: 512px;9 height: 256px;

10 }11 </style>12 </head>13 <body>14 <h1>OpenLayers Map 1</h1>15 <div id="map-id"></div>16 <script>17 var map = new OpenLayers.Map("map-id");18 var world = new OpenLayers.Layer.WMS(19 "Earth",20 "http://localhost:8080/geoserver/wms",21 {layers: "earthgroup"}22 );23 map.addLayer(world);24 map.zoomToMaxExtent();25 </script>26 </body>27 </html>

1. Using a basic text editor. Copy the text above into a new file and save it as<user>\.opengeo\data_dir\www\map1.html.

Note: We recommend using Notepad2 as it is a more robust text editor than the standard Win-dows Notepad. We have provided Notepad2 in the <workshop>\\software folder.

2. Open the working map in your web browser by navigating to:http://localhost:8080/geoserver/www/map1.html

Figure 8.2: A basic OpenLayers map

8.2.2 Dissecting Your Map

As mentioned in the previous section, a map is generated by bringing together the necessary:

130 Chapter 8. Chapter 6: Custom Web-Map Clients

Page 135: Introduction to The OpenGeo Suite

Introduction to The OpenGeo Suite, Release March 18, 2012

• Libraries,

• Markup,

• Style declarations, and

• Initialization code.

Using our simple map from the previous section, let’s look at each of these parts in more detail. Themap1.html file should still be open in your text editor.

Library Loading

The header of the document loads necessary JavaScript and CSS files to be included with the map. Inthe <head> element, the OpenLayers JavaScript library is loaded (OpenLayers.js), followed by adefault stylesheet (style.css) that specifies how map-related elements should be styled.

<script src="openlayers/OpenLayers.js"></script><link rel="stylesheet" href="openlayers/theme/default/style.css" type="text/css">

Let’s skip the <style> tag for a moment, and jump down to the <body>.

Markup

The markup for the map generates a single document element:

<div id="map-id"></div>

This element will serve as the container for our map viewport.

Here we use a <div> element, although the container for the viewport can be any block-level element.

We also give the container an id attribute so we can reference it in our code.

Map Style

We’ve already noticed that OpenLayers includes a default stylesheet. However, OpenLayers doesn’tmake any guesses about the size of your map/viewport container.

Because of this, we need to also include at least one style declaration to make room on the page for themap. This is the <style> element in the <head>:

<style>#map-id {

width: 512px;height: 256px;

}</style>

We use the map container’s id value as a selector (#map-id), and then we specify the width (512px)and the height (256px) for the map container.

Note: Although the style declarations are directly included in the <head> of our document. In manycases, your map-related style declarations would be a part of an external stylesheet as part of a largerwebsite theme.

8.2. OpenLayers Tutorial 131

Page 136: Introduction to The OpenGeo Suite

Introduction to The OpenGeo Suite, Release March 18, 2012

Map Initialization Code

The next step in generating your map is to include some initialization code. This is where we determinethe content of our map. In our case, we have included a <script> element at the bottom of ourdocument’s <body> to do the work.

Note: We put the initialization code at the bottom of the <body> of our document, when we couldhave loaded it with the OpenLayers library in the <head>. We did this because our initialization codecannot run until both the OpenLayers library is loaded and the document element that serves as theviewport container (the <div>) is fully loaded. By including the initialization code below this elementin the <body> markup, we ensure that the library is loaded and the viewport container is ready beforegenerating our OpenLayers map.

<script>var map = new OpenLayers.Map("map-id");var world = new OpenLayers.Layer.WMS(

"Earth","http://localhost:8080/geoserver/wms",{layers: "earthgroup"}

);map.addLayer(world);map.zoomToMaxExtent();

</script>

The first line of our script creates a new OpenLayers.Map object, which is known as a constructor:

var map = new OpenLayers.Map("map-id");

This line also tells the map constructor to render the map in the the viewport container, selected by itsid attribute value (map-id).

This constructor (referred to by the JavaScript variable name map) will create the map in the <div>element created above.

Note: The above syntax is a shortcut for convenience. We could be more explicit and provide a directreference to the element (e.g. document.getElementById("map-id")).

The next few lines creates a map layer:

var world = new OpenLayers.Layer.WMS("Earth","/geoserver/wms",{layers: "earthgroup"}

);

Don’t worry about the syntax here if this part is new to you. The important part to understand is thatour map view will be a collection of layers.

Here we have described one layer, a WMS (Web Map Service) layer served from our existing GeoServerinstance, called “earthgroup”, and saved this layer with the variable earth.

The next line adds our one layer to our map.

map.addLayer(world);

The final step is to set the initial geographic limits of the map display, which is known as the extent. Thisspecifies the minimum bounding rectangle of the map area in the form of (Xmin,Ymin,Xmax,Ymax).There are a number of ways to specify this initial extent. In our example, we use a simple request tozoom to map to the maximum extent. By default, this layer’s maximum extent is the entire world ingeographic coordinates, so our map will zoom out all the way.

map.zoomToMaxExtent();

132 Chapter 8. Chapter 6: Custom Web-Map Clients

Page 137: Introduction to The OpenGeo Suite

Introduction to The OpenGeo Suite, Release March 18, 2012

And that’s a very simple map!

Note: It’s easy to get confused by multiple uses of the word “map”. We named our map constructor bythe variable “map” in the first line of our initialization code. If we had used the variable, say, “hello”,our first line of code would have been var hello = new OpenLayers.Map("map-id");, and thisline above would read hello.addLayer(world).

8.2.3 Adding Layers and Controls

By default, all OpenLayers maps come with two default controls. We saw them in our previous exam-ple.

• There is a navigation (or “pan”) tool in the top left corner of the screen, which allows a user topan the map by clicking on direction buttons.

• Below this, there is a Zoom tool, which contains three buttons, one to Zoom In (the up arrow), oneto Zoom Out (the down arrow), and a middle button which is a Zoom To Full Extent button (theglobe icon).

In this section, we’ll extend the template from our previous example with another control for zoomingand panning, another layer, and a control that allows you to toggle layer visibility.

A Starter Map

Let’s start with a slight variation on our template OpenLayers map.

1 <html>2 <head>3 <title>OpenLayers Map 2</title>4 <script src="openlayers/OpenLayers.js"></script>5 <link rel="stylesheet" href="openlayers/theme/default/style.css" type="text/css">6 <style>7 #map-id {8 width: 512px;9 height: 256px;

10 }11 </style>12 </head>13 <body>14 <h1>OpenLayers Map 2</h1>15 <div id="map-id"></div>16 <script>17

18 // MAP OPTIONS //19

20 var map = new OpenLayers.Map("map-id");21 var world = new OpenLayers.Layer.WMS(22 "Earth",23 "/geoserver/wms",24 {layers: "earthgroup"}25 );26 map.addLayer(world);27

28 // OTHER LAYERS //29

30 map.zoomToMaxExtent();31 </script>32 </body>33 </html>

1. Using a basic text editor. Copy the text above into a new file called map2.html, and save it as<user>\.opengeo\data_dir\www\map2.html.

8.2. OpenLayers Tutorial 133

Page 138: Introduction to The OpenGeo Suite

Introduction to The OpenGeo Suite, Release March 18, 2012

This template is nearly identical to our previous map. This version has place holders for codewe’ll add to implement controls (// MAP OPTIONS //) and additional map layers (// OTHERLAYERS //).

2. Verify that the map works by navigating to: http://localhost:8080/geoserver/www/map2.html

Figure 8.3: A basic (but soon to be extended) OpenLayers map

Adding Controls with Options

The PanZoom control is added to OpenLayers maps by default. However, when it is added explicitlyyou can configure an option for the zoom tool to include a slider bar with a ~step~ for each availablezoom level. (Eg. If you have 16 zoom levels, the default, your Zoom tool will have 16 possible positionsfor the slider.)

1. In your working example, add a mapoptions block with the following code:

var mapoptions = {controls:[

new OpenLayers.Control.PanZoomBar(),new OpenLayers.Control.Navigation()

]};

It should be added at around line 17, replacing the placeholder ‘// MAP OPTIONS //’.

2. The next thing we need to do is instruct the map constructor to use these options. Replace theline:

var map = new OpenLayers.Map("map-id");

with

var map = new OpenLayers.Map("map-id", mapoptions);

3. Save the file and reload in the browser.

134 Chapter 8. Chapter 6: Custom Web-Map Clients

Page 139: Introduction to The OpenGeo Suite

Introduction to The OpenGeo Suite, Release March 18, 2012

Figure 8.4: An extended ZoomBar

Note that the zoom bar has too many zoom levels for the size of our small map window. In this case,we could either make our map window larger, by replacing our map style with a large height value,as in:

<style>#map-id {

width: 512px;height: 512px;

}</style>

Or, we could reduce the number of zoom levels in our map, by adding the numZoomLevels propertyto the map options, for example:

var mapoptions = {numZoomLevels: 12,controls:[

new OpenLayers.Control.PanZoomBar(),new OpenLayers.Control.Navigation()

]};

Figure 8.5: An extended ZoomBar with only 12 zoom levels

8.2. OpenLayers Tutorial 135

Page 140: Introduction to The OpenGeo Suite

Introduction to The OpenGeo Suite, Release March 18, 2012

Bonus & Discussion

• Add other layers to your map. You’ll need to include ...

– A variable to hold the layer definition (what type of layer will you add?)

var OSM = new OpenLayers.Layer.OSM();

var gmap = new OpenLayers.Layer.Google("Google",{type:google.maps.MapTypeId.HYBRID});

<script src="http://maps.google.com/maps/api/js?v=3.2&sensor=false"></script>

– The layer object(s) in the list of layers added to the map:

map.addLayers([world, OSM, gmap]);

• Add a control to toggle the visibility of your layers

map.addControl(new OpenLayers.Control.LayerSwitcher());

8.3 GeoExt Tutorial

8.3.1 Creating a GeoExt Floating Map Window

In GeoExt, we use a “web application” paradigm, as opposed to a “web page” paradigm. This meansthat we won’t create extensive markup. The basic ingredients of our map window will be:

• A minimal HTML document including JavaScript and CSS resources

• JavaScript for application initialization

• Configuration objects for the application’s components

Example

Let’s take a look at a fully working example of a GeoExt map window.

1. Copy the code below into your text editor and save it as<user>\.opengeo\data_dir\www\gxmap1.html.

1 <html>2

3 <head>4

5 <script src="ext-3.4.0/adapter/ext/ext-base.js" type="text/javascript"></script>6 <script src="ext-3.4.0/ext-all.js" type="text/javascript"></script>7 <link rel="stylesheet" type="text/css" href="ext-3.4.0/resources/css/ext-all.css"></link>8

9 <script src="openlayers/OpenLayers.js" type="text/javascript"></script>10

11 <script src="geoext/script/GeoExt.js" type="text/javascript"></script>12

13 <script type="text/javascript">14

15 Ext.onReady(function() {16

17 var world = new OpenLayers.Layer.WMS(18 "Global Imagery",19 "/geoserver/wms/",20 {layers: "earthgroup"}

136 Chapter 8. Chapter 6: Custom Web-Map Clients

Page 141: Introduction to The OpenGeo Suite

Introduction to The OpenGeo Suite, Release March 18, 2012

21 );22

23 var mapwin = new Ext.Window({24 title: "GeoExt Map 1",25 width: 600,26 height: 400,27 layout: "fit",28 items: {29 xtype: "gx_mappanel",30 layers: [world]31 }32 });33

34 mapwin.show();35

36 });37

38 </script>39

40 </head>41

42 <body><!-- Oh no you didn’t !!! --></body>43

44 </html>

1. Open this file in your web browser: http://localhost:8080/geoserver/www/gxmap1.html

2. Drag this map window around your browser!

Figure 8.6: A GeoExt MapWindow

8.3.2 Dissecting Your Map Window

As demonstrated in the previous section, a map window is generated by bringing together a minimalHTML document, application initialization code, and configuration objects. We’ll look at each of theseparts of our map in a bit more detail.

8.3. GeoExt Tutorial 137

Page 142: Introduction to The OpenGeo Suite

Introduction to The OpenGeo Suite, Release March 18, 2012

Markup

HTML

Every web application needs at least a basic HTML document as a container. It does not need to containhuman readable markup in this case, so it has an empty <body>.

<body><!-- Oh no you didn’t !!! --></body>

(This case differs from OpenLayers, where a block-level element was required to position the map.)

All of the required script and style resources are loaded in the <head> element ...

Ext JS

First we load Ext JS libraries:

<script src="ext-3.4.0/adapter/ext/ext-base.js" type="text/javascript"></script><script src="ext-3.4.0/ext-all.js" type="text/javascript"></script>

Ext JS can be used as a standalone framework, or together with JavaScript frameworks like JQuery.Depending on this environment, an appropriate adapter has to be loaded first. Since we are using Ext JSstandalone, we use the ext-base.js library. In the second line, we load the main Ext JS ext-all.jslibrary.

Finally, we load the stylesheet required by Ext JS:

<link rel="stylesheet" type="text/css" href="ext-3.4.0/resources/css/ext-all.css" />

This loads all CSS that Ext JS needs to use the default theme. To customize your map application,additional CSS resources can be added.

OpenLayers

GeoExt also requires OpenLayers. So we also have to load the OpenLayers libraries.

<script src="openlayers/lib/OpenLayers.js"></script>

GeoExt

Finally, we can load the GeoExt library that pulls everything together:

<script type="text/javascript" src="geoext/script/GeoExt.js"></script>

Note: When using GeoExt, you also benefit from all the functionality that standalone Ext JS and Open-Layers provide. You can add GeoExt to your existing Ext JS and OpenLayers applications withoutbreaking anything.

Initialization Code

Initialization is done entirely in Javascript and usually consists of two stages:

• initialize the application itself

• initialize the user interface

138 Chapter 8. Chapter 6: Custom Web-Map Clients

Page 143: Introduction to The OpenGeo Suite

Introduction to The OpenGeo Suite, Release March 18, 2012

<script type="text/javascript">

Ext.onReady(function() {

var world = new OpenLayers.Layer.WMS("Global Imagery","/geoserver/wms/",{layers: "earthgroup"}

);

var mapwin = new Ext.Window({

/** Map Window Configuration Object **/

});

mapwin.show();

});

</script>

Initialize the application

To initialize the application, we:

• Define an OpenLayers layer object (based on our local GeoServer earth group layer).

• Create a new Ext.Window saved as as the variable mapwin

Initialize the user interface

To initialize the user interface, we:

• Call the .show() method on the Ext.Window

Configuration Objects

The part of our map application where the map is drawn is contained in the configuration object (seethe comment in the above code).

In Ext JS, you create configuration objects instead of writing code for most basic tasks, which usuallymakes application development easier and faster.

In Ext JS, all constructors take a single argument, which we will be referring to as a “configurationobject”.

Like all JavaScript objects, this configuration object is wrapped in curly braces, and contains key:value pairs. Let’s have a look at the configuration object for our map window:

{title: "GeoExt Map 1",width: 600,height: 400,layout: "fit",items: {

xtype: "gx_mappanel",layers: [world]

}}

8.3. GeoExt Tutorial 139

Page 144: Introduction to The OpenGeo Suite

Introduction to The OpenGeo Suite, Release March 18, 2012

In this code, we set some simple properties, like the title, width and height of our window.

We also set the layout to “fit”, which means that the window will have one item that fills up the entirewindow space.

Since other layouts can position more than just one item, we use an array (square braces) for a list of thewindow’s items – in our case just one: a GeoExt Map Panel.

We configure our GeoExt.MapPanel. To do this, we start a nested object by declaring an xtype of“gx_mappanel”.

The GeoExt.MapPanel configuration takes another property: an array of layers.

For our simple map window example, we just want to show a single WMS layer: world which we’vealready defined with a now familiar syntax.

Note: The following two notations are equivalent:

• new GeoExt.MapPanel({layers: [/* ... */]});

• {xtype: "gx_mappanel", layers: [/* ... */]});

Ext JS keeps a registry of available components, called “xtypes”. GeoExt adds its components to thisregistry. To make them distinguishable from other non-GeoExt components, their names start with the“gx” prefix.

8.3.3 Creating Popups with Feature Info

For our final exercise, we will create a GeoExt map application with:

• A raster basemap and a vector overlay, and

• Pop-ups that display when we click the vector features.

The pop-ups will contain information about those features, directly from their attributes in the under-lying GeoServer feature-store.

Example

1. First open the previous example, gxmap1.html and save it as a new file, called gxmap2.html.Open this new file for editing in a text editor.

2. Add a new WFS layer definition just below our existing WMS layer:

var smallworld = new OpenLayers.Layer.Vector("Small World", {strategies: [new OpenLayers.Strategy.Fixed()],protocol: new OpenLayers.Protocol.WFS({

url: "/geoserver/wfs",featureType: "smallworld",featureNS: "http://geoserver.org/earth"

})});

This creates a vector layer out of our Small World points, served through WFS from our localGeoServer.

3. Add this layer to your GeoExt map panel by updating the layers array in the configuration object:

layers: [world, smallworld]

4. At the bottom of the map initialization code, but before the mapwin.show() call, create a functionfor a GeoExt popup:

140 Chapter 8. Chapter 6: Custom Web-Map Clients

Page 145: Introduction to The OpenGeo Suite

Introduction to The OpenGeo Suite, Release March 18, 2012

var popup;function createPopup(feature) {

popup = new GeoExt.Popup({title: "It’s a Small World",location: feature,width:200,html: feature.attributes.placename + "<br/>" + feature.attributes.comment + "<br/>" + feature.attributes.year + "<br/>",maximizable: true,collapsible: true

});popup.show();

}

5. Below that, we add a function that creates the popup when the smallworld layer is clicked:

smallworld.events.on({featureselected: function(e) {

createPopup(e.feature);}

});

6. Finally, we add the SelectFeature control to our map and activate it

var selectCtrl = new OpenLayers.Control.SelectFeature(smallworld);

var mapPanel;mapPanel = mapwin.items.get(0);mapPanel.map.addControl(selectCtrl);selectCtrl.activate();

7. Save the file, and load it in the browser: http://localhost:8080/geoserver/www/gxmap2.html.Click on a feature to see the pop-up

Figure 8.7: A GeoExt MapWindow with a vector layer plus popup

Your final code-listing might look like this:

1 <html>2

3 <head>

8.3. GeoExt Tutorial 141

Page 146: Introduction to The OpenGeo Suite

Introduction to The OpenGeo Suite, Release March 18, 2012

4

5 <script src="ext-3.4.0/adapter/ext/ext-base.js" type="text/javascript"></script>6 <script src="ext-3.4.0/ext-all.js" type="text/javascript"></script>7 <link rel="stylesheet" type="text/css" href="ext-3.4.0/resources/css/ext-all.css"></link>8

9 <script src="openlayers/OpenLayers.js" type="text/javascript"></script>10

11 <script src="geoext/script/GeoExt.js" type="text/javascript"></script>12

13 <script type="text/javascript">14

15 Ext.onReady(function() {16

17 var world = new OpenLayers.Layer.WMS(18 "Global Imagery",19 "/geoserver/wms/",20 {layers: "earthgroup"}21 );22

23 var smallworld = new OpenLayers.Layer.Vector(24 "Small World", {25 strategies: [new OpenLayers.Strategy.Fixed()],26 protocol: new OpenLayers.Protocol.WFS({27 url: "/geoserver/wfs",28 featureType: "smallworld",29 featureNS: "http://geoserver.org/earth"30 })31 });32

33 var mapwin = new Ext.Window({34 title: "GeoExt Map 1",35 width: 600,36 height: 400,37 layout: "fit",38 items: {39 xtype: "gx_mappanel",40 layers: [world, smallworld]41 }42 });43

44 var popup;45 function createPopup(feature) {46 popup = new GeoExt.Popup({47 title: "It’s a Small World",48 location: feature,49 width:200,50 html: feature.attributes.placename + "<br/>" + feature.attributes.comment + "<br/>" + feature.attributes.year + "<br/>",51 maximizable: true,52 collapsible: true53 });54 popup.show();55 }56

57 smallworld.events.on({58 featureselected: function(e) {59 createPopup(e.feature);60 }61 });62

63 var selectCtrl = new OpenLayers.Control.SelectFeature(smallworld);64

65 var mapPanel;66 mapPanel = mapwin.items.get(0);

142 Chapter 8. Chapter 6: Custom Web-Map Clients

Page 147: Introduction to The OpenGeo Suite

Introduction to The OpenGeo Suite, Release March 18, 2012

67 mapPanel.map.addControl(selectCtrl);68 selectCtrl.activate();69

70 mapwin.show();71

72 });73

74 </script>75

76 </head>77

78 <body><!-- Oh no you didn’t !!! --></body>79

80 </html>

8.3. GeoExt Tutorial 143

Page 148: Introduction to The OpenGeo Suite

Introduction to The OpenGeo Suite, Release March 18, 2012

144 Chapter 8. Chapter 6: Custom Web-Map Clients

Page 149: Introduction to The OpenGeo Suite

CHAPTER 9

Getting Support for the OpenGeoSuite

9.1 Two Types of Support

• The Open Source “Business Model”

• Community Support

• Enterprise Support

9.2 Community Support

9.2.1 Project Pages

• http://postgis.org/

• http://geoserver.org/

• http://geowebcache.org/

• http://openlayers.org

• http://geoext.org

9.2.2 Users Lists

• http://postgis.org/pipermail/postgis-users/

• https://lists.sourceforge.net/lists/listinfo/geoserver-users

• https://lists.sourceforge.net/lists/listinfo/geowebcache-users

• http://lists.osgeo.org/mailman/listinfo/openlayers-users/

• http://www.geoext.org/cgi-bin/mailman/listinfo/users

9.2.3 Developers Lists

• http://postgis.org/pipermail/postgis-devel/

• https://lists.sourceforge.net/lists/listinfo/geoserver-devel

145

Page 150: Introduction to The OpenGeo Suite

Introduction to The OpenGeo Suite, Release March 18, 2012

• http://sourceforge.net/mailarchive/forum.php?forum_name=geowebcache-devel

• http://lists.osgeo.org/mailman/listinfo/openlayers-dev/

• http://www.geoext.org/cgi-bin/mailman/listinfo/dev

9.2.4 The Suite

• You did see the documenation available through the dashboard, right?

• Other workshops and talks ...

• Online ...

9.2.5 OpenGeo.Org

• Our business is supporting folks deploying open source, particularly deploying Enterprise appli-cations built on the Suite.

• http://opengeo.org/

• The Suite is also available in a community edition, backed by community/expert support

• http://getsatisfaction.com/opengeo

9.3 Enterprise Support

http://opengeosuite.com/

146 Chapter 9. Getting Support for the OpenGeo Suite