Coordinate Conversion Library in MS
Coordinate Conversion Library in MS
MS Excel
Contact Phil Scadden
Price: $199 for individual user. $1500 for a site license. Exclusive of GST.
The functions provided are available in both Excel and Access, as Add-ins. The code and
functionality are the same.
SETTING UP TO USE..........................................................................................................1
THE FUNCTIONS. ...............................................................................................................2
TRUNCATED COORDINATE HANDLING: .................................................................................. 2
NZMGTruncE(mapsheet, teast, level)............................................................................................ 2
NZMGTruncN(mapsheet, tnorth, level). ......................................................................................... 2
Coord2Trunc(Coord, level). ............................................................................................................ 2
Mapsheet(east, north) .................................................................................................................... 2
NZMS1TruncE(mapsheet, teast, level). ......................................................................................... 2
NZMS1TruncN(mapsheet, tnorth, level)......................................................................................... 2
TruncYardNZE(mapsheet, teast, tnorth,level)................................................................................ 3
TruncYardNZN(mapsheet, teast, tnorth,level)................................................................................ 3
Gridrefm_NZN(reference,level). ..................................................................................................... 3
Gridrefm_NZE(reference,level). ..................................................................................................... 3
Gridrefy_NZN(reference,level). ...................................................................................................... 3
Gridrefy_NZE(reference,level). ...................................................................................................... 3
Gridrefy_MGref(reference,level)..................................................................................................... 4
NZMS1 YARD TO NZ MAP GRID .......................................................................................... 4
YardNZE(island, easty, northy). ..................................................................................................... 4
YardNZN(island, easty, northy). ..................................................................................................... 4
LATITUDE/LONGITUDE / NZ MAP GRID ................................................................................. 4
NZLAT(Easting,Northing) ............................................................................................................... 4
NZLONG(Easting,Northing)............................................................................................................ 4
GEODNZE(Latitude,Longitude)...................................................................................................... 4
GEODNZN(Latitude,Longitude) ..................................................................................................... 5
NZGD49 / WGS84 (GD2000) CONVERSIONS ...................................................................... 5
NZGD_WGSLT(Latitude,Longitude) .............................................................................................. 5
NZGD_WGSLN(Latitude,Longitude) .............................................................................................. 5
WGS_NZGDLT(Latitude,Longitude) .............................................................................................. 5
WGS_NZGDLN(Latitude,Longitude) .............................................................................................. 5
LOCAL MERIDIONAL CIRCUIT CONVERSION............................................................................ 5
Function geod_localx(circuit As String, lat, lng) ............................................................................. 6
Function geod_localy(circuit As String, lat, lng) ............................................................................. 6
Function local_lat(circuit As String, x, y) ........................................................................................ 6
Function local_long(circuit As String, x, y) ..................................................................................... 7
Function local_NZE(circuit As String, x, y) ..................................................................................... 7
Function local_NZN(circuit As String, x, y)..................................................................................... 7
Function NZMG_localx(circuit As String, x, y)................................................................................ 7
Function NZMG_localy(circuit As String, x, y)................................................................................ 7
Function geod_local2kx(circuit As String, lat, lng) ......................................................................... 7
Function geod_local2ky(circuit As String, lat, lng) ......................................................................... 7
Function local2k_lat(circuit As String, x, y)..................................................................................... 7
Function local2k_long(circuit As String, x, y).................................................................................. 7
Function local_local2kx(circuit As String, x, y) ............................................................................... 8
Function local_local2ky(circuit As String, x, y) ............................................................................... 8
DECIMAL DEGREE/DMS CONVERSIONS ................................................................................ 8
DMSStrToDeg(dmsstr) ................................................................................................................... 8
DMStr2Deg(dmstr) ......................................................................................................................... 8
DMSToDeg(degrees,minutes,seconds) ......................................................................................... 8
DegToDMSStrP( L , NoDec) .......................................................................................................... 8
DegToDMSStr( L , NoDec)............................................................................................................. 9
THE SUBROUTINES: (ONLY AVAILABLE IN VBA ROUTINES)...................................................... 9
NZMS1_to_NZMG(island, easty, northy, eastm, northm) .............................................................. 9
NZMG_GEOD(N As Double, E As Double, LT As Double, LN As Double) ................................... 9
GEOD_NZMG(LT As Double, LN As Double, N As Double, E As Double) ................................... 9
NZGD2WGS(LT as Double, LN As Double, HT as Double, LTw as Double, LNw As Double,
HTw as Double) .............................................................................................................................. 9
WGS2NZGD(LT as Double, LN As Double, HT as Double, LTw as Double, LNw As Double,
HTw as Double) ............................................................................................................................ 10
Using the Coordinate Conversion Library in MS Access or
MS Excel
The functions provided are available in both Excel and Access, as Add-ins. The code and
functionality are the same.
SETTING UP TO USE
EXCEL. To use in Excel, go Tools | Addins. Use the Browse button and locate
converter.xla. Press Okay.
It asks "Copy to Converter.xla to Excel Addin Library Area". If you click "Yes", a copy will be
taken to your local excel/library area. If an update is made to this addin, you will have to
copy the new .xla file into area again. If you are loading from a network disk, then probably
best to press "No" BUT note that if you copy a spreadsheet using these functions to a
portable or similarly disconnected PC, then the function wont work. Where the function is
needed on a portable, say "Yes" to the copy function.
Creating a reference. Go to Modules and choose design ( first creating a new module
if none exist). It doesnt matter which module is used. From the menu, choose
Tools|Reference and then select Browse. Now change File Of Type to *.mda and
select the converter database, CONVERTER.MDA. Click OK. You can now use the
conversion functions in your database.
Or
Importing in a database. Select the Modules Tab on your database, then
File | Get External Data | Import Browse to Converter.MDA and import all modules.
1
THE FUNCTIONS.
Converts a truncated NZMG map northing and its sheet to full NZMG metres northing.
Mapsheet - the sheet the coordinate is from. Eg V18
tnorth - the truncated northing
level - the level of truncation (either 3 or 4 figures)
Coord2Trunc(Coord, level).
Takes a full NZMG coordinate and returns either a 3 or 4 figure truncated reference.
Coord - a 7 figure map coordinate
Level - either 3 or 4, the level to truncate at.
Mapsheet(east, north)
Takes full NZMG coordinate and returns the NZMS 260 map sheet no. it comes from.
Easting full NZMG easting
Northing full NZMG northing
Converts a truncated NZMS1 map easting and its sheet to full NZMS1 yard easting.
Mapsheet - the sheet the coordinate is from. Eg N34
teast - the truncated easting
level - the level of truncation
Converts a truncated NZMS1 map northing and its sheet to full NZMS1 yard northing.
Mapsheet - the sheet the coordinate is from. Eg S102
tnorth - the truncated northing
level - the level of truncation (either 3 or 4 figures)
2
TruncYardNZE(mapsheet, teast, tnorth,level).
Converts a truncated yard grid coordinate plus the mapsheet to a full NZMG metre easting.
Mapsheet - the sheet the coordinate is from. Eg S102
teast - truncated NZMS1 yard easting
tnorth - truncated NZMG1 yard northing
level - the level of truncation (either 3 or 4 figures)
Converts a truncated yard grid coordinate plus the mapsheet to a full NZMG metre northing.
Mapsheet - the sheet the coordinate is from. Eg S102
teast - truncated NZMS1 yard easting
tnorth - truncated NZMG1 yard northing
level - the level of truncation (either 3 or 4 figures)
Gridrefm_NZN(reference,level).
Converts a truncated NZ mapgrid reference in form "_xx / eeennn" or "_xx/eeeennnn" and
converts it to full NZ map grid northing.
Reference: String form of truncated reference. Refs like: R12/342094, R12 : 343 094, R12-
343094 would all be accepted level - the level of truncation (either 3 or 4 figures)
Gridrefm_NZE(reference,level).
Converts a truncated NZ mapgrid reference in form "_xx / eeennn" or "_xx/eeeennnn" and
converts it to full NZ map grid easting.
Reference: String form of truncated reference. Refs like: R12/342094, R12 : 343 094, R12-
343094 would all be accepted level - the level of truncation (either 3 or 4 figures)
Gridrefy_NZN(reference,level).
Converts a truncated National Yard grid reference in form "ixxx / eeennn" or
"ixxx/eeeennnn" and converts it to full NZ map grid northing.
Reference: String form of truncated reference. Refs like: S122/573921, N12 : 643 994, S8-
76334095 would all be accepted level - the level of truncation (either 3 or 4 figures)
Gridrefy_NZE(reference,level).
Converts a truncated National Yard reference in form "ixxx / eeennn" or "ixxx/eeeennnn"
and converts it to full NZ map grid easting.
3
Reference: String form of truncated reference. Refs like: S122/573921, N12 : 643 994, S8-
76334095 would all be accepted level - the level of truncation (either 3 or 4 figures)
Gridrefy_MGref(reference,level).
Converts a truncated National Yard reference in form "ixxx / eeennn" or "ixxx/eeeennnn"
and converts it into a truncated NZMG reference.
Reference: String form of truncated reference. Refs like: S122/573921, N12 : 643 994, S8-
76334095 would all be accepted level - the level of truncation (either 3 or 4 figures)
NZLAT(Easting,Northing)
NZLONG(Easting,Northing)
Converts a NZ Map grid reference to the equivalent Longitude in Decimal degrees
Easting full NZMG easting
Northing full NZMG northing
GEODNZE(Latitude,Longitude)
Converts a lat/long reference to full NZMG easting.
Latitude latitude in decimal degrees
4
Longitude longitude in decimal degrees
GEODNZN(Latitude,Longitude)
This is a suite that converts between the NZ Geodetic Datum 1949 and the WGS84 Datum.
No height above spheroid is included so accuracy limited to +/- 2cm for height above
spheroid less than 100m. The conversion to WGS84 is equivalent to the 7-parameter
conversion from NZGD49 to the new GD2000 Datum. This has an accuracy of +/- 4m as it
does not take into account local deformation of the NZ by plate tectonics forces since 1949.
NZGD_WGSLT(Latitude,Longitude)
Converts a lat/long reference in NZ Geodetic Datum to WGS84 latitude.
Latitude latitude in decimal degrees in NZGD49
Longitude longitude in decimal degrees in NZGD49
NZGD_WGSLN(Latitude,Longitude)
Converts a lat/long reference in NZ Geodetic Datum to WGS84 longitude
Latitude latitude in decimal degrees in NZGD49
Longitude longitude in decimal degrees in NZGD49
WGS_NZGDLT(Latitude,Longitude)
WGS_NZGDLN(Latitude,Longitude)
Converts a lat/long reference in WGS84 Datum to NZ Geodetic Datum 49 longitude
Latitude latitude in decimal degrees in WGS84
Longitude longitude in decimal degrees in WGS84
This suite of functions provide conversions for the 28 local meridional circuits on both the
GD49 and GD2000 datums. All use a string code to identify the circuit being used. These
codes have been chosen to match those used by the old CONCORD program. They are:
5
AMUR Amuri Circuit PLEN Bay of Plenty Circuit
Eg. To convert a coordinate in Bluff meridional circuit to NZMG, then the functions would
look like local_NZE("BLUF",[bluff_east],[bluf_north]) in ACCESS or
=local_NZN("BLUF",A1,B1) in Excel
6
Function local_long(circuit As String, x, y)
Returns GD49 longitude from local GD49 coordinate
Returns NZMG Easting from local GD49 coordinate. Note that this uses calculation of
lat/long first and then the projection instead of the J Hannah's time-series formula. The two
methods agree to nearest cm.
Returns NZMG Northing from local GD49 coordinate. Note that this uses calculation of
lat/long first and then the projection instead of the J Hannah's time-series formula. The two
methods agree to nearest cm.
Returns local GD49 coordinate easting from NZMG coordinate. Note that This uses
calculation of lat/long first and then the projection instead of the J Hannah's time-series
formula. The two methods agree to nearest cm.
Returns local GD2000 easting from GD2000 lat/long (This function does NOT do a datum
shift).
Returns GD2000 latitude from GD2000 local circuit (This function does NOT do a datum
shift).
7
Function local_local2kx(circuit As String, x, y)
Return GD2000 easting from a GD49 local coordinate. (Does 7 parameter datum shift)
Return GD2000 northing from a GD49 local coordinate. (Does 7 parameter datum shift)
DMSStrToDeg(dmsstr)
Converts a string containing a DMS representation of latitude or longitude to decimal
degrees
Dmsstr string containing DMS. The elements degrees, minutes and seconds must
be separated by a space. They can have , and " marks so long as no extra spaces
are present. Eg 42 6 34.4, -55 09 44.5555" are both valid but 43 34 45.55 " is
not.
DMStr2Deg(dmstr)
Converts a string containing a Degress and Decimal minutes representation of latitude or
longitude to decimal degrees.
Dmstr string containing DM. Converts strings of forms like W178 34.34 or 44S23.22
WENS are recognised but not required. A non-numeric character(s) is required
between the Degrees values and the minutes. Degrees must come before minutes.
DMSToDeg(degrees,minutes,seconds)
Converts fields containing degrees, minutes and seconds to decimal degrees
Degrees real value contains the degrees part of a DMS coordinate
Minutes real value contains the minutes part of a DMS coordinate
Seconds real value contains the seconds part of a DMS coordinate
DegToDMSStrP( L , NoDec)
Converts a decimal degree value to a string containing a DMS representation separated by
spaces and including and " marks
L Decimal Degree value to convert
NoDec the no. of decimal places to quote the seconds value to.
8
DegToDMSStr( L , NoDec)
Converts a decimal degree value to a string containing a DMS representation separated by
spaces.
L Decimal Degree value to convert
NoDec the no. of decimal places to quote the seconds value to.
9
LTw latitude in decimal degrees on WGS84, written
LNw longitude in decimal degrees on WGS84, written
HTw height of point on geoid above the WGS84 spheroid, written
10