Thursday, 26 August 2010

Today I read that Spring-JPA is the 'dream team' for POJO development. So I thought I'd see what all the hype is about. Here is a skeleton Maven project using Spring, JPA implemented with Hibernate and backed with an embedded Derby database.

A much neater alternative is to use a JPA style controller which gives you direct access to the EntityManager. The @PersistenceContext annotation is understood by Spring and your entity manager is injected into the controller class.

Don't Believe The Hype

So basically, for me anyway, using Spring in conjunction with JPA gives you nothing above and beyond using JPA directly. By the the time you decide not to bother with JpaDaoSupport, all that has been achieved is moving connection properties form persistence.xml to context.xml, which just creates more Spring configuration XML clutter.

Spring recognising the @PersistenceContext is a nice touch for testing, but using constructor/setter injection to inject an EntityManager into a JPA controller class is no big deal if you don't want to use spring.

For this post I'll only be using data on disc 1/6 and 3/6 on the OS Street View discs.

Getting GeoServer

GeoServer stable release can be downloaded here. I punted for the binary download format, because I want to run GeoServer on Linux. After unzipping and starting GeoServer, you should be able to browse to http://localhost:8080/geoserver/web/ and log in using the default username/password:

admin/geoserver

Using the Street View Rasters

First we need to decide what set of tiles we want to use. I only want maps for York and the surrounding area, so using the grid map:

I can see I only want to use the SE data.

Disc 3 of the OS Street View set contains the tif image files I want, located in the directory:

data/se

The files need to be coppied to a location in GeoServers data directory tree. I coppied the images to:

geoserver-2.0.2/data_dir/data/OpenData/StreetView/se

The image files aren't GeoTIFFs, so need geo-referencing data not contained in the image file. This information is held on the disc 1 of the OS Street View set, in the directory:

data/georeferencing files/TFW

We only need the files which start with se, and these need to be copied along side the images in the data directory:

geoserver-2.0.2/data_dir/data/OpenData/StreetView/se

We also need to make sure that the file extension of the tfw is lower cased, using a Linux shell:

rename .TFW .tfw *.TFW

We should now have a directory containing .tif image files and .tfwworld files. Each of the tif/tfw pairs needs a file containing projection information before it can be loaded into GeoServer. The files aren't supplied with the raster data, but they are simple to create. The name of the file must match the name of the tif/tfw, and each of the files must contain the same data:

If you have a data directory with files that look a bit like this, then you're ready to load them into GeoServer:

Load GeoServer up in a browser http://localhost:8080/geoserver/web/ and login. Click the 'Workspaces' link in the 'Data' section of the left hand navigation bar. Now click the 'Add new workspace' link.

Name the workspace OpenData and give it the URI https://www.ordnancesurvey.co.uk/, and click save.

Click the 'Stores' link in the 'Data' section of the left hand navigation bar. Now click the 'Add new Store' link. Under the 'Raster Data Sources' heading, click the 'ImageMosaic' link.

Select the OpenData workspace, name the data source OS Street View SE and point the URL connection parameter to the data directory:

file:data/OpenData/StreetView/se

and then click save.

You should be forwarded to the 'New Layer chooser page', click the 'Publish' link next to the 'se' layer in the table.

About halfway down the page there should be inputs for 'Native SRS' and 'Declared SRS', make sure they both contain:

EPSG:27700

and click the 'Compute from data' and 'Compute from native bounds' links.

Finally click save.

If all went well you should be able to use GeoServers 'Layer Preview' built in OpenLayers client to view the map: