Skip to content

Commit 1149a66

Browse files
authored
Merge pull request #138 from jonathonpsmith/master
Introduction of a projection parameter for convert.py functions and ISG grid/geo conversion capability
2 parents f22fb4e + d7db0ec commit 1149a66

File tree

5 files changed

+513
-25
lines changed

5 files changed

+513
-25
lines changed

geodepy/constants.py

Lines changed: 5 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -67,6 +67,11 @@ def __init__(self, falseeast, falsenorth, cmscale, zonewidth, initialcm):
6767

6868
utm = Projection(500000, 10000000, 0.9996, 6, -177)
6969

70+
# Integrated Survey Grid - used in NSW as the projection for AGD66
71+
# Spatial Services projections page - https://www.spatial.nsw.gov.au/surveying/geodesy/projections
72+
# ISG Technical Manual - https://www.spatial.nsw.gov.au/__data/assets/pdf_file/0017/25730/ISG.pdf
73+
isg = Projection(300000, 5000000, 0.99994, 2, -177)
74+
7075

7176
# Helmert 14 parameter transformation
7277
class Transformation(object):

geodepy/convert.py

Lines changed: 49 additions & 24 deletions
Original file line numberDiff line numberDiff line change
@@ -8,7 +8,8 @@
88
from math import (sin, cos, atan2, radians, degrees,
99
sqrt, cosh, sinh, tan, atan, log)
1010
import datetime
11-
from geodepy.constants import utm, grs80
11+
import warnings
12+
from geodepy.constants import utm, isg, grs80, ans
1213
from geodepy.angles import (DECAngle, HPAngle, GONAngle, DMSAngle, DDMAngle,
1314
dec2hp, dec2hpa, dec2gon, dec2gona,
1415
dec2dms, dec2ddm,
@@ -19,11 +20,6 @@
1920
dd2sec, angular_typecheck)
2021

2122

