Lab 12: Geoserver: Take 2 4/10/2014

Name:______

In this lab, you will learn how to use Geoserver to create WMS layers and then load them into your rpi Leaflet map. You will first prepare a choropleth map showing road density for Census Tracts in the RPI area. The (very handy) pre-summarized census tract data was downloaded from this site: https://www.census.gov/geo/maps-data/data/tiger-data.html and then clipped to the bounding box of the rpi_roads.shp.

Part 1: Preparing the Data

Task / How you did it:
Download and extract the data for today, and load the 2 shapefiles into either QGIS for analysis:
·  rpi_census_tracts_clip.shp
·  rpi_roads.shp
Look at the attribute table of rpi_census_tracts_clip. What do the field names mean?
Open the DP_TableDescriptions.xls file included in your data folder. This should tell you what the descriptions mean.
Calculate the area in square kilometers for each tract.
Sum the length of roads (km) within each tract.
Calculate the density of roads (km roads/km2) within each tract
Make a choropleth map showing road density within each census tract.

Part 2: Geoserver-QGIS interface

Task
Open QGIS and install the ‘OpenGeo Explorer’ Plugin.
Hint: directions for how to do this are found here:
http://qgis.boundlessgeo.com/static/docs/intro.html
Open the OpenGeo Explorer Settings and make sure ‘keep a list of previous catalog connections’ is checked.
Open the OpenGeo Explorer plugin and add a ‘New Geoserver Catalog’ using these connection parameters:
Catalog Name: http://frontierspatial.com:8082/geoserver
URL: http://frontierspatial.com:8082/geoserver
User name: rpi
Password: rpi101
Geonode Connection Parameters: http://frontierspatial.com:8082/geoserver
Look for your choropleth road density layer in QGIS ProjectàQGIS Layers branch of the OpenGeo Explorer catalog tree. Right click on the layer and select ‘Publish to Geoserver’. Make sure to select your personal workspace.
If this succeeds, you should see your layer appear in the ‘Geoserver Layers’ branch of the OpenGeo Explorer catalog.
You should also find a new style under ‘Geoserver Styles’. Right-click on this and select ‘Edit SLD’. This is the code that symbolizes the layer in Geoserver. You can either edit this directly, or right-clickàEdit to use the QGIS syle GUI to modify the style.

Part 3: Geoserver web interface

Task
Go to http://frontierspatial.com:8082/geoserver and log in using username= rpi, password=rpi101
Click on ‘Layer Preview’ and preview your layer in OpenLayers and KML (if you have Google Earth installed). What do you see?
Take note of the ‘Name’ of your layer—you will use this when adding your WMS layer to your leaflet map. The ‘Name’ takes the form of workspace:layer.

Part 4: Adding Your new Geoserver WMS layers to a Leaflet map.

Task
Download the ‘giscience_leaflet_template_rpi’ folder into your webserver (e.g. Apache/www)
Open the localhost:8080/giscience_leaflet_template_rpi/rpi.html file in your browser. What is different about this map then the NYC map template?
Open giscience_leaflet_template_rpi/rpi.html in Sublime Text and add this code, but REPLACE THE HIGHLIGHTED CODE, substituting the name of your workspace instead of ‘giscience’ and your layer name instead of ’rpi_tracts’
:
var rpi_tracts = new L.TileLayer.WMS("http://frontierspatial.com:8082/geoserver/giscience/wms", {
layers: 'giscience:rpi_tracts',
format: 'image/png',
transparent: true
});
Remember to add an entry for your layer to the layer control
Optional: Add a legend to your leaflet layer control:
1)  Use the Snipping tool or screen capture to make a .jpg or .png image of your legend in QGIS.
2)  Save this to your /img folder.
3)  Use code like this when adding the layer to the layer control:
var overlays = {
"Class": classroster,
"Road Density By Tract</brimg src='img/rpr_tracts.png'</img>": rpi_tracts
};

Now try creating other GeoServer layers, e.g. for your group project, and adding them to your Leaflet map.