Changing the Projection

Introduction

GeoMOOSE 2 uses the Proj4js library to perform all of its projection work. This is much more robust than the older GeoMOOSE reprojection library but requires a different setup to use different projections within the application.

Projections are defined using the standard Proj4 syntax which configures the datum, origin, and units for the projection among other parameters. Most applications will use a well-known projection that is assigned a unique identifier, or “EPSG code”. The Spatial Reference website contains a listing of valid EPSG codes and definitions in various formats. The Proj4 C library also includes the full list of EPSG definitions. This list can be found in the file proj/nad/epsg included with MS4W.

Proj4js does not include the full list of definitions by default, though it can dynamically load definitions directly from the Spatial Reference website. However, it is recommended that you explicitly create an EPSG code definition file for your projection in order to use it in your map.

Step 1: Determine your projection.

First check to see if your projection already exists as an EPSG definition. Having a predetermined projection makes this step quick and easy. Note that the same basic projection may have multiple variants with differing EPSG codes. For example, UTM 15N is defined as EPSG:26915 when based on the NAD83 datum, but as EPSG:32615 when based on the WGS 84 datum. Most commercial map layers use a projection commonly known as Web or Spherical Mercator, which now has the standard code EPSG:3857. The GeoMoose demo is configured to use EPSG:3857 by default.

If your projection is not found in the standard list, you will need to define your own. For example, an arbitrary projection might be defined as:

+proj=tmerc +lat_0=38 +lon_0=125 +k=1 +x_0=200000 +y_0=500000 +ellps=bessel +units=m +no_defs

The projection definition must be placed within a JavaScript file as described below.

Step 2: Create a Projection Javascript File.

Projection files should be placed in the htdocs/projections directory and follow the naming convention EPSGXXXXX.js where “XXXXX” is the projection code. If you created a custom projection in step one be sure to make this a number above 100000. In side of this file you should have:

Proj4js.defs["EPSG:XXXXX"] = "+proj=tmerc +lat_0=38 +lon_0=125 +k=1 +x_0=200000 +y_0=500000 +ellps=bessel +units=m +no_defs";

Again, substitute your own EPSG number and projection information above. The Spatial Reference website provides Proj4js format files for well known projections. After searching for and finding a projection you will have the option to export the projection in Proj4js format. Simply copy and paste the code into your EPSGXXXXX.js file.

Include the Javascript File in your HTML

Find the section in the <head> of geomoose.html that states, “Include your projection here” and place the code:

<script type=”text/javascript” src=”projections/EPSGXXXXX.js”></script>

Step 3: Ensure your data sources support your projection

This step will depend on your data sources and target projection. If your data source does not support your projection you will usually need to reproject it. Coordinates and vector layers (e.g. WFS) can generally be reprojected from within the web browser as long as both Proj4js definitions are provided. Raster layers (e.g. WMS) can often be reprojected using MapServer. In the case of the demo it is as simple as adding the EPSG code to the ows_srs parameter in basemap.map, parcels.map, lmic.map, and usgs.map:

WEB
        METADATA
                'ows_title' 'County'
                'ows_srs' [...] EPSG:3857 EPSG:XXXXX'
                'ows_enable_request' '*'
        END
END
PROJECTION
        'init=epsg:26915'
END

The initial projection should remain as whatever the source data is in (EPSG:26915 in this case).

Note

Commercial map layers (like Bing, Google, and MapQuest) generally do not support reprojection, so you will not be able to easily use them with any map projection other than EPSG:3857 (or the unofficial equivalent EPSG:900913).

Step 4: Change the mapbook parameter for your projection.

In the <configuration> section of the mapbook you will need to change the following line:

<param name=”projection”>EPSG:XXXXX</param>

If you are changing the projection for an existing map (such as the demo), you will almost certainly need to change the max_extent and initial_extent parameters or the entire map may be shifted far off-screen. Essentially you will need to reproject the extent coordinates from the old projection into the new. One way to do approximate this from within GeoMOOSE is by panning and zooming until your data is back in view, then recording the X,Y coordinates at the bottom left and top right of the region. This task will be much simpler if you are able to use a worldwide map layer that supports your target projection. The ArcGIS REST example in the demo supports a wide range of projections and can be useful for this purpose.

For example, after changing the demo to Minnesota state plane South (EPSG:26993) you would want to change the initial_extent to something like:

<param name="initial_extent">2169678,512220,2268587,618926</param>

For more information on finding projections and projection definition strings visit http://www.spatialreference.org.