22-
# Universal Transverse Mercator Projection Parameters
23-
# TODO: Add this part into functions: geo2grid, grid2geo, psfandgridconv
24-
proj = utm
25-
26-
2723
def polar2rect(r, theta):
2824
"""
2925
Converts point in polar coordinates to corresponding rectangular coordinates
@@ -240,7 +236,7 @@ def beta_coeff(ellipsoid):
240236
return b2, b4, b6, b8, b10, b12, b14, b16
241237

242238

243-
def psfandgridconv(xi1, eta1, lat, lon, cm, conf_lat, ellipsoid=grs80):
239+
def psfandgridconv(xi1, eta1, lat, lon, cm, conf_lat, ellipsoid=grs80, prj=utm):
244240
"""
245241
Calculates Point Scale Factor and Grid Convergence. Used in convert.geo2grid
246242
and convert.grid2geo
@@ -270,7 +266,7 @@ def psfandgridconv(xi1, eta1, lat, lon, cm, conf_lat, ellipsoid=grs80):
270266
p += 2*r * a[r-1] * cos(2*r * xi1) * cosh(2*r * eta1)
271267
q += 2*r * a[r-1] * sin(2*r * xi1) * sinh(2*r * eta1)
272268
q = -q
273-
psf = (float(proj.cmscale)
269+
psf = (float(prj.cmscale)
274270
* (A / ellipsoid.semimaj)
275271
* sqrt(q**2 + p**2)
276272
* ((sqrt(1 + (tan(lat)**2))
@@ -289,7 +285,7 @@ def psfandgridconv(xi1, eta1, lat, lon, cm, conf_lat, ellipsoid=grs80):
289285
return psf, grid_conv
290286

291287

292-
def geo2grid(lat, lon, zone=0, ellipsoid=grs80):
288+
def geo2grid(lat, lon, zone=0, ellipsoid=grs80, prj=utm):
293289
"""
294290
Takes a geographic co-ordinate (latitude, longitude) and returns its
295291
corresponding Hemisphere, Zone and Projection Easting and Northing, Point
@@ -314,23 +310,40 @@ def geo2grid(lat, lon, zone=0, ellipsoid=grs80):
314310
lon = angular_typecheck(lon)
315311
# Input Validation - UTM Extents and Values
316312
zone = int(zone)
317-
if zone < 0 or zone > 60:
318-
raise ValueError('Invalid Zone - Zones from 1 to 60')
313+
if prj == isg:
314+
if zone not in (0, 541, 542, 543, 551, 552, 553, 561, 562, 563, 572):
315+
raise ValueError('Invalid Zone - Choose from 541, 542, 543, 551, 552, 553, 561, 562, 563, 572')
316+
else:
317+
if zone < 0 or zone > 60:
318+
raise ValueError('Invalid Zone - Zones from 1 to 60')
319319

320320
if lat < -80 or lat > 84:
321321
raise ValueError('Invalid Latitude - Latitudes from -80 to +84')
322322

323323
if lon < -180 or lon > 180:
324324
raise ValueError('Invalid Longitude - Longitudes from -180 to +180')
325325

326+
if prj == isg and ellipsoid != ans:
327+
warnings.warn(message='ISG projection should be used with ANS ellipsoid', category=UserWarning)
328+
326329
A = rect_radius(ellipsoid)
327330
a = alpha_coeff(ellipsoid)
328331
lat = radians(lat)
329332
# Calculate Zone
330333
if zone == 0:
331-
zone = int((float(lon) - (
332-
proj.initialcm - (1.5 * proj.zonewidth))) / proj.zonewidth)
333-
cm = float(zone * proj.zonewidth) + (proj.initialcm - proj.zonewidth)
334+
if prj == isg:
335+
amgzone = (float(lon) - (prj.initialcm - (4.5 * prj.zonewidth))) / (prj.zonewidth * 3)
336+
subzone = int((amgzone - int(amgzone)) * 3 + 1)
337+
amgzone = int(amgzone)
338+
zone = int(f'{amgzone}{subzone}')
339+
else:
340+
zone = int((float(lon) - (prj.initialcm - (1.5 * prj.zonewidth))) / prj.zonewidth)
341+
if prj == isg:
342+
amgzone = int(str(zone)[:2])
343+
subzone = int(str(zone)[2])
344+
cm = float((amgzone - 1) * prj.zonewidth * 3 + prj.initialcm + (subzone - 2) * prj.zonewidth)
345+
else:
346+
cm = float(zone * prj.zonewidth + prj.initialcm - prj.zonewidth)
334347

335348
# Conformal Latitude
336349
sigx = (ellipsoid.ecc1 * tan(lat)) / sqrt(1 + (tan(lat) ** 2))
@@ -357,14 +370,14 @@ def geo2grid(lat, lon, zone=0, ellipsoid=grs80):
357370
y = A * xi
358371

359372
# Hemisphere-dependent UTM Projection Co-ordinates
360-
east = proj.cmscale * x + proj.falseeast
373+
east = prj.cmscale * x + prj.falseeast
361374
if y < 0:
362375
hemisphere = 'South'
363-
north = proj.cmscale * y + proj.falsenorth
376+
north = prj.cmscale * y + prj.falsenorth
364377
else:
365378
hemisphere = 'North'
366379
falsenorth = 0
367-
north = proj.cmscale * y + falsenorth
380+
north = prj.cmscale * y + falsenorth
368381

369382
# Point Scale Factor and Grid Convergence
370383
psf, grid_conv = psfandgridconv(xi1, eta1, degrees(lat), lon, cm, conf_lat)
@@ -375,7 +388,7 @@ def geo2grid(lat, lon, zone=0, ellipsoid=grs80):
375388
round(psf, 8), grid_conv)
376389

377390

378-
def grid2geo(zone, east, north, hemisphere='south', ellipsoid=grs80):
391+
def grid2geo(zone, east, north, hemisphere='south', ellipsoid=grs80, prj=utm):
379392
"""
380393
Takes a Transverse Mercator grid co-ordinate (Zone, Easting, Northing,
381394
Hemisphere) and returns its corresponding Geographic Latitude and Longitude,
@@ -393,8 +406,12 @@ def grid2geo(zone, east, north, hemisphere='south', ellipsoid=grs80):
393406
"""
394407
# Input Validation - UTM Extents and Values
395408
zone = int(zone)
396-
if zone < 0 or zone > 60:
397-
raise ValueError('Invalid Zone - Zones from 1 to 60')
409+
if prj == isg:
410+
if zone not in (541, 542, 543, 551, 552, 553, 561, 562, 563, 572):
411+
raise ValueError('Invalid Zone - Choose from 541, 542, 543, 551, 552, 553, 561, 562, 563, 572')
412+
else:
413+
if zone < 0 or zone > 60:
414+
raise ValueError('Invalid Zone - Zones from 1 to 60')
398415

399416
if east < -2830000 or east > 3830000:
400417
raise ValueError('Invalid Easting - Must be within'
@@ -407,15 +424,18 @@ def grid2geo(zone, east, north, hemisphere='south', ellipsoid=grs80):
407424
if h != 'north' and h != 'south':
408425
raise ValueError('Invalid Hemisphere - String, either North or South')
409426

427+
if prj == isg and ellipsoid != ans:
428+
warnings.warn(message='ISG projection should be used with ANS ellipsoid', category=UserWarning)
429+
410430
A = rect_radius(ellipsoid)
411431
b = beta_coeff(ellipsoid)
412432
# Transverse Mercator Co-ordinates
413-
x = (east - float(proj.falseeast)) / float(proj.cmscale)
433+
x = (east - float(prj.falseeast)) / float(prj.cmscale)
414434
if hemisphere.lower() == 'north':
415-
y = -(north / float(proj.cmscale))
435+
y = -(north / float(prj.cmscale))
416436
hemisign = -1
417437
else:
418-
y = (north - float(proj.falsenorth)) / float(proj.cmscale)
438+
y = (north - float(prj.falsenorth)) / float(prj.cmscale)
419439
hemisign = 1
420440

421441
# Transverse Mercator Ratios
@@ -463,7 +483,12 @@ def f1tn(tn, ecc1, ecc1sq):
463483
lat = degrees(atan(t))
464484

465485
# Compute Longitude
466-
cm = float((zone * proj.zonewidth) + proj.initialcm - proj.zonewidth)
486+
if prj == isg:
487+
amgzone = int(str(zone)[:2])
488+
subzone = int(str(zone)[2])
489+
cm = float((amgzone - 1) * prj.zonewidth * 3 + prj.initialcm + (subzone - 2) * prj.zonewidth)
490+
else:
491+
cm = float((zone * prj.zonewidth) + prj.initialcm - prj.zonewidth)
467492
long_diff = degrees(atan(sinh(eta1) / cos(xi1)))
468493
long = cm + long_diff
469494

Lines changed: 212 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,212 @@
1+
ALBU,-36.079078850050,146.914301020650,
2+
ANNA,-32.786387375840,152.085197007870,
3+
ARD2,-30.522463664480,151.673569431060,
4+
ARDL,-34.352400821090,146.902223561530,
5+
ARMD,-30.516201910320,151.664711111400,
6+
ASHF,-29.325939194990,151.092033399130,
7+
BALN,-28.874270142210,153.563020333320,
8+
BANK,-33.916653008040,151.035165581320,
9+
BARR,-34.565756130890,150.857174374750,
10+
BATH,-33.431260053750,149.566032786600,
11+
BBDH,-32.343426762120,146.652773125790,
12+
BDST,-27.988693001490,152.994004422590,
13+
BEGA,-36.677477042550,149.840791166900,
14+
BERM,-36.432192532390,150.074756654240,
15+
BIGG,-36.282304606530,148.024989032530,
16+
BING,-32.413362673700,151.651193214890,
17+
BJCT,-30.103225969580,148.963030107990,
18+
BKNL,-31.997804118910,141.468816141530,
19+
BLCK,-31.655869939440,150.243563220700,
20+
BLKT,-33.773325128960,150.907625503660,
21+
BLRN,-34.647376511190,143.566122032320,
22+
BNDC,-37.149042056380,148.883670791220,
23+
BOMB,-36.913603745640,149.235862495550,
24+
BOOR,-34.439875740910,148.700493741500,
25+
BORA,-31.513812898990,150.639630095520,
26+
BRBA,-30.381927466300,150.606159279950,
27+
BRDW,-35.448057820140,149.783983323290,
28+
BRWN,-29.969962049740,146.859629830410,
29+
BUND,-30.186693592420,151.088547277780,
30+
BURK,-30.096818183800,145.933090647440,
31+
CANR,-37.566417946260,149.156254776660,
32+
CARG,-33.289969788060,146.364698024680,
33+
CBAR,-31.515200953450,145.834937112410,
34+
CBLE,-30.955106664800,148.377054074800,
35+
CBRA,-35.913536753510,145.642887120900,
36+
CBRM,-35.913730019200,145.644123289160,
37+
CESS,-32.836839479180,151.355424238120,
38+
CHCC,-30.296949944770,153.116452056710,
39+
CHIP,-33.888468395020,151.200058446270,
40+
CHSM,-35.419814372640,149.119590268640,
41+
CKWL,-34.457633734950,149.471319973730,
42+
CLAH,-31.832023492750,149.713778172590,
43+
CLBI,-29.544125834720,148.584346163510,
44+
CMDN,-34.047855394520,150.690349966570,
45+
CNBN,-31.334889140090,149.268408606510,
46+
CNDA,-30.466878337590,147.686954814500,
47+
CNDO,-33.086709612700,147.149791898160,
48+
CNWD,-35.207947226360,149.031553277260,
49+
COBH,-30.808623541220,146.779606564930,
50+
COFF,-30.301715186760,153.137240133770,
51+
COLE,-34.808511810850,145.878982178890,
52+
COMA,-36.236931036870,149.126002278100,
53+
COPS,-29.582469259810,152.772422029060,
54+
CRDX,-34.326381899560,150.766395626120,
55+
CSNO,-28.867168234440,153.046492333440,
56+
CTMD,-34.640854520510,148.024428846600,
57+
CWN2,-33.595280843160,151.170401310160,
58+
CWRA,-33.832803699280,148.701112901410,
59+
DBBO,-32.250934874890,148.600941240150,
60+
DKSN,-35.252310013350,149.134522098020,
61+
DLQN,-35.533143342320,144.963344877280,
62+
DORR,-30.351968626410,152.711936850130,
63+
DUNE,-32.013429920710,149.387007128460,
64+
DWHY,-33.752851019060,151.285837551170,
65+
ECHU,-36.141836503430,144.752294114480,
66+
ECOR,-34.377194893520,150.909653507890,
67+
EDEN,-37.073313317370,149.908099186570,
68+
EMMD,-31.667875248990,144.284531118480,
69+
FLGP,-31.106188458550,141.726864221780,
70+
FORB,-33.386823485560,148.005764467050,
71+
FORS,-32.202710872290,152.521279912290,
72+
FTDN,-33.856641888470,151.224090214610,
73+
GABO,-37.569690473100,149.913973093290,
74+
GERR,-34.747858820360,150.826503806750,
75+
GFEL,-33.894580785140,148.159517594830,
76+
GFTH,-34.287847702910,146.035544915810,
77+
GFTN,-29.694628189700,152.931812918630,
78+
GILG,-31.712549375050,148.661286333990,
79+
GLB2,-34.747981834810,149.709950157180,
80+
GLBN,-34.757258766220,149.716521170260,
81+
GLIN,-29.745140339400,151.750555070350,
82+
GNGN,-35.186526813120,149.129325278390,
83+
GNOA,-37.478456864560,149.588255913920,
84+
GONG,-34.428798726090,150.897673735630,
85+
GOOL,-33.986013365380,145.705699947480,
86+
GUNN,-30.979748133500,150.255136195760,
87+
GURL,-29.736374729300,149.794397024980,
88+
GWAB,-30.607217796500,148.970055985540,
89+
HAY1,-34.507065605300,144.851186647770,
90+
HERN,-30.328217372130,152.485758066980,
91+
HILL,-33.486454175090,145.530098471910,
92+
HLB2,-35.712778654860,147.316222432940,
93+
HLBK,-35.725922870950,147.316155284490,
94+
HNSB,-33.701901431810,151.096493086520,
95+
IHOE,-32.865662241970,143.490795121490,
96+
INVL,-29.778008344970,151.113275953640,
97+
IRYM,-34.221226895810,142.189912111170,
98+
IVH2,-32.884967999620,144.307617640270,
99+
JERI,-35.356857921110,145.724204898170,
100+
KIRR,-34.044934188350,151.071899350910,
101+
KNCB,-33.482823083220,151.390789830280,
102+
KRNG,-35.736914809100,143.921006923710,
103+
KTMB,-33.697374117700,150.317020257580,
104+
KULW,-32.327731173920,145.008613436410,
105+
KURJ,-33.555848060380,150.664437736660,
106+
LGOW,-33.482521885170,150.158662459500,
107+
LIPO,-34.106879828990,141.009902661120,
108+
LIRI,-29.431299550670,147.981730153680,
109+
LKHT,-35.228801969070,146.704570180350,
110+
LORD,-31.521522180960,159.060201939740,
111+
LOTH,-30.535051650830,145.115609446820,
112+
MACK,-30.712034649050,152.917284371330,
113+
MENA,-34.127673092760,150.742585967250,
114+
MENO,-34.273855325240,141.805322115080,
115+
MGRV,-33.628099764890,150.829824546440,
116+
MHOP,-32.921796300530,145.910784251350,
117+
MNDE,-32.394328297570,142.416650264410,
118+
MNPK,-33.173075032630,151.549959133970,
119+
MOGO,-35.748958806400,150.190785610250,
120+
MOUL,-35.092564428440,144.034741161740,
121+
MREE,-29.459300454610,149.824413821780,
122+
MRWA,-32.141340244110,150.354104895070,
123+
MSV2,-34.550684444020,150.372985351130,
124+
MSVL,-34.552112656670,150.372214490690,
125+
MTHR,-32.617018805550,151.097961971100,
126+
MTLD,-32.738569519450,151.559156812120,
127+
MUDG,-32.591572907010,149.583509963220,
128+
MWAL,-35.994674877580,145.987190855910,
129+
NBRI,-30.331701161640,149.785211166790,
130+
NBRK,-29.678703399780,145.812838240400,
131+
NDRA,-34.753444164790,146.536290015360,
132+
NEWE,-32.925559065750,151.787608326110,
133+
NGAN,-31.565459310400,147.193360053320,
134+
NMBN,-28.599434985970,153.230499970500,
135+
NOWE,-31.515142575740,151.715151497200,
136+
NRMN,-32.236010961490,148.237516634800,
137+
NSTA,-29.047129217410,150.442979523360,
138+
NWCS,-32.931168819540,151.764092098380,
139+
NWRA,-34.875343194560,150.603631645820,
140+
NYMA,-32.067701391520,146.314409977290,
141+
OBRN,-33.705521182240,149.856428172010,
142+
ORNG,-33.286762296710,149.096837893300,
143+
OVAL,-32.755411057210,148.644863619150,
144+
OXLY,-34.194693908940,144.100428423170,
145+
PARK,-33.000328312300,148.263413990430,
146+
PBOT,-33.975609862890,151.210895108160,
147+
PCTN,-34.159189725940,150.603976898820,
148+
PERI,-36.412841838130,148.408734116770,
149+
PIAN,-35.055844182060,143.326428977960,
150+
PMAC,-31.463504548720,152.896574077270,
151+
POON,-33.384043016550,142.565575120360,
152+
PRCE,-35.365137141950,149.087785486010,
153+
PRKS,-33.136292183010,148.175265584150,
154+
PTKL,-34.477127766480,150.912527248830,
155+
PUTY,-32.954620895850,150.658359913800,
156+
QUAM,-30.934558432890,147.868825445340,
157+
RAND,-35.595319266520,146.577251067320,
158+
RANK,-33.843527001430,146.260407837020,
159+
RAYM,-32.764467134990,151.744289410730,
160+
RBVL,-34.591834001070,142.768576347670,
161+
RGLN,-33.417233215590,149.653804409750,
162+
ROBI,-28.078561956330,153.380185071210,
163+
RUUS,-34.043990798410,141.267661676860,
164+
RYLS,-32.794022742730,149.975508128490,
165+
SCON,-32.052935807700,150.868499000200,
166+
SLTC,-28.273328280410,153.573806707950,
167+
SNGO,-32.559818166330,151.174604604680,
168+
SPPT,-32.961843433420,151.622519349880,
169+
SPWD,-33.700119179160,150.562771606160,
170+
STR1,-35.317094613710,149.008840791660,
171+
STR2,-35.317722240160,149.008942882160,
172+
SYDN,-33.782461034370,151.149221129830,
173+
SYM1,-35.344075493330,149.159851516890,
174+
TAMW,-31.094437232860,150.929780603990,
175+
TARE,-31.913796793190,152.462679874520,
176+
TBOB,-29.451682888950,142.056174284850,
177+
TID1,-35.400765396740,148.978784924650,
178+
TLPA,-30.868502342240,144.412558269720,
179+
TMBA,-35.779238740370,148.010291213980,
180+
TMRA,-34.448001871050,147.533182888470,
181+
TMUT,-35.302643610120,148.218953584450,
182+
TNTR,-29.056362484200,152.018821126120,
183+
TOTT,-32.254926544980,147.368539197360,
184+
TULL,-32.633765292060,147.568499137660,
185+
TURO,-36.036714128190,150.120994043860,
186+
ULLA,-35.363540535700,150.464154105420,
187+
UNSW,-33.919253347720,151.230686636390,
188+
UNW2,-33.919775931790,151.231539899560,
189+
VLWD,-33.882216612320,150.976004844000,
190+
WAKL,-35.456861348640,144.379706933050,
191+
WALW,-35.967558982930,147.732940588930,
192+
WARI,-29.542163135120,150.573076304270,
193+
WARW,-28.215068628490,152.029299479150,
194+
WCHP,-31.462664673680,152.733164012130,
195+
WDBG,-28.395031300420,152.606047728950,
196+
WEEM,-29.014858731570,149.253381412470,
197+
WFAL,-34.135791767390,150.993806632310,
198+
WGBA,-33.888008907390,150.596577774240,
199+
WGGA,-35.108730522160,147.368062957900,
200+
WLCA,-31.556825338460,143.373845848210,
201+
WLGT,-30.024952808760,148.115771853170,
202+
WLMD,-35.596106671330,149.136499948870,
203+
WLWN,-30.932237460500,152.624354982030,
204+
WRRN,-31.702371232160,147.835254676800,
205+
WTCF,-30.854815949200,143.091762732270,
206+
WTON,-32.575358672460,148.955422027630,
207+
WWLG,-33.704981792290,147.320457917690,
208+
WYNG,-33.284131475860,151.422832003760,
209+
YARO,-31.237928944550,151.921103512690,
210+
YASS,-34.846467014510,148.912040492890,
211+
YMBA,-29.449038838130,153.356815424290,
212+
YUNG,-34.305317631760,148.281535497920,

0 commit comments

Comments
 (0)