(Adding this to give some documentation about how I added the shapefile layer for future reference)
The shapefile we started with, Planting_Years_1980-2070.shp, had a corresponding MapServer file, green_wt.map. However, this shapefile was in WGS84 (EPSG:4326) and the DSS is in spherical mercator (EPSG:3857), so it wouldn't show up on the DSS maps in that format.
To get the shapefile in the correct projection, the GDAL function ogr2ogr was used:
The .map file also had to be modified. The PROJECTION field was changed from "proj=latlong" to "init=epsg:3857" for both the file and the individual layers.
With that done, the shapefile could be added to the OpenLayers v3 maps using this code:
In addition to displaying the data on the map, we wanted to retrieve the value from a clicked point. This can be done with WMS GetFeatureInfo requests.
First, a few other lines had to be added to the new .map file:
LAYER
...
TEMPLATE "layers/query_layer.html"
METADATA
"wms_include_items" "all"
"wms_exclude_items" ""
END #METADATA
...
END
The template is simply an HTML file. Listing this in the .map file apparently specifies that the shapefile is queryable.
Finally, the GetFeatureInfo request can be used to retrieve data from a clicked point. This can be done using a bit of OpenLayers code, or with a URL string request:
By changing the file name or layer in the URL and parsing through the output, data from clicked points can be quickly retrieved in lieu of using something like an OPenDAP call or a MySQL lookup.
(Adding this to give some documentation about how I added the shapefile layer for future reference)
The shapefile we started with, Planting_Years_1980-2070.shp, had a corresponding MapServer file, green_wt.map. However, this shapefile was in WGS84 (EPSG:4326) and the DSS is in spherical mercator (EPSG:3857), so it wouldn't show up on the DSS maps in that format.
To get the shapefile in the correct projection, the GDAL function
ogr2ogr
was used:The .map file also had to be modified. The PROJECTION field was changed from
"proj=latlong"
to"init=epsg:3857"
for both the file and the individual layers.With that done, the shapefile could be added to the OpenLayers v3 maps using this code:
In addition to displaying the data on the map, we wanted to retrieve the value from a clicked point. This can be done with WMS GetFeatureInfo requests.
First, a few other lines had to be added to the new .map file:
The template is simply an HTML file. Listing this in the .map file apparently specifies that the shapefile is queryable.
Finally, the GetFeatureInfo request can be used to retrieve data from a clicked point. This can be done using a bit of OpenLayers code, or with a URL string request:
In this case, the
&I=
and&J=
parameters specify which point was clicked.The output looks like this:
By changing the file name or layer in the URL and parsing through the output, data from clicked points can be quickly retrieved in lieu of using something like an OPenDAP call or a MySQL lookup.