Projections
Introduction
ESPG codes uniquely define every projection available and are used by the SolarFarmer scripting to avoid ambiguity. Find your ESPG codes here: http://spatialreference.org/ref/epsg/.
Another option for defining projection is the Global Mapper .prj file which contains "Well Known Text" that describes a projection.
Load a projection from a *.prj file
var projection = Toolbox.LoadProjectionFromFile(@"C:\TestData\BritishGrid.prj");
Create a projection from its EPSG code
var projection = Toolbox.GetProjectionFromEpsgCode(2805);
Set or redefine the global projection
var projection = Toolbox.GetProjectionFromEpsgCode(2805);
// Set or redefine the workbook's projection
Toolbox.RedefineWorkbookProjection(projection);
Reproject point
You can reproject a point from one projection to another.
Here's an example of projecting a point in latitude/longitude (EPSG code 4236) to the workbook's projection:
// Define the input and output projections
var wgs84Projection = Toolbox.GetProjectionFromEpsgCode(4326);
var workbookProjection = Workbook.Domain.Geography.WorkbookProjection;
// The location (in latitude/longitude) to reproject
Location stonehengeInLatLon = new Location(-1.826168, 51.178854);
// Reproject the point
var stonehengeInWorkbook = Toolbox.ReprojectPoint(
stonehengeInLatLon,
wgs84Projection,
workbookProjection);
// Print out the result
Toolbox.Log(string.Format("Location in latitude/longitude: {0}, {1}",
stonehengeInLatLon.Y,
stonehengeInLatLon.X));
Toolbox.Log(string.Format("Location in workbook projection (X, Y): {0}, {1}",
stonehengeInWorkbook.X,
stonehengeInWorkbook.Y));
The above script, assuming your workbook projection was UTM Zone 30 (where Stonehenge is located!) would print out:
Location in latitude/longitude: 51.178854, -1.826168
Location in workbook projection (X, Y): 582049.024907241, 5670369.2988251