Geoserver installation
This guide assumes you have access to shapefile map data that you would like to use with GpsGate Server and VehicleTracker. Besides GpsGate Server we will use GeoServer and OpenLayers, both of which are free and open source.
1. Verify that you have the required Shapefile data
A shapefile is a set of several files. Apart from the file with the .shp extension, .shx and .dbffiles are also necessary to form the mandatory triplet that defines a shapefile. You might also have a mix of other optional files that describe projection, geocoding, etc. GeoServer will automatically handle any optional files.
Typical map data is split into several layers of shape files. In this guide we’ll assume a typical case of three layers:
- polygon.(shp/shx/dbf) = country, coast line.
- line.(shp/shx/dbf) = roads, rivers.
- poi.(shp/shx/dbf) = Point-of-interest. I.e customers, hospitals, pubs, and other important places.
2. Install GeoServer
Download the GeoServer installer here. Note that this blog post was first written for GeoServer version 2.0.2 and has since been updated to version 2.24.2. The UI may have changed slightly but is virtually the same as when the original screenshots were taken.
In my experience on Windows, the installation was very smooth, a simple wizard installer.
When asked about the “Type of Installation” you’ll most likely want to select “Run as Service” for a production setup.
Apart from the actual map data storage and bandwidth usage, please note that GeoServer will also consume memory and CPU resources, so place it on a machine with cycles to spare. By default, the map data will be located under the installation directory but you can also specify the data directory location separately.
In this guide, we’ll assume the default directory.
3. Copy your shape file data to the GeoServer data store
By default the map data directory is located in C:/ [ProgramFiles]/GeoServer/
Create a new sub-directory (for example “MyNewMap”) and copy all of your shapefiles there.
4. Log in to GeoServer
Start your favorite web browser and go to the GeoServer login page. The default URL is http://www.yourserver.com:8080/geoserver/web/ but it’s also available as a “GeoServer Web Admin Page” link in the Windows’ start menu.
See GeoServer’s quickstart guide on how to set up user accounts, log in, etc. In this tutorial we require only the default settings and default user, thus you don’t need to change anything.
When you have logged in the left-hand side of the interface contains the menu with the main functionalities. In the rest of this guide, we’ll reference a certain menu by saying: Root Menu->Directory->Function, ex: Data->Syles->Add new Style.
In particular, all menus needed in this guide happen to be located in the “Data” group.
Now we’re ready to start creating the actual map.
5. Create a workspace
Workspaces are used as a logical grouping of your data. You typically create workspaces based on your company name and/or per project.
Go to: Data->Workspaces->Add new workspace to create a new workspace.
Here we choose the name “MyCompany”.
Press the “Submit” button.
6. Import your shapefiles
Now we can import the shapefiles into GeoServer’s data store. The easiest is to import the entire directory of shapefiles in one go, though you can also import individual files.
Go to: Data->Stores->Add new Store.
Select “Directory of spatial files"
Select your workspace, in this case, “MyCompany”, and then give your data a name. Here we choose “MyNewMap”.
Point to your shapefile data on the disk
In “Connection Parameters” you set the URL to file:data/MyNewMap, where “MyNewMap” refers to the directory where you placed your map data files in step 3.
Press the “Save” button.
7. Create map layers
Now we need to turn the raw shape data into map layers.
Go to: Data->Layers->Add a new resource to create a new layer.
Choose your data store in the drop-down list. In this example, it will be “MyCompany:MyNewMap”.
Now you should see the available layers corresponding to your shapefiles.
Next, the layers need to be configured and “published”. Click “Publish” on the right-hand side.
7.1 Specify Coordinate Reference Systems, SRS
Click “Find” to see if the coordinate system is already included in your data files. Otherwise, the most common coordinate system is probably EPSG:4326 (Same as WGS84)
Add it manually in that case by typing “EPSG:4326” in the “Declared SRS” field.
7.2 Specify Bounding Boxes
Bounding Boxes describe the extent of your map (since your map most likely doesn’t cover the entire globe).
The easiest is to click “Compute from data” and “Compute from native bounds” respectively to generate bounding boxes (if you don’t have any particular reasons for custom settings).
Press the “Save” button.
! Repeat the above steps (from “Publish”) for all your layers!
When you’re done you should be able to see your layers in the list something like this:
8. Style your layers
Now you need to specify the look of your layers, coloring, width of different roads, etc.
Go to the layer (as in step 7) and select the “Publishing” tab at the top.
Under “WMS Settings”, choose for example one of the default styles in the drop-down menu.
Tip: Consult your “web-page-guy” if you need more advanced styling.
Press the “Save” button.
! Repeat this step for the remaining layers!
Note: The map background color can for some reason not be configured here, it is instead specified in the OpenLayers setup (more about this in step 11).
Note: This styling will be the default for the layer, but you can also associate a separate style with your layer when creating the “Layer group” in the next step.
9. Group your layers into a map
Now we need to specify that our layers are intended to be grouped into a map.
Go to: Data -> Layer Groups -> Add new layer group to create a new group. Here we call it “MyNewMap”.
Add your layers to the group
Click “Add Layer” and select each of your layers.
When you’ve added all your layers click “Generate Bounds” (the bounds will be the union of the individual layers’ bounds as we set in step 7).
Verify the order of the layers
Here we indicate which visible order our layers shall have.
The bottom layer will be first in the list, the next layer will end up above (covering the previous).
In our example case, this means the correct order should be:
- polygon (ground).
- line (roads).
- poi (customers).
Click the green up/down-arrows on each layer to change the ordering.
Press the “Save” button.
10. Verify the map looks ok in the Demo/preview
.. Almost done!
Go to: Layer Preview (at the bottom in the left-hand menu).
Here you should now be able to see your separate layers, “MyCompany:line”, “MyCompany:poi”, “MyCompany:polygon” and most importantly the resulting map: “MyNewMap”
Now simply click “OpenLayers” to see the result of your hard work!
If the map doesn’t look the way you like you need to go back and tune the styling (in Data->Styles). Needless to say, if the map doesn’t show correctly here, it won’t show correctly in VehicleTracker either!
Keep this preview window open, it is needed in the next step.
11. Install the GpsGate Server plugins CoreMap and GeoServer to load your map
We can now start the final phase of importing the map to GpsGate Server and VehicleTracker using OpenLayers map plugins.
From SiteAdmin -> Plugins -> Get More Plugins, first install CoreMap, and then install the plugin named GeoServer.
You can now configure a GeoServer map in GpsGate from the SiteAdmin -> Maps -> GeoServer page.
On that page, you can configure settings such as WMS URL, background color, maxResolution (affects map scale), and other settings that should be specifically tuned for the group layer that you have created in GeoServer.
Fortunately, you can find suitable values for these settings by previewing your layer from the GeoServer Web Admin page. Go to Layer Preview (as in step 10) in the GeoServer Web Admin page and select your “MyNewMap”, then select “view source” in your web browser.
Here’s an example snippet of the relevant parts of the preview source code you should see.
(should start at about line #130 in the “view source” window).
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
|
.... var options = {
controls: [],
maxExtent: bounds,
maxResolution: 0.01869921875, // (1)
projection: "EPSG:4326" , // (2)
units: 'degrees'
}; var map = new OpenLayers.Map( 'map' , options);
// setup tiled layer var tiled = new OpenLayers.Layer.WMS(
"Geoserver layers - Tiled" , "http://yourserver.com/geoserver/MyCompany/wms" , // (3) url will point to your GeoServer
{
height: '123' ,
width: '123' ,
layers: 'MyNewMap' , // (4)
styles: '' ,
srs: 'EPSG:4326' ,
format: format,
tiled: 'true' ,
bgColor: '0xECD0D5' , // (5) background color in 0xRRGGBB format
tilesOrigin : map.maxExtent.left + ',' + map.maxExtent.bottom
},
{
buffer: 0,
displayOutsideMaxExtent: true
}
); .... |
You can read more about OpenLayers’ WMS layer settings here.
11.1 Create a Map in GpsGate SiteAdmin by copying map settings from GeoServer
Now we must create a GeoServer map in GpsGate SiteAdmin by copying the necessary map parameters from this GeoServer example map.
- Go to SiteAdmin -> Maps -> GeoServer
- Click “Create New”
- Look for the relevant settings indicated in the snippet above with (1), (2), etc.
- Enter the value into the corresponding input field in the SiteAdmin form.
- When you’re done, click Save.
Finally, to enable the GeoServer map for an application go to Site Admin › Applications › Manage Applications - click the application.
2. Navigate to the Maps and Geocoders where you select the GeoServer map
3. Click “Save”
13. Finished!
Fire up VehicleTracker, go to the “Maps” menu, and select “GeoServer”. Voilà - you can now get started tracking on your very own brand-new map!
Note that if you configure many GeoServer maps you can select one of them by clicking the blue and white plus sign in the upper-right edge of the map view.