Вы находитесь на странице: 1из 12

Using the Coordinate Conversion Library in MS Access or

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.

ACCESS. The functions for coordinate conversion are in a database called


CONVERTER.MDA. They can be imported from there but a better method is to create a
Reference to the database so that can be used by any MS Access database.

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.

TRUNCATED COORDINATE HANDLING:

NZMGTruncE(mapsheet, teast, level).


Converts a truncated NZMG map easting and its sheet to full NZMG metres easting.
Mapsheet - the sheet the coordinate is from. Eg V18
teast - the truncated easting
level - the level of truncation (either 3 or 4 figures)

NZMGTruncN(mapsheet, tnorth, level).

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

NZMS1TruncE(mapsheet, teast, level).

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

NZMS1TruncN(mapsheet, tnorth, level).

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)

TruncYardNZN(mapsheet, teast, tnorth,level).

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)

NZMS1 YARD TO NZ MAP GRID

YardNZE(island, easty, northy).


Converts a full yard grid coordinate plus the island to a NZMG metre easting.
Island - either N or S (or the mapsheet eg N102)
Easty - full NZMS1 yard easting
Northy - full NZMG1 yard northing

YardNZN(island, easty, northy).


Converts a full yard grid coordinate plus the island to a NZMG metre northing.
Island - either N or S (or the mapsheet eg N102)
Easty - full NZMS1 yard easting
Northy - full NZMG1 yard northing

LATITUDE/LONGITUDE / NZ MAP GRID

NZLAT(Easting,Northing)

Converts a NZ Map grid reference to the equivalent Latitude in Decimal degrees


Easting full NZMG easting
Northing full NZMG 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)

Converts a lat/long reference to full NZMG northing.


Latitude latitude in decimal degrees
Longitude longitude in decimal degrees

NZGD49 / WGS84 (GD2000) CONVERSIONS

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)

Converts a lat/long reference in WGS84 Datum to NZ Geodetic Datum 49 latitude


Latitude latitude in decimal degrees in WGS84
Longitude longitude in decimal degrees in WGS84

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

LOCAL MERIDIONAL CIRCUIT CONVERSION

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

BLUF Bluff Circuit BULL Buller Circuit

COLL Collingwood Circuit GAWL Gawler Circuit

GREY Grey Circuit HAWK Hawkes Bay Circuit

HOKI Hokitika Circuit JACK Jacksons Bay Circuit

KARA Karamea Circuit LIND Lindis Peak Circuit

MARL Marlborough Circuit EDEN Mt Eden Circuit

NICH Mt Nicholas Circuit PLEA Mt Pleasant Circuit

YORK Mt York Circuit NELS Nelson Circuit

TAIE North Taieri Circuit OBSE Observation Point


Circuit

OKAR Okarito Circuit POVE Poverty Bay Circuit

TARA Taranaki Circuit TIMA Timaru Circuit

TUHI Tuhirangi Circuit WAIR Wairarapa Circuit

WANG Wanganui Circuit WELL Wellington 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

Function geod_localx(circuit As String, lat, lng)

Returns circuit easting from a GD49 lat/long

Function geod_localy(circuit As String, lat, lng)


Returns circuit northing from a GD49 lat/long

Function local_lat(circuit As String, x, y)


Returns GD49 latitude from local GD49 coordinate

6
Function local_long(circuit As String, x, y)
Returns GD49 longitude from local GD49 coordinate

Function local_NZE(circuit As String, x, y)

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.

Function local_NZN(circuit As String, x, y)

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.

Function NZMG_localx(circuit As String, x, y)

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.

Function NZMG_localy(circuit As String, x, y)


Returns local GD49 coordinate northing 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.

Function geod_local2kx(circuit As String, lat, lng)

Returns local GD2000 easting from GD2000 lat/long (This function does NOT do a datum
shift).

Function geod_local2ky(circuit As String, lat, lng)


Returns local GD2000 northing from GD2000 lat/long (This function does NOT do a datum
shift).

Function local2k_lat(circuit As String, x, y)

Returns GD2000 latitude from GD2000 local circuit (This function does NOT do a datum
shift).

Function local2k_long(circuit As String, x, y)


Returns GD2000 longitude 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)

Function local_local2ky(circuit As String, x, y)

Return GD2000 northing from a GD49 local coordinate. (Does 7 parameter datum shift)

DECIMAL DEGREE/DMS CONVERSIONS


This suite is based on example code provided by Microsoft Corp, in the NEATCODE.MDB
download. The routines have been enhanced and corrected to allow for negative degrees

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.

THE SUBROUTINES: (ONLY AVAILABLE IN VBA ROUTINES)

NZMS1_to_NZMG(island, easty, northy, eastm, northm)


Converts a full National Yard grid reference to NZMG
Island - either N or S (or the mapsheet eg N102)
Easty - full NZMS1 yard easting, read
Northy - full NZMG1 yard northing, read
Eastm full NZMG easting, written
Northm full NZMG northing, written

NZMG_GEOD(N As Double, E As Double, LT As Double, LN As Double)

Converts a NZMG reference to Latitude /longitude


N full NZMG northing, read
E - full NZMG easting , read
LT latitude in decimal degrees, written
LN longitude in decimal degrees , written

GEOD_NZMG(LT As Double, LN As Double, N As Double, E As Double)

Converts Lat/long to NZMG


LT latitude in decimal degrees, read
LN longitude in decimal degrees , read
N full NZMG northing, written
E - full NZMG easting , written

NZGD2WGS(LT as Double, LN As Double, HT as Double, LTw as Double, LNw As


Double, HTw as Double)
Converts Lat/long measured on NZGD49 to values measured against WGS84. If height is
unknown (use The EGM96 program at http://www.nima.mil/GandG/egm96/intpt.htm to
determine) then use 0.
LT latitude in decimal degrees off NZGD49, read
LN longitude in decimal degrees off NZGD49, read
HT height of point on geoid above the NZGD49 spheroid, read

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

WGS2NZGD(LT as Double, LN As Double, HT as Double, LTw as Double, LNw As


Double, HTw as Double)
Converts Lat/long measured on WGS84 datum to values measured on NZGD49. If height is
unknown (use The EGM96 progrom at http://164.214.2.59/GandG/wgs-84/egm96.html to
determine) then use 0.
LT latitude in decimal degrees off WGS84, read
LN longitude in decimal degrees off WGS84, read
HT height of point on geoid above the WGS84spheroid, read
LTw latitude in decimal degrees on NZGD49, written
LNw longitude in decimal degrees on NZGD49, written
HTw height of point on geoid above the NZGD49spheroid, written

10

Вам также может понравиться