proj4js-combined.js 182 KB

12345678910111213141516171819202122232425262728293031323334353637383940414243444546474849505152535455565758596061626364656667686970717273747576777879808182838485868788899091929394959697989910010110210310410510610710810911011111211311411511611711811912012112212312412512612712812913013113213313413513613713813914014114214314414514614714814915015115215315415515615715815916016116216316416516616716816917017117217317417517617717817918018118218318418518618718818919019119219319419519619719819920020120220320420520620720820921021121221321421521621721821922022122222322422522622722822923023123223323423523623723823924024124224324424524624724824925025125225325425525625725825926026126226326426526626726826927027127227327427527627727827928028128228328428528628728828929029129229329429529629729829930030130230330430530630730830931031131231331431531631731831932032132232332432532632732832933033133233333433533633733833934034134234334434534634734834935035135235335435535635735835936036136236336436536636736836937037137237337437537637737837938038138238338438538638738838939039139239339439539639739839940040140240340440540640740840941041141241341441541641741841942042142242342442542642742842943043143243343443543643743843944044144244344444544644744844945045145245345445545645745845946046146246346446546646746846947047147247347447547647747847948048148248348448548648748848949049149249349449549649749849950050150250350450550650750850951051151251351451551651751851952052152252352452552652752852953053153253353453553653753853954054154254354454554654754854955055155255355455555655755855956056156256356456556656756856957057157257357457557657757857958058158258358458558658758858959059159259359459559659759859960060160260360460560660760860961061161261361461561661761861962062162262362462562662762862963063163263363463563663763863964064164264364464564664764864965065165265365465565665765865966066166266366466566666766866967067167267367467567667767867968068168268368468568668768868969069169269369469569669769869970070170270370470570670770870971071171271371471571671771871972072172272372472572672772872973073173273373473573673773873974074174274374474574674774874975075175275375475575675775875976076176276376476576676776876977077177277377477577677777877978078178278378478578678778878979079179279379479579679779879980080180280380480580680780880981081181281381481581681781881982082182282382482582682782882983083183283383483583683783883984084184284384484584684784884985085185285385485585685785885986086186286386486586686786886987087187287387487587687787887988088188288388488588688788888989089189289389489589689789889990090190290390490590690790890991091191291391491591691791891992092192292392492592692792892993093193293393493593693793893994094194294394494594694794894995095195295395495595695795895996096196296396496596696796896997097197297397497597697797897998098198298398498598698798898999099199299399499599699799899910001001100210031004100510061007100810091010101110121013101410151016101710181019102010211022102310241025102610271028102910301031103210331034103510361037103810391040104110421043104410451046104710481049105010511052105310541055105610571058105910601061106210631064106510661067106810691070107110721073107410751076107710781079108010811082108310841085108610871088108910901091109210931094109510961097109810991100110111021103110411051106110711081109111011111112111311141115111611171118111911201121112211231124112511261127112811291130113111321133113411351136113711381139114011411142114311441145114611471148114911501151115211531154115511561157115811591160116111621163116411651166116711681169117011711172117311741175117611771178117911801181118211831184118511861187118811891190119111921193119411951196119711981199120012011202120312041205120612071208120912101211121212131214121512161217121812191220122112221223122412251226122712281229123012311232123312341235123612371238123912401241124212431244124512461247124812491250125112521253125412551256125712581259126012611262126312641265126612671268126912701271127212731274127512761277127812791280128112821283128412851286128712881289129012911292129312941295129612971298129913001301130213031304130513061307130813091310131113121313131413151316131713181319132013211322132313241325132613271328132913301331133213331334133513361337133813391340134113421343134413451346134713481349135013511352135313541355135613571358135913601361136213631364136513661367136813691370137113721373137413751376137713781379138013811382138313841385138613871388138913901391139213931394139513961397139813991400140114021403140414051406140714081409141014111412141314141415141614171418141914201421142214231424142514261427142814291430143114321433143414351436143714381439144014411442144314441445144614471448144914501451145214531454145514561457145814591460146114621463146414651466146714681469147014711472147314741475147614771478147914801481148214831484148514861487148814891490149114921493149414951496149714981499150015011502150315041505150615071508150915101511151215131514151515161517151815191520152115221523152415251526152715281529153015311532153315341535153615371538153915401541154215431544154515461547154815491550155115521553155415551556155715581559156015611562156315641565156615671568156915701571157215731574157515761577157815791580158115821583158415851586158715881589159015911592159315941595159615971598159916001601160216031604160516061607160816091610161116121613161416151616161716181619162016211622162316241625162616271628162916301631163216331634163516361637163816391640164116421643164416451646164716481649165016511652165316541655165616571658165916601661166216631664166516661667166816691670167116721673167416751676167716781679168016811682168316841685168616871688168916901691169216931694169516961697169816991700170117021703170417051706170717081709171017111712171317141715171617171718171917201721172217231724172517261727172817291730173117321733173417351736173717381739174017411742174317441745174617471748174917501751175217531754175517561757175817591760176117621763176417651766176717681769177017711772177317741775177617771778177917801781178217831784178517861787178817891790179117921793179417951796179717981799180018011802180318041805180618071808180918101811181218131814181518161817181818191820182118221823182418251826182718281829183018311832183318341835183618371838183918401841184218431844184518461847184818491850185118521853185418551856185718581859186018611862186318641865186618671868186918701871187218731874187518761877187818791880188118821883188418851886188718881889189018911892189318941895189618971898189919001901190219031904190519061907190819091910191119121913191419151916191719181919192019211922192319241925192619271928192919301931193219331934193519361937193819391940194119421943194419451946194719481949195019511952195319541955195619571958195919601961196219631964196519661967196819691970197119721973197419751976197719781979198019811982198319841985198619871988198919901991199219931994199519961997199819992000200120022003200420052006200720082009201020112012201320142015201620172018201920202021202220232024202520262027202820292030203120322033203420352036203720382039204020412042204320442045204620472048204920502051205220532054205520562057205820592060206120622063206420652066206720682069207020712072207320742075207620772078207920802081208220832084208520862087208820892090209120922093209420952096209720982099210021012102210321042105210621072108210921102111211221132114211521162117211821192120212121222123212421252126212721282129213021312132213321342135213621372138213921402141214221432144214521462147214821492150215121522153215421552156215721582159216021612162216321642165216621672168216921702171217221732174217521762177217821792180218121822183218421852186218721882189219021912192219321942195219621972198219922002201220222032204220522062207220822092210221122122213221422152216221722182219222022212222222322242225222622272228222922302231223222332234223522362237223822392240224122422243224422452246224722482249225022512252225322542255225622572258225922602261226222632264226522662267226822692270227122722273227422752276227722782279228022812282228322842285228622872288228922902291229222932294229522962297229822992300230123022303230423052306230723082309231023112312231323142315231623172318231923202321232223232324232523262327232823292330233123322333233423352336233723382339234023412342234323442345234623472348234923502351235223532354235523562357235823592360236123622363236423652366236723682369237023712372237323742375237623772378237923802381238223832384238523862387238823892390239123922393239423952396239723982399240024012402240324042405240624072408240924102411241224132414241524162417241824192420242124222423242424252426242724282429243024312432243324342435243624372438243924402441244224432444244524462447244824492450245124522453245424552456245724582459246024612462246324642465246624672468246924702471247224732474247524762477247824792480248124822483248424852486248724882489249024912492249324942495249624972498249925002501250225032504250525062507250825092510251125122513251425152516251725182519252025212522252325242525252625272528252925302531253225332534253525362537253825392540254125422543254425452546254725482549255025512552255325542555255625572558255925602561256225632564256525662567256825692570257125722573257425752576257725782579258025812582258325842585258625872588258925902591259225932594259525962597259825992600260126022603260426052606260726082609261026112612261326142615261626172618261926202621262226232624262526262627262826292630263126322633263426352636263726382639264026412642264326442645264626472648264926502651265226532654265526562657265826592660266126622663266426652666266726682669267026712672267326742675267626772678267926802681268226832684268526862687268826892690269126922693269426952696269726982699270027012702270327042705270627072708270927102711271227132714271527162717271827192720272127222723272427252726272727282729273027312732273327342735273627372738273927402741274227432744274527462747274827492750275127522753275427552756275727582759276027612762276327642765276627672768276927702771277227732774277527762777277827792780278127822783278427852786278727882789279027912792279327942795279627972798279928002801280228032804280528062807280828092810281128122813281428152816281728182819282028212822282328242825282628272828282928302831283228332834283528362837283828392840284128422843284428452846284728482849285028512852285328542855285628572858285928602861286228632864286528662867286828692870287128722873287428752876287728782879288028812882288328842885288628872888288928902891289228932894289528962897289828992900290129022903290429052906290729082909291029112912291329142915291629172918291929202921292229232924292529262927292829292930293129322933293429352936293729382939294029412942294329442945294629472948294929502951295229532954295529562957295829592960296129622963296429652966296729682969297029712972297329742975297629772978297929802981298229832984298529862987298829892990299129922993299429952996299729982999300030013002300330043005300630073008300930103011301230133014301530163017301830193020302130223023302430253026302730283029303030313032303330343035303630373038303930403041304230433044304530463047304830493050305130523053305430553056305730583059306030613062306330643065306630673068306930703071307230733074307530763077307830793080308130823083308430853086308730883089309030913092309330943095309630973098309931003101310231033104310531063107310831093110311131123113311431153116311731183119312031213122312331243125312631273128312931303131313231333134313531363137313831393140314131423143314431453146314731483149315031513152315331543155315631573158315931603161316231633164316531663167316831693170317131723173317431753176317731783179318031813182318331843185318631873188318931903191319231933194319531963197319831993200320132023203320432053206320732083209321032113212321332143215321632173218321932203221322232233224322532263227322832293230323132323233323432353236323732383239324032413242324332443245324632473248324932503251325232533254325532563257325832593260326132623263326432653266326732683269327032713272327332743275327632773278327932803281328232833284328532863287328832893290329132923293329432953296329732983299330033013302330333043305330633073308330933103311331233133314331533163317331833193320332133223323332433253326332733283329333033313332333333343335333633373338333933403341334233433344334533463347334833493350335133523353335433553356335733583359336033613362336333643365336633673368336933703371337233733374337533763377337833793380338133823383338433853386338733883389339033913392339333943395339633973398339934003401340234033404340534063407340834093410341134123413341434153416341734183419342034213422342334243425342634273428342934303431343234333434343534363437343834393440344134423443344434453446344734483449345034513452345334543455345634573458345934603461346234633464346534663467346834693470347134723473347434753476347734783479348034813482348334843485348634873488348934903491349234933494349534963497349834993500350135023503350435053506350735083509351035113512351335143515351635173518351935203521352235233524352535263527352835293530353135323533353435353536353735383539354035413542354335443545354635473548354935503551355235533554355535563557355835593560356135623563356435653566356735683569357035713572357335743575357635773578357935803581358235833584358535863587358835893590359135923593359435953596359735983599360036013602360336043605360636073608360936103611361236133614361536163617361836193620362136223623362436253626362736283629363036313632363336343635363636373638363936403641364236433644364536463647364836493650365136523653365436553656365736583659366036613662366336643665366636673668366936703671367236733674367536763677367836793680368136823683368436853686368736883689369036913692369336943695369636973698369937003701370237033704370537063707370837093710371137123713371437153716371737183719372037213722372337243725372637273728372937303731373237333734373537363737373837393740374137423743374437453746374737483749375037513752375337543755375637573758375937603761376237633764376537663767376837693770377137723773377437753776377737783779378037813782378337843785378637873788378937903791379237933794379537963797379837993800380138023803380438053806380738083809381038113812381338143815381638173818381938203821382238233824382538263827382838293830383138323833383438353836383738383839384038413842384338443845384638473848384938503851385238533854385538563857385838593860386138623863386438653866386738683869387038713872387338743875387638773878387938803881388238833884388538863887388838893890389138923893389438953896389738983899390039013902390339043905390639073908390939103911391239133914391539163917391839193920392139223923392439253926392739283929393039313932393339343935393639373938393939403941394239433944394539463947394839493950395139523953395439553956395739583959396039613962396339643965396639673968396939703971397239733974397539763977397839793980398139823983398439853986398739883989399039913992399339943995399639973998399940004001400240034004400540064007400840094010401140124013401440154016401740184019402040214022402340244025402640274028402940304031403240334034403540364037403840394040404140424043404440454046404740484049405040514052405340544055405640574058405940604061406240634064406540664067406840694070407140724073407440754076407740784079408040814082408340844085408640874088408940904091409240934094409540964097409840994100410141024103410441054106410741084109411041114112411341144115411641174118411941204121412241234124412541264127412841294130413141324133413441354136413741384139414041414142414341444145414641474148414941504151415241534154415541564157415841594160416141624163416441654166416741684169417041714172417341744175417641774178417941804181418241834184418541864187418841894190419141924193419441954196419741984199420042014202420342044205420642074208420942104211421242134214421542164217421842194220422142224223422442254226422742284229423042314232423342344235423642374238423942404241424242434244424542464247424842494250425142524253425442554256425742584259426042614262426342644265426642674268426942704271427242734274427542764277427842794280428142824283428442854286428742884289429042914292429342944295429642974298429943004301430243034304430543064307430843094310431143124313431443154316431743184319432043214322432343244325432643274328432943304331433243334334433543364337433843394340434143424343434443454346434743484349435043514352435343544355435643574358435943604361436243634364436543664367436843694370437143724373437443754376437743784379438043814382438343844385438643874388438943904391439243934394439543964397439843994400440144024403440444054406440744084409441044114412441344144415441644174418441944204421442244234424442544264427442844294430443144324433443444354436443744384439444044414442444344444445444644474448444944504451445244534454445544564457445844594460446144624463446444654466446744684469447044714472447344744475447644774478447944804481448244834484448544864487448844894490449144924493449444954496449744984499450045014502450345044505450645074508450945104511451245134514451545164517451845194520452145224523452445254526452745284529453045314532453345344535453645374538453945404541454245434544454545464547454845494550455145524553455445554556455745584559456045614562456345644565456645674568456945704571457245734574457545764577457845794580458145824583458445854586458745884589459045914592459345944595459645974598459946004601460246034604460546064607460846094610461146124613461446154616461746184619462046214622462346244625462646274628462946304631463246334634463546364637463846394640464146424643464446454646464746484649465046514652465346544655465646574658465946604661466246634664466546664667466846694670467146724673467446754676467746784679468046814682468346844685468646874688468946904691469246934694469546964697469846994700470147024703470447054706470747084709471047114712471347144715471647174718471947204721472247234724472547264727472847294730473147324733473447354736473747384739474047414742474347444745474647474748474947504751475247534754475547564757475847594760476147624763476447654766476747684769477047714772477347744775477647774778477947804781478247834784478547864787478847894790479147924793479447954796479747984799480048014802480348044805480648074808480948104811481248134814481548164817481848194820482148224823482448254826482748284829483048314832483348344835483648374838483948404841484248434844484548464847484848494850485148524853485448554856485748584859486048614862486348644865486648674868486948704871487248734874487548764877487848794880488148824883488448854886488748884889489048914892489348944895489648974898489949004901490249034904490549064907490849094910491149124913491449154916491749184919492049214922492349244925492649274928492949304931493249334934493549364937493849394940494149424943494449454946494749484949495049514952495349544955495649574958495949604961496249634964496549664967496849694970497149724973497449754976497749784979498049814982498349844985498649874988498949904991499249934994499549964997499849995000500150025003500450055006500750085009501050115012501350145015501650175018501950205021502250235024502550265027502850295030503150325033503450355036503750385039504050415042504350445045504650475048504950505051505250535054505550565057505850595060506150625063506450655066506750685069507050715072507350745075507650775078507950805081508250835084508550865087508850895090509150925093509450955096509750985099510051015102510351045105510651075108510951105111511251135114511551165117511851195120512151225123512451255126512751285129513051315132513351345135513651375138513951405141514251435144514551465147514851495150515151525153515451555156515751585159516051615162516351645165516651675168516951705171517251735174517551765177517851795180518151825183518451855186518751885189519051915192519351945195519651975198519952005201520252035204520552065207520852095210521152125213521452155216521752185219522052215222522352245225522652275228522952305231523252335234523552365237523852395240524152425243524452455246524752485249525052515252525352545255525652575258525952605261526252635264526552665267526852695270527152725273527452755276527752785279528052815282528352845285528652875288528952905291529252935294529552965297529852995300530153025303530453055306530753085309531053115312531353145315531653175318531953205321532253235324532553265327532853295330533153325333533453355336533753385339534053415342534353445345534653475348534953505351535253535354535553565357535853595360536153625363536453655366536753685369537053715372537353745375537653775378537953805381538253835384538553865387538853895390539153925393539453955396539753985399540054015402540354045405540654075408540954105411541254135414541554165417541854195420542154225423542454255426542754285429543054315432543354345435543654375438
  1. /*
  2. proj4js.js -- Javascript reprojection library.
  3. Authors: Mike Adair madairATdmsolutions.ca
  4. Richard Greenwood richATgreenwoodmap.com
  5. Didier Richard didier.richardATign.fr
  6. Stephen Irons stephen.ironsATclear.net.nz
  7. Olivier Terral oterralATgmail.com
  8. License:
  9. Copyright (c) 2012, Mike Adair, Richard Greenwood, Didier Richard,
  10. Stephen Irons and Olivier Terral
  11. Permission is hereby granted, free of charge, to any person obtaining a
  12. copy of this software and associated documentation files (the "Software"),
  13. to deal in the Software without restriction, including without limitation
  14. the rights to use, copy, modify, merge, publish, distribute, sublicense,
  15. and/or sell copies of the Software, and to permit persons to whom the
  16. Software is furnished to do so, subject to the following conditions:
  17. The above copyright notice and this permission notice shall be included
  18. in all copies or substantial portions of the Software.
  19. THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS
  20. OR IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
  21. FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL
  22. THE AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER
  23. LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING
  24. FROM, OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER
  25. DEALINGS IN THE SOFTWARE.
  26. Note: This program is an almost direct port of the C library PROJ.4.
  27. */
  28. /* ======================================================================
  29. proj4js.js
  30. ====================================================================== */
  31. /*
  32. Author: Mike Adair madairATdmsolutions.ca
  33. Richard Greenwood rich@greenwoodmap.com
  34. License: LGPL as per: http://www.gnu.org/copyleft/lesser.html
  35. $Id: Proj.js 2956 2007-07-09 12:17:52Z steven $
  36. */
  37. /**
  38. * Namespace: Proj4js
  39. *
  40. * Proj4js is a JavaScript library to transform point coordinates from one
  41. * coordinate system to another, including datum transformations.
  42. *
  43. * This library is a port of both the Proj.4 and GCTCP C libraries to JavaScript.
  44. * Enabling these transformations in the browser allows geographic data stored
  45. * in different projections to be combined in browser-based web mapping
  46. * applications.
  47. *
  48. * Proj4js must have access to coordinate system initialization strings (which
  49. * are the same as for PROJ.4 command line). Thes can be included in your
  50. * application using a <script> tag or Proj4js can load CS initialization
  51. * strings from a local directory or a web service such as spatialreference.org.
  52. *
  53. * Similarly, Proj4js must have access to projection transform code. These can
  54. * be included individually using a <script> tag in your page, built into a
  55. * custom build of Proj4js or loaded dynamically at run-time. Using the
  56. * -combined and -compressed versions of Proj4js includes all projection class
  57. * code by default.
  58. *
  59. * Note that dynamic loading of defs and code happens ascynchrously, check the
  60. * Proj.readyToUse flag before using the Proj object. If the defs and code
  61. * required by your application are loaded through script tags, dynamic loading
  62. * is not required and the Proj object will be readyToUse on return from the
  63. * constructor.
  64. *
  65. * All coordinates are handled as points which have a .x and a .y property
  66. * which will be modified in place.
  67. *
  68. * Override Proj4js.reportError for output of alerts and warnings.
  69. *
  70. * See http://trac.osgeo.org/proj4js/wiki/UserGuide for full details.
  71. */
  72. /**
  73. * Global namespace object for Proj4js library
  74. */
  75. var Proj4js = {
  76. /**
  77. * Property: defaultDatum
  78. * The datum to use when no others a specified
  79. */
  80. defaultDatum: 'WGS84', //default datum
  81. /**
  82. * Method: transform(source, dest, point)
  83. * Transform a point coordinate from one map projection to another. This is
  84. * really the only public method you should need to use.
  85. *
  86. * Parameters:
  87. * source - {Proj4js.Proj} source map projection for the transformation
  88. * dest - {Proj4js.Proj} destination map projection for the transformation
  89. * point - {Object} point to transform, may be geodetic (long, lat) or
  90. * projected Cartesian (x,y), but should always have x,y properties.
  91. */
  92. transform: function(source, dest, point) {
  93. if (!source.readyToUse) {
  94. this.reportError("Proj4js initialization for:"+source.srsCode+" not yet complete");
  95. return point;
  96. }
  97. if (!dest.readyToUse) {
  98. this.reportError("Proj4js initialization for:"+dest.srsCode+" not yet complete");
  99. return point;
  100. }
  101. // Workaround for datum shifts towgs84, if either source or destination projection is not wgs84
  102. if (source.datum && dest.datum && (
  103. ((source.datum.datum_type == Proj4js.common.PJD_3PARAM || source.datum.datum_type == Proj4js.common.PJD_7PARAM) && dest.datumCode != "WGS84") ||
  104. ((dest.datum.datum_type == Proj4js.common.PJD_3PARAM || dest.datum.datum_type == Proj4js.common.PJD_7PARAM) && source.datumCode != "WGS84"))) {
  105. var wgs84 = Proj4js.WGS84;
  106. this.transform(source, wgs84, point);
  107. source = wgs84;
  108. }
  109. // DGR, 2010/11/12
  110. if (source.axis!="enu") {
  111. this.adjust_axis(source,false,point);
  112. }
  113. // Transform source points to long/lat, if they aren't already.
  114. if ( source.projName=="longlat") {
  115. point.x *= Proj4js.common.D2R; // convert degrees to radians
  116. point.y *= Proj4js.common.D2R;
  117. } else {
  118. if (source.to_meter) {
  119. point.x *= source.to_meter;
  120. point.y *= source.to_meter;
  121. }
  122. source.inverse(point); // Convert Cartesian to longlat
  123. }
  124. // Adjust for the prime meridian if necessary
  125. if (source.from_greenwich) {
  126. point.x += source.from_greenwich;
  127. }
  128. // Convert datums if needed, and if possible.
  129. point = this.datum_transform( source.datum, dest.datum, point );
  130. // Adjust for the prime meridian if necessary
  131. if (dest.from_greenwich) {
  132. point.x -= dest.from_greenwich;
  133. }
  134. if( dest.projName=="longlat" ) {
  135. // convert radians to decimal degrees
  136. point.x *= Proj4js.common.R2D;
  137. point.y *= Proj4js.common.R2D;
  138. } else { // else project
  139. dest.forward(point);
  140. if (dest.to_meter) {
  141. point.x /= dest.to_meter;
  142. point.y /= dest.to_meter;
  143. }
  144. }
  145. // DGR, 2010/11/12
  146. if (dest.axis!="enu") {
  147. this.adjust_axis(dest,true,point);
  148. }
  149. return point;
  150. }, // transform()
  151. /** datum_transform()
  152. source coordinate system definition,
  153. destination coordinate system definition,
  154. point to transform in geodetic coordinates (long, lat, height)
  155. */
  156. datum_transform : function( source, dest, point ) {
  157. // Short cut if the datums are identical.
  158. if( source.compare_datums( dest ) ) {
  159. return point; // in this case, zero is sucess,
  160. // whereas cs_compare_datums returns 1 to indicate TRUE
  161. // confusing, should fix this
  162. }
  163. // Explicitly skip datum transform by setting 'datum=none' as parameter for either source or dest
  164. if( source.datum_type == Proj4js.common.PJD_NODATUM
  165. || dest.datum_type == Proj4js.common.PJD_NODATUM) {
  166. return point;
  167. }
  168. // Do we need to go through geocentric coordinates?
  169. if( source.es != dest.es || source.a != dest.a
  170. || source.datum_type == Proj4js.common.PJD_3PARAM
  171. || source.datum_type == Proj4js.common.PJD_7PARAM
  172. || dest.datum_type == Proj4js.common.PJD_3PARAM
  173. || dest.datum_type == Proj4js.common.PJD_7PARAM)
  174. {
  175. // Convert to geocentric coordinates.
  176. source.geodetic_to_geocentric( point );
  177. // CHECK_RETURN;
  178. // Convert between datums
  179. if( source.datum_type == Proj4js.common.PJD_3PARAM || source.datum_type == Proj4js.common.PJD_7PARAM ) {
  180. source.geocentric_to_wgs84(point);
  181. // CHECK_RETURN;
  182. }
  183. if( dest.datum_type == Proj4js.common.PJD_3PARAM || dest.datum_type == Proj4js.common.PJD_7PARAM ) {
  184. dest.geocentric_from_wgs84(point);
  185. // CHECK_RETURN;
  186. }
  187. // Convert back to geodetic coordinates
  188. dest.geocentric_to_geodetic( point );
  189. // CHECK_RETURN;
  190. }
  191. return point;
  192. }, // cs_datum_transform
  193. /**
  194. * Function: adjust_axis
  195. * Normalize or de-normalized the x/y/z axes. The normal form is "enu"
  196. * (easting, northing, up).
  197. * Parameters:
  198. * crs {Proj4js.Proj} the coordinate reference system
  199. * denorm {Boolean} when false, normalize
  200. * point {Object} the coordinates to adjust
  201. */
  202. adjust_axis: function(crs, denorm, point) {
  203. var xin= point.x, yin= point.y, zin= point.z || 0.0;
  204. var v, t;
  205. for (var i= 0; i<3; i++) {
  206. if (denorm && i==2 && point.z===undefined) { continue; }
  207. if (i==0) { v= xin; t= 'x'; }
  208. else if (i==1) { v= yin; t= 'y'; }
  209. else { v= zin; t= 'z'; }
  210. switch(crs.axis[i]) {
  211. case 'e':
  212. point[t]= v;
  213. break;
  214. case 'w':
  215. point[t]= -v;
  216. break;
  217. case 'n':
  218. point[t]= v;
  219. break;
  220. case 's':
  221. point[t]= -v;
  222. break;
  223. case 'u':
  224. if (point[t]!==undefined) { point.z= v; }
  225. break;
  226. case 'd':
  227. if (point[t]!==undefined) { point.z= -v; }
  228. break;
  229. default :
  230. alert("ERROR: unknow axis ("+crs.axis[i]+") - check definition of "+crs.projName);
  231. return null;
  232. }
  233. }
  234. return point;
  235. },
  236. /**
  237. * Function: reportError
  238. * An internal method to report errors back to user.
  239. * Override this in applications to report error messages or throw exceptions.
  240. */
  241. reportError: function(msg) {
  242. //console.log(msg);
  243. },
  244. /**
  245. *
  246. * Title: Private Methods
  247. * The following properties and methods are intended for internal use only.
  248. *
  249. * This is a minimal implementation of JavaScript inheritance methods so that
  250. * Proj4js can be used as a stand-alone library.
  251. * These are copies of the equivalent OpenLayers methods at v2.7
  252. */
  253. /**
  254. * Function: extend
  255. * Copy all properties of a source object to a destination object. Modifies
  256. * the passed in destination object. Any properties on the source object
  257. * that are set to undefined will not be (re)set on the destination object.
  258. *
  259. * Parameters:
  260. * destination - {Object} The object that will be modified
  261. * source - {Object} The object with properties to be set on the destination
  262. *
  263. * Returns:
  264. * {Object} The destination object.
  265. */
  266. extend: function(destination, source) {
  267. destination = destination || {};
  268. if(source) {
  269. for(var property in source) {
  270. var value = source[property];
  271. if(value !== undefined) {
  272. destination[property] = value;
  273. }
  274. }
  275. }
  276. return destination;
  277. },
  278. /**
  279. * Constructor: Class
  280. * Base class used to construct all other classes. Includes support for
  281. * multiple inheritance.
  282. *
  283. */
  284. Class: function() {
  285. var Class = function() {
  286. this.initialize.apply(this, arguments);
  287. };
  288. var extended = {};
  289. var parent;
  290. for(var i=0; i<arguments.length; ++i) {
  291. if(typeof arguments[i] == "function") {
  292. // get the prototype of the superclass
  293. parent = arguments[i].prototype;
  294. } else {
  295. // in this case we're extending with the prototype
  296. parent = arguments[i];
  297. }
  298. Proj4js.extend(extended, parent);
  299. }
  300. Class.prototype = extended;
  301. return Class;
  302. },
  303. /**
  304. * Function: bind
  305. * Bind a function to an object. Method to easily create closures with
  306. * 'this' altered.
  307. *
  308. * Parameters:
  309. * func - {Function} Input function.
  310. * object - {Object} The object to bind to the input function (as this).
  311. *
  312. * Returns:
  313. * {Function} A closure with 'this' set to the passed in object.
  314. */
  315. bind: function(func, object) {
  316. // create a reference to all arguments past the second one
  317. var args = Array.prototype.slice.apply(arguments, [2]);
  318. return function() {
  319. // Push on any additional arguments from the actual function call.
  320. // These will come after those sent to the bind call.
  321. var newArgs = args.concat(
  322. Array.prototype.slice.apply(arguments, [0])
  323. );
  324. return func.apply(object, newArgs);
  325. };
  326. },
  327. /**
  328. * The following properties and methods handle dynamic loading of JSON objects.
  329. */
  330. /**
  331. * Property: scriptName
  332. * {String} The filename of this script without any path.
  333. */
  334. scriptName: "proj4js-combined.js",
  335. /**
  336. * Property: defsLookupService
  337. * AJAX service to retreive projection definition parameters from
  338. */
  339. defsLookupService: 'http://spatialreference.org/ref',
  340. /**
  341. * Property: libPath
  342. * internal: http server path to library code.
  343. */
  344. libPath: null,
  345. /**
  346. * Function: getScriptLocation
  347. * Return the path to this script.
  348. *
  349. * Returns:
  350. * Path to this script
  351. */
  352. getScriptLocation: function () {
  353. if (this.libPath) return this.libPath;
  354. var scriptName = this.scriptName;
  355. var scriptNameLen = scriptName.length;
  356. var scripts = document.getElementsByTagName('script');
  357. for (var i = 0; i < scripts.length; i++) {
  358. var src = scripts[i].getAttribute('src');
  359. if (src) {
  360. var index = src.lastIndexOf(scriptName);
  361. // is it found, at the end of the URL?
  362. if ((index > -1) && (index + scriptNameLen == src.length)) {
  363. this.libPath = src.slice(0, -scriptNameLen);
  364. break;
  365. }
  366. }
  367. }
  368. return this.libPath||"";
  369. },
  370. /**
  371. * Function: loadScript
  372. * Load a JS file from a URL into a <script> tag in the page.
  373. *
  374. * Parameters:
  375. * url - {String} The URL containing the script to load
  376. * onload - {Function} A method to be executed when the script loads successfully
  377. * onfail - {Function} A method to be executed when there is an error loading the script
  378. * loadCheck - {Function} A boolean method that checks to see if the script
  379. * has loaded. Typically this just checks for the existance of
  380. * an object in the file just loaded.
  381. */
  382. loadScript: function(url, onload, onfail, loadCheck) {
  383. var script = document.createElement('script');
  384. script.defer = false;
  385. script.type = "text/javascript";
  386. script.id = url;
  387. script.src = url;
  388. script.onload = onload;
  389. script.onerror = onfail;
  390. script.loadCheck = loadCheck;
  391. if (/MSIE/.test(navigator.userAgent)) {
  392. script.onreadystatechange = this.checkReadyState;
  393. }
  394. document.getElementsByTagName('head')[0].appendChild(script);
  395. },
  396. /**
  397. * Function: checkReadyState
  398. * IE workaround since there is no onerror handler. Calls the user defined
  399. * loadCheck method to determine if the script is loaded.
  400. *
  401. */
  402. checkReadyState: function() {
  403. if (this.readyState == 'loaded') {
  404. if (!this.loadCheck()) {
  405. this.onerror();
  406. } else {
  407. this.onload();
  408. }
  409. }
  410. }
  411. };
  412. /**
  413. * Class: Proj4js.Proj
  414. *
  415. * Proj objects provide transformation methods for point coordinates
  416. * between geodetic latitude/longitude and a projected coordinate system.
  417. * once they have been initialized with a projection code.
  418. *
  419. * Initialization of Proj objects is with a projection code, usually EPSG codes,
  420. * which is the key that will be used with the Proj4js.defs array.
  421. *
  422. * The code passed in will be stripped of colons and converted to uppercase
  423. * to locate projection definition files.
  424. *
  425. * A projection object has properties for units and title strings.
  426. */
  427. Proj4js.Proj = Proj4js.Class({
  428. /**
  429. * Property: readyToUse
  430. * Flag to indicate if initialization is complete for this Proj object
  431. */
  432. readyToUse: false,
  433. /**
  434. * Property: title
  435. * The title to describe the projection
  436. */
  437. title: null,
  438. /**
  439. * Property: projName
  440. * The projection class for this projection, e.g. lcc (lambert conformal conic,
  441. * or merc for mercator). These are exactly equivalent to their Proj4
  442. * counterparts.
  443. */
  444. projName: null,
  445. /**
  446. * Property: units
  447. * The units of the projection. Values include 'm' and 'degrees'
  448. */
  449. units: null,
  450. /**
  451. * Property: datum
  452. * The datum specified for the projection
  453. */
  454. datum: null,
  455. /**
  456. * Property: x0
  457. * The x coordinate origin
  458. */
  459. x0: 0,
  460. /**
  461. * Property: y0
  462. * The y coordinate origin
  463. */
  464. y0: 0,
  465. /**
  466. * Property: localCS
  467. * Flag to indicate if the projection is a local one in which no transforms
  468. * are required.
  469. */
  470. localCS: false,
  471. /**
  472. * Property: queue
  473. * Buffer (FIFO) to hold callbacks waiting to be called when projection loaded.
  474. */
  475. queue: null,
  476. /**
  477. * Constructor: initialize
  478. * Constructor for Proj4js.Proj objects
  479. *
  480. * Parameters:
  481. * srsCode - a code for map projection definition parameters. These are usually
  482. * (but not always) EPSG codes.
  483. */
  484. initialize: function(srsCode, callback) {
  485. this.srsCodeInput = srsCode;
  486. //Register callbacks prior to attempting to process definition
  487. this.queue = [];
  488. if( callback ){
  489. this.queue.push( callback );
  490. }
  491. //check to see if this is a WKT string
  492. if ((srsCode.indexOf('GEOGCS') >= 0) ||
  493. (srsCode.indexOf('GEOCCS') >= 0) ||
  494. (srsCode.indexOf('PROJCS') >= 0) ||
  495. (srsCode.indexOf('LOCAL_CS') >= 0)) {
  496. this.parseWKT(srsCode);
  497. this.deriveConstants();
  498. this.loadProjCode(this.projName);
  499. return;
  500. }
  501. // DGR 2008-08-03 : support urn and url
  502. if (srsCode.indexOf('urn:') == 0) {
  503. //urn:ORIGINATOR:def:crs:CODESPACE:VERSION:ID
  504. var urn = srsCode.split(':');
  505. if ((urn[1] == 'ogc' || urn[1] =='x-ogc') &&
  506. (urn[2] =='def') &&
  507. (urn[3] =='crs')) {
  508. srsCode = urn[4]+':'+urn[urn.length-1];
  509. }
  510. } else if (srsCode.indexOf('http://') == 0) {
  511. //url#ID
  512. var url = srsCode.split('#');
  513. if (url[0].match(/epsg.org/)) {
  514. // http://www.epsg.org/#
  515. srsCode = 'EPSG:'+url[1];
  516. } else if (url[0].match(/RIG.xml/)) {
  517. //http://librairies.ign.fr/geoportail/resources/RIG.xml#
  518. //http://interop.ign.fr/registers/ign/RIG.xml#
  519. srsCode = 'IGNF:'+url[1];
  520. }
  521. }
  522. this.srsCode = srsCode.toUpperCase();
  523. if (this.srsCode.indexOf("EPSG") == 0) {
  524. this.srsCode = this.srsCode;
  525. this.srsAuth = 'epsg';
  526. this.srsProjNumber = this.srsCode.substring(5);
  527. // DGR 2007-11-20 : authority IGNF
  528. } else if (this.srsCode.indexOf("IGNF") == 0) {
  529. this.srsCode = this.srsCode;
  530. this.srsAuth = 'IGNF';
  531. this.srsProjNumber = this.srsCode.substring(5);
  532. // DGR 2008-06-19 : pseudo-authority CRS for WMS
  533. } else if (this.srsCode.indexOf("CRS") == 0) {
  534. this.srsCode = this.srsCode;
  535. this.srsAuth = 'CRS';
  536. this.srsProjNumber = this.srsCode.substring(4);
  537. } else {
  538. this.srsAuth = '';
  539. this.srsProjNumber = this.srsCode;
  540. }
  541. this.loadProjDefinition();
  542. },
  543. /**
  544. * Function: loadProjDefinition
  545. * Loads the coordinate system initialization string if required.
  546. * Note that dynamic loading happens asynchronously so an application must
  547. * wait for the readyToUse property is set to true.
  548. * To prevent dynamic loading, include the defs through a script tag in
  549. * your application.
  550. *
  551. */
  552. loadProjDefinition: function() {
  553. //check in memory
  554. if (Proj4js.defs[this.srsCode]) {
  555. this.defsLoaded();
  556. return;
  557. }
  558. //else check for def on the server
  559. var url = Proj4js.getScriptLocation() + 'defs/' + this.srsAuth.toUpperCase() + this.srsProjNumber + '.js';
  560. Proj4js.loadScript(url,
  561. Proj4js.bind(this.defsLoaded, this),
  562. Proj4js.bind(this.loadFromService, this),
  563. Proj4js.bind(this.checkDefsLoaded, this) );
  564. },
  565. /**
  566. * Function: loadFromService
  567. * Creates the REST URL for loading the definition from a web service and
  568. * loads it.
  569. *
  570. */
  571. loadFromService: function() {
  572. //else load from web service
  573. var url = Proj4js.defsLookupService +'/' + this.srsAuth +'/'+ this.srsProjNumber + '/proj4js/';
  574. Proj4js.loadScript(url,
  575. Proj4js.bind(this.defsLoaded, this),
  576. Proj4js.bind(this.defsFailed, this),
  577. Proj4js.bind(this.checkDefsLoaded, this) );
  578. },
  579. /**
  580. * Function: defsLoaded
  581. * Continues the Proj object initilization once the def file is loaded
  582. *
  583. */
  584. defsLoaded: function() {
  585. this.parseDefs();
  586. this.loadProjCode(this.projName);
  587. },
  588. /**
  589. * Function: checkDefsLoaded
  590. * This is the loadCheck method to see if the def object exists
  591. *
  592. */
  593. checkDefsLoaded: function() {
  594. if (Proj4js.defs[this.srsCode]) {
  595. return true;
  596. } else {
  597. return false;
  598. }
  599. },
  600. /**
  601. * Function: defsFailed
  602. * Report an error in loading the defs file, but continue on using WGS84
  603. *
  604. */
  605. defsFailed: function() {
  606. Proj4js.reportError('failed to load projection definition for: '+this.srsCode);
  607. Proj4js.defs[this.srsCode] = Proj4js.defs['WGS84']; //set it to something so it can at least continue
  608. this.defsLoaded();
  609. },
  610. /**
  611. * Function: loadProjCode
  612. * Loads projection class code dynamically if required.
  613. * Projection code may be included either through a script tag or in
  614. * a built version of proj4js
  615. *
  616. */
  617. loadProjCode: function(projName) {
  618. if (Proj4js.Proj[projName]) {
  619. this.initTransforms();
  620. return;
  621. }
  622. //the URL for the projection code
  623. var url = Proj4js.getScriptLocation() + 'projCode/' + projName + '.js';
  624. Proj4js.loadScript(url,
  625. Proj4js.bind(this.loadProjCodeSuccess, this, projName),
  626. Proj4js.bind(this.loadProjCodeFailure, this, projName),
  627. Proj4js.bind(this.checkCodeLoaded, this, projName) );
  628. },
  629. /**
  630. * Function: loadProjCodeSuccess
  631. * Loads any proj dependencies or continue on to final initialization.
  632. *
  633. */
  634. loadProjCodeSuccess: function(projName) {
  635. if (Proj4js.Proj[projName].dependsOn){
  636. this.loadProjCode(Proj4js.Proj[projName].dependsOn);
  637. } else {
  638. this.initTransforms();
  639. }
  640. },
  641. /**
  642. * Function: defsFailed
  643. * Report an error in loading the proj file. Initialization of the Proj
  644. * object has failed and the readyToUse flag will never be set.
  645. *
  646. */
  647. loadProjCodeFailure: function(projName) {
  648. Proj4js.reportError("failed to find projection file for: " + projName);
  649. //TBD initialize with identity transforms so proj will still work?
  650. },
  651. /**
  652. * Function: checkCodeLoaded
  653. * This is the loadCheck method to see if the projection code is loaded
  654. *
  655. */
  656. checkCodeLoaded: function(projName) {
  657. if (Proj4js.Proj[projName]) {
  658. return true;
  659. } else {
  660. return false;
  661. }
  662. },
  663. /**
  664. * Function: initTransforms
  665. * Finalize the initialization of the Proj object
  666. *
  667. */
  668. initTransforms: function() {
  669. Proj4js.extend(this, Proj4js.Proj[this.projName]);
  670. this.init();
  671. this.readyToUse = true;
  672. if( this.queue ) {
  673. var item;
  674. while( (item = this.queue.shift()) ) {
  675. item.call( this, this );
  676. }
  677. }
  678. },
  679. /**
  680. * Function: parseWKT
  681. * Parses a WKT string to get initialization parameters
  682. *
  683. */
  684. wktRE: /^(\w+)\[(.*)\]$/,
  685. parseWKT: function(wkt) {
  686. var wktMatch = wkt.match(this.wktRE);
  687. if (!wktMatch) return;
  688. var wktObject = wktMatch[1];
  689. var wktContent = wktMatch[2];
  690. var wktTemp = wktContent.split(",");
  691. var wktName;
  692. if (wktObject.toUpperCase() == "TOWGS84") {
  693. wktName = wktObject; //no name supplied for the TOWGS84 array
  694. } else {
  695. wktName = wktTemp.shift();
  696. }
  697. wktName = wktName.replace(/^\"/,"");
  698. wktName = wktName.replace(/\"$/,"");
  699. /*
  700. wktContent = wktTemp.join(",");
  701. var wktArray = wktContent.split("],");
  702. for (var i=0; i<wktArray.length-1; ++i) {
  703. wktArray[i] += "]";
  704. }
  705. */
  706. var wktArray = new Array();
  707. var bkCount = 0;
  708. var obj = "";
  709. for (var i=0; i<wktTemp.length; ++i) {
  710. var token = wktTemp[i];
  711. for (var j=0; j<token.length; ++j) {
  712. if (token.charAt(j) == "[") ++bkCount;
  713. if (token.charAt(j) == "]") --bkCount;
  714. }
  715. obj += token;
  716. if (bkCount === 0) {
  717. wktArray.push(obj);
  718. obj = "";
  719. } else {
  720. obj += ",";
  721. }
  722. }
  723. //do something based on the type of the wktObject being parsed
  724. //add in variations in the spelling as required
  725. switch (wktObject) {
  726. case 'LOCAL_CS':
  727. this.projName = 'identity'
  728. this.localCS = true;
  729. this.srsCode = wktName;
  730. break;
  731. case 'GEOGCS':
  732. this.projName = 'longlat'
  733. this.geocsCode = wktName;
  734. if (!this.srsCode) this.srsCode = wktName;
  735. break;
  736. case 'PROJCS':
  737. this.srsCode = wktName;
  738. break;
  739. case 'GEOCCS':
  740. break;
  741. case 'PROJECTION':
  742. this.projName = Proj4js.wktProjections[wktName]
  743. break;
  744. case 'DATUM':
  745. this.datumName = wktName;
  746. break;
  747. case 'LOCAL_DATUM':
  748. this.datumCode = 'none';
  749. break;
  750. case 'SPHEROID':
  751. this.ellps = wktName;
  752. this.a = parseFloat(wktArray.shift());
  753. this.rf = parseFloat(wktArray.shift());
  754. break;
  755. case 'PRIMEM':
  756. this.from_greenwich = parseFloat(wktArray.shift()); //to radians?
  757. break;
  758. case 'UNIT':
  759. this.units = wktName;
  760. this.unitsPerMeter = parseFloat(wktArray.shift());
  761. break;
  762. case 'PARAMETER':
  763. var name = wktName.toLowerCase();
  764. var value = parseFloat(wktArray.shift());
  765. //there may be many variations on the wktName values, add in case
  766. //statements as required
  767. switch (name) {
  768. case 'false_easting':
  769. this.x0 = value;
  770. break;
  771. case 'false_northing':
  772. this.y0 = value;
  773. break;
  774. case 'scale_factor':
  775. this.k0 = value;
  776. break;
  777. case 'central_meridian':
  778. this.long0 = value*Proj4js.common.D2R;
  779. break;
  780. case 'latitude_of_origin':
  781. this.lat0 = value*Proj4js.common.D2R;
  782. break;
  783. case 'more_here':
  784. break;
  785. default:
  786. break;
  787. }
  788. break;
  789. case 'TOWGS84':
  790. this.datum_params = wktArray;
  791. break;
  792. //DGR 2010-11-12: AXIS
  793. case 'AXIS':
  794. var name= wktName.toLowerCase();
  795. var value= wktArray.shift();
  796. switch (value) {
  797. case 'EAST' : value= 'e'; break;
  798. case 'WEST' : value= 'w'; break;
  799. case 'NORTH': value= 'n'; break;
  800. case 'SOUTH': value= 's'; break;
  801. case 'UP' : value= 'u'; break;
  802. case 'DOWN' : value= 'd'; break;
  803. case 'OTHER':
  804. default : value= ' '; break;//FIXME
  805. }
  806. if (!this.axis) { this.axis= "enu"; }
  807. switch(name) {
  808. case 'x': this.axis= value + this.axis.substr(1,2); break;
  809. case 'y': this.axis= this.axis.substr(0,1) + value + this.axis.substr(2,1); break;
  810. case 'z': this.axis= this.axis.substr(0,2) + value ; break;
  811. default : break;
  812. }
  813. case 'MORE_HERE':
  814. break;
  815. default:
  816. break;
  817. }
  818. for (var i=0; i<wktArray.length; ++i) {
  819. this.parseWKT(wktArray[i]);
  820. }
  821. },
  822. /**
  823. * Function: parseDefs
  824. * Parses the PROJ.4 initialization string and sets the associated properties.
  825. *
  826. */
  827. parseDefs: function() {
  828. this.defData = Proj4js.defs[this.srsCode];
  829. var paramName, paramVal;
  830. if (!this.defData) {
  831. return;
  832. }
  833. var paramArray=this.defData.split("+");
  834. for (var prop=0; prop<paramArray.length; prop++) {
  835. var property = paramArray[prop].split("=");
  836. paramName = property[0].toLowerCase();
  837. paramVal = property[1];
  838. switch (paramName.replace(/\s/gi,"")) { // trim out spaces
  839. case "": break; // throw away nameless parameter
  840. case "title": this.title = paramVal; break;
  841. case "proj": this.projName = paramVal.replace(/\s/gi,""); break;
  842. case "units": this.units = paramVal.replace(/\s/gi,""); break;
  843. case "datum": this.datumCode = paramVal.replace(/\s/gi,""); break;
  844. case "nadgrids": this.nagrids = paramVal.replace(/\s/gi,""); break;
  845. case "ellps": this.ellps = paramVal.replace(/\s/gi,""); break;
  846. case "a": this.a = parseFloat(paramVal); break; // semi-major radius
  847. case "b": this.b = parseFloat(paramVal); break; // semi-minor radius
  848. // DGR 2007-11-20
  849. case "rf": this.rf = parseFloat(paramVal); break; // inverse flattening rf= a/(a-b)
  850. case "lat_0": this.lat0 = paramVal*Proj4js.common.D2R; break; // phi0, central latitude
  851. case "lat_1": this.lat1 = paramVal*Proj4js.common.D2R; break; //standard parallel 1
  852. case "lat_2": this.lat2 = paramVal*Proj4js.common.D2R; break; //standard parallel 2
  853. case "lat_ts": this.lat_ts = paramVal*Proj4js.common.D2R; break; // used in merc and eqc
  854. case "lon_0": this.long0 = paramVal*Proj4js.common.D2R; break; // lam0, central longitude
  855. case "alpha": this.alpha = parseFloat(paramVal)*Proj4js.common.D2R; break; //for somerc projection
  856. case "lonc": this.longc = paramVal*Proj4js.common.D2R; break; //for somerc projection
  857. case "x_0": this.x0 = parseFloat(paramVal); break; // false easting
  858. case "y_0": this.y0 = parseFloat(paramVal); break; // false northing
  859. case "k_0": this.k0 = parseFloat(paramVal); break; // projection scale factor
  860. case "k": this.k0 = parseFloat(paramVal); break; // both forms returned
  861. case "r_a": this.R_A = true; break; // sphere--area of ellipsoid
  862. case "zone": this.zone = parseInt(paramVal,10); break; // UTM Zone
  863. case "south": this.utmSouth = true; break; // UTM north/south
  864. case "towgs84":this.datum_params = paramVal.split(","); break;
  865. case "to_meter": this.to_meter = parseFloat(paramVal); break; // cartesian scaling
  866. case "from_greenwich": this.from_greenwich = paramVal*Proj4js.common.D2R; break;
  867. // DGR 2008-07-09 : if pm is not a well-known prime meridian take
  868. // the value instead of 0.0, then convert to radians
  869. case "pm": paramVal = paramVal.replace(/\s/gi,"");
  870. this.from_greenwich = Proj4js.PrimeMeridian[paramVal] ?
  871. Proj4js.PrimeMeridian[paramVal] : parseFloat(paramVal);
  872. this.from_greenwich *= Proj4js.common.D2R;
  873. break;
  874. // DGR 2010-11-12: axis
  875. case "axis": paramVal = paramVal.replace(/\s/gi,"");
  876. var legalAxis= "ewnsud";
  877. if (paramVal.length==3 &&
  878. legalAxis.indexOf(paramVal.substr(0,1))!=-1 &&
  879. legalAxis.indexOf(paramVal.substr(1,1))!=-1 &&
  880. legalAxis.indexOf(paramVal.substr(2,1))!=-1) {
  881. this.axis= paramVal;
  882. } //FIXME: be silent ?
  883. break
  884. case "no_defs": break;
  885. default: //alert("Unrecognized parameter: " + paramName);
  886. } // switch()
  887. } // for paramArray
  888. this.deriveConstants();
  889. },
  890. /**
  891. * Function: deriveConstants
  892. * Sets several derived constant values and initialization of datum and ellipse
  893. * parameters.
  894. *
  895. */
  896. deriveConstants: function() {
  897. if (this.nagrids == '@null') this.datumCode = 'none';
  898. if (this.datumCode && this.datumCode != 'none') {
  899. var datumDef = Proj4js.Datum[this.datumCode];
  900. if (datumDef) {
  901. this.datum_params = datumDef.towgs84 ? datumDef.towgs84.split(',') : null;
  902. this.ellps = datumDef.ellipse;
  903. this.datumName = datumDef.datumName ? datumDef.datumName : this.datumCode;
  904. }
  905. }
  906. if (!this.a) { // do we have an ellipsoid?
  907. var ellipse = Proj4js.Ellipsoid[this.ellps] ? Proj4js.Ellipsoid[this.ellps] : Proj4js.Ellipsoid['WGS84'];
  908. Proj4js.extend(this, ellipse);
  909. }
  910. if (this.rf && !this.b) this.b = (1.0 - 1.0/this.rf) * this.a;
  911. if (this.rf === 0 || Math.abs(this.a - this.b)<Proj4js.common.EPSLN) {
  912. this.sphere = true;
  913. this.b= this.a;
  914. }
  915. this.a2 = this.a * this.a; // used in geocentric
  916. this.b2 = this.b * this.b; // used in geocentric
  917. this.es = (this.a2-this.b2)/this.a2; // e ^ 2
  918. this.e = Math.sqrt(this.es); // eccentricity
  919. if (this.R_A) {
  920. this.a *= 1. - this.es * (Proj4js.common.SIXTH + this.es * (Proj4js.common.RA4 + this.es * Proj4js.common.RA6));
  921. this.a2 = this.a * this.a;
  922. this.b2 = this.b * this.b;
  923. this.es = 0.;
  924. }
  925. this.ep2=(this.a2-this.b2)/this.b2; // used in geocentric
  926. if (!this.k0) this.k0 = 1.0; //default value
  927. //DGR 2010-11-12: axis
  928. if (!this.axis) { this.axis= "enu"; }
  929. this.datum = new Proj4js.datum(this);
  930. }
  931. });
  932. Proj4js.Proj.longlat = {
  933. init: function() {
  934. //no-op for longlat
  935. },
  936. forward: function(pt) {
  937. //identity transform
  938. return pt;
  939. },
  940. inverse: function(pt) {
  941. //identity transform
  942. return pt;
  943. }
  944. };
  945. Proj4js.Proj.identity = Proj4js.Proj.longlat;
  946. /**
  947. Proj4js.defs is a collection of coordinate system definition objects in the
  948. PROJ.4 command line format.
  949. Generally a def is added by means of a separate .js file for example:
  950. <SCRIPT type="text/javascript" src="defs/EPSG26912.js"></SCRIPT>
  951. def is a CS definition in PROJ.4 WKT format, for example:
  952. +proj="tmerc" //longlat, etc.
  953. +a=majorRadius
  954. +b=minorRadius
  955. +lat0=somenumber
  956. +long=somenumber
  957. */
  958. Proj4js.defs = {
  959. // These are so widely used, we'll go ahead and throw them in
  960. // without requiring a separate .js file
  961. 'WGS84': "+title=long/lat:WGS84 +proj=longlat +ellps=WGS84 +datum=WGS84 +units=degrees",
  962. 'EPSG:4326': "+title=long/lat:WGS84 +proj=longlat +a=6378137.0 +b=6356752.31424518 +ellps=WGS84 +datum=WGS84 +units=degrees",
  963. 'EPSG:4269': "+title=long/lat:NAD83 +proj=longlat +a=6378137.0 +b=6356752.31414036 +ellps=GRS80 +datum=NAD83 +units=degrees",
  964. 'EPSG:3875': "+title= Google Mercator +proj=merc +a=6378137 +b=6378137 +lat_ts=0.0 +lon_0=0.0 +x_0=0.0 +y_0=0 +k=1.0 +units=m +nadgrids=@null +no_defs"
  965. };
  966. Proj4js.defs['EPSG:3785'] = Proj4js.defs['EPSG:3875']; //maintain backward compat, official code is 3875
  967. Proj4js.defs['GOOGLE'] = Proj4js.defs['EPSG:3875'];
  968. Proj4js.defs['EPSG:900913'] = Proj4js.defs['EPSG:3875'];
  969. Proj4js.defs['EPSG:102113'] = Proj4js.defs['EPSG:3875'];
  970. Proj4js.common = {
  971. PI : 3.141592653589793238, //Math.PI,
  972. HALF_PI : 1.570796326794896619, //Math.PI*0.5,
  973. TWO_PI : 6.283185307179586477, //Math.PI*2,
  974. FORTPI : 0.78539816339744833,
  975. R2D : 57.29577951308232088,
  976. D2R : 0.01745329251994329577,
  977. SEC_TO_RAD : 4.84813681109535993589914102357e-6, /* SEC_TO_RAD = Pi/180/3600 */
  978. EPSLN : 1.0e-10,
  979. MAX_ITER : 20,
  980. // following constants from geocent.c
  981. COS_67P5 : 0.38268343236508977, /* cosine of 67.5 degrees */
  982. AD_C : 1.0026000, /* Toms region 1 constant */
  983. /* datum_type values */
  984. PJD_UNKNOWN : 0,
  985. PJD_3PARAM : 1,
  986. PJD_7PARAM : 2,
  987. PJD_GRIDSHIFT: 3,
  988. PJD_WGS84 : 4, // WGS84 or equivalent
  989. PJD_NODATUM : 5, // WGS84 or equivalent
  990. SRS_WGS84_SEMIMAJOR : 6378137.0, // only used in grid shift transforms
  991. // ellipoid pj_set_ell.c
  992. SIXTH : .1666666666666666667, /* 1/6 */
  993. RA4 : .04722222222222222222, /* 17/360 */
  994. RA6 : .02215608465608465608, /* 67/3024 */
  995. RV4 : .06944444444444444444, /* 5/72 */
  996. RV6 : .04243827160493827160, /* 55/1296 */
  997. // Function to compute the constant small m which is the radius of
  998. // a parallel of latitude, phi, divided by the semimajor axis.
  999. // -----------------------------------------------------------------
  1000. msfnz : function(eccent, sinphi, cosphi) {
  1001. var con = eccent * sinphi;
  1002. return cosphi/(Math.sqrt(1.0 - con * con));
  1003. },
  1004. // Function to compute the constant small t for use in the forward
  1005. // computations in the Lambert Conformal Conic and the Polar
  1006. // Stereographic projections.
  1007. // -----------------------------------------------------------------
  1008. tsfnz : function(eccent, phi, sinphi) {
  1009. var con = eccent * sinphi;
  1010. var com = .5 * eccent;
  1011. con = Math.pow(((1.0 - con) / (1.0 + con)), com);
  1012. return (Math.tan(.5 * (this.HALF_PI - phi))/con);
  1013. },
  1014. // Function to compute the latitude angle, phi2, for the inverse of the
  1015. // Lambert Conformal Conic and Polar Stereographic projections.
  1016. // ----------------------------------------------------------------
  1017. phi2z : function(eccent, ts) {
  1018. var eccnth = .5 * eccent;
  1019. var con, dphi;
  1020. var phi = this.HALF_PI - 2 * Math.atan(ts);
  1021. for (var i = 0; i <= 15; i++) {
  1022. con = eccent * Math.sin(phi);
  1023. dphi = this.HALF_PI - 2 * Math.atan(ts *(Math.pow(((1.0 - con)/(1.0 + con)),eccnth))) - phi;
  1024. phi += dphi;
  1025. if (Math.abs(dphi) <= .0000000001) return phi;
  1026. }
  1027. alert("phi2z has NoConvergence");
  1028. return (-9999);
  1029. },
  1030. /* Function to compute constant small q which is the radius of a
  1031. parallel of latitude, phi, divided by the semimajor axis.
  1032. ------------------------------------------------------------*/
  1033. qsfnz : function(eccent,sinphi) {
  1034. var con;
  1035. if (eccent > 1.0e-7) {
  1036. con = eccent * sinphi;
  1037. return (( 1.0- eccent * eccent) * (sinphi /(1.0 - con * con) - (.5/eccent)*Math.log((1.0 - con)/(1.0 + con))));
  1038. } else {
  1039. return(2.0 * sinphi);
  1040. }
  1041. },
  1042. /* Function to eliminate roundoff errors in asin
  1043. ----------------------------------------------*/
  1044. asinz : function(x) {
  1045. if (Math.abs(x)>1.0) {
  1046. x=(x>1.0)?1.0:-1.0;
  1047. }
  1048. return Math.asin(x);
  1049. },
  1050. // following functions from gctpc cproj.c for transverse mercator projections
  1051. e0fn : function(x) {return(1.0-0.25*x*(1.0+x/16.0*(3.0+1.25*x)));},
  1052. e1fn : function(x) {return(0.375*x*(1.0+0.25*x*(1.0+0.46875*x)));},
  1053. e2fn : function(x) {return(0.05859375*x*x*(1.0+0.75*x));},
  1054. e3fn : function(x) {return(x*x*x*(35.0/3072.0));},
  1055. mlfn : function(e0,e1,e2,e3,phi) {return(e0*phi-e1*Math.sin(2.0*phi)+e2*Math.sin(4.0*phi)-e3*Math.sin(6.0*phi));},
  1056. srat : function(esinp, exp) {
  1057. return(Math.pow((1.0-esinp)/(1.0+esinp), exp));
  1058. },
  1059. // Function to return the sign of an argument
  1060. sign : function(x) { if (x < 0.0) return(-1); else return(1);},
  1061. // Function to adjust longitude to -180 to 180; input in radians
  1062. adjust_lon : function(x) {
  1063. x = (Math.abs(x) < this.PI) ? x: (x - (this.sign(x)*this.TWO_PI) );
  1064. return x;
  1065. },
  1066. // IGNF - DGR : algorithms used by IGN France
  1067. // Function to adjust latitude to -90 to 90; input in radians
  1068. adjust_lat : function(x) {
  1069. x= (Math.abs(x) < this.HALF_PI) ? x: (x - (this.sign(x)*this.PI) );
  1070. return x;
  1071. },
  1072. // Latitude Isometrique - close to tsfnz ...
  1073. latiso : function(eccent, phi, sinphi) {
  1074. if (Math.abs(phi) > this.HALF_PI) return +Number.NaN;
  1075. if (phi==this.HALF_PI) return Number.POSITIVE_INFINITY;
  1076. if (phi==-1.0*this.HALF_PI) return -1.0*Number.POSITIVE_INFINITY;
  1077. var con= eccent*sinphi;
  1078. return Math.log(Math.tan((this.HALF_PI+phi)/2.0))+eccent*Math.log((1.0-con)/(1.0+con))/2.0;
  1079. },
  1080. fL : function(x,L) {
  1081. return 2.0*Math.atan(x*Math.exp(L)) - this.HALF_PI;
  1082. },
  1083. // Inverse Latitude Isometrique - close to ph2z
  1084. invlatiso : function(eccent, ts) {
  1085. var phi= this.fL(1.0,ts);
  1086. var Iphi= 0.0;
  1087. var con= 0.0;
  1088. do {
  1089. Iphi= phi;
  1090. con= eccent*Math.sin(Iphi);
  1091. phi= this.fL(Math.exp(eccent*Math.log((1.0+con)/(1.0-con))/2.0),ts)
  1092. } while (Math.abs(phi-Iphi)>1.0e-12);
  1093. return phi;
  1094. },
  1095. // Needed for Gauss Schreiber
  1096. // Original: Denis Makarov (info@binarythings.com)
  1097. // Web Site: http://www.binarythings.com
  1098. sinh : function(x)
  1099. {
  1100. var r= Math.exp(x);
  1101. r= (r-1.0/r)/2.0;
  1102. return r;
  1103. },
  1104. cosh : function(x)
  1105. {
  1106. var r= Math.exp(x);
  1107. r= (r+1.0/r)/2.0;
  1108. return r;
  1109. },
  1110. tanh : function(x)
  1111. {
  1112. var r= Math.exp(x);
  1113. r= (r-1.0/r)/(r+1.0/r);
  1114. return r;
  1115. },
  1116. asinh : function(x)
  1117. {
  1118. var s= (x>= 0? 1.0:-1.0);
  1119. return s*(Math.log( Math.abs(x) + Math.sqrt(x*x+1.0) ));
  1120. },
  1121. acosh : function(x)
  1122. {
  1123. return 2.0*Math.log(Math.sqrt((x+1.0)/2.0) + Math.sqrt((x-1.0)/2.0));
  1124. },
  1125. atanh : function(x)
  1126. {
  1127. return Math.log((x-1.0)/(x+1.0))/2.0;
  1128. },
  1129. // Grande Normale
  1130. gN : function(a,e,sinphi)
  1131. {
  1132. var temp= e*sinphi;
  1133. return a/Math.sqrt(1.0 - temp*temp);
  1134. },
  1135. //code from the PROJ.4 pj_mlfn.c file; this may be useful for other projections
  1136. pj_enfn: function(es) {
  1137. var en = new Array();
  1138. en[0] = this.C00 - es * (this.C02 + es * (this.C04 + es * (this.C06 + es * this.C08)));
  1139. en[1] = es * (this.C22 - es * (this.C04 + es * (this.C06 + es * this.C08)));
  1140. var t = es * es;
  1141. en[2] = t * (this.C44 - es * (this.C46 + es * this.C48));
  1142. t *= es;
  1143. en[3] = t * (this.C66 - es * this.C68);
  1144. en[4] = t * es * this.C88;
  1145. return en;
  1146. },
  1147. pj_mlfn: function(phi, sphi, cphi, en) {
  1148. cphi *= sphi;
  1149. sphi *= sphi;
  1150. return(en[0] * phi - cphi * (en[1] + sphi*(en[2]+ sphi*(en[3] + sphi*en[4]))));
  1151. },
  1152. pj_inv_mlfn: function(arg, es, en) {
  1153. var k = 1./(1.-es);
  1154. var phi = arg;
  1155. for (var i = Proj4js.common.MAX_ITER; i ; --i) { /* rarely goes over 2 iterations */
  1156. var s = Math.sin(phi);
  1157. var t = 1. - es * s * s;
  1158. //t = this.pj_mlfn(phi, s, Math.cos(phi), en) - arg;
  1159. //phi -= t * (t * Math.sqrt(t)) * k;
  1160. t = (this.pj_mlfn(phi, s, Math.cos(phi), en) - arg) * (t * Math.sqrt(t)) * k;
  1161. phi -= t;
  1162. if (Math.abs(t) < Proj4js.common.EPSLN)
  1163. return phi;
  1164. }
  1165. Proj4js.reportError("cass:pj_inv_mlfn: Convergence error");
  1166. return phi;
  1167. },
  1168. /* meridinal distance for ellipsoid and inverse
  1169. ** 8th degree - accurate to < 1e-5 meters when used in conjuction
  1170. ** with typical major axis values.
  1171. ** Inverse determines phi to EPS (1e-11) radians, about 1e-6 seconds.
  1172. */
  1173. C00: 1.0,
  1174. C02: .25,
  1175. C04: .046875,
  1176. C06: .01953125,
  1177. C08: .01068115234375,
  1178. C22: .75,
  1179. C44: .46875,
  1180. C46: .01302083333333333333,
  1181. C48: .00712076822916666666,
  1182. C66: .36458333333333333333,
  1183. C68: .00569661458333333333,
  1184. C88: .3076171875
  1185. };
  1186. /** datum object
  1187. */
  1188. Proj4js.datum = Proj4js.Class({
  1189. initialize : function(proj) {
  1190. this.datum_type = Proj4js.common.PJD_WGS84; //default setting
  1191. if (proj.datumCode && proj.datumCode == 'none') {
  1192. this.datum_type = Proj4js.common.PJD_NODATUM;
  1193. }
  1194. if (proj && proj.datum_params) {
  1195. for (var i=0; i<proj.datum_params.length; i++) {
  1196. proj.datum_params[i]=parseFloat(proj.datum_params[i]);
  1197. }
  1198. if (proj.datum_params[0] != 0 || proj.datum_params[1] != 0 || proj.datum_params[2] != 0 ) {
  1199. this.datum_type = Proj4js.common.PJD_3PARAM;
  1200. }
  1201. if (proj.datum_params.length > 3) {
  1202. if (proj.datum_params[3] != 0 || proj.datum_params[4] != 0 ||
  1203. proj.datum_params[5] != 0 || proj.datum_params[6] != 0 ) {
  1204. this.datum_type = Proj4js.common.PJD_7PARAM;
  1205. proj.datum_params[3] *= Proj4js.common.SEC_TO_RAD;
  1206. proj.datum_params[4] *= Proj4js.common.SEC_TO_RAD;
  1207. proj.datum_params[5] *= Proj4js.common.SEC_TO_RAD;
  1208. proj.datum_params[6] = (proj.datum_params[6]/1000000.0) + 1.0;
  1209. }
  1210. }
  1211. }
  1212. if (proj) {
  1213. this.a = proj.a; //datum object also uses these values
  1214. this.b = proj.b;
  1215. this.es = proj.es;
  1216. this.ep2 = proj.ep2;
  1217. this.datum_params = proj.datum_params;
  1218. }
  1219. },
  1220. /****************************************************************/
  1221. // cs_compare_datums()
  1222. // Returns TRUE if the two datums match, otherwise FALSE.
  1223. compare_datums : function( dest ) {
  1224. if( this.datum_type != dest.datum_type ) {
  1225. return false; // false, datums are not equal
  1226. } else if( this.a != dest.a || Math.abs(this.es-dest.es) > 0.000000000050 ) {
  1227. // the tolerence for es is to ensure that GRS80 and WGS84
  1228. // are considered identical
  1229. return false;
  1230. } else if( this.datum_type == Proj4js.common.PJD_3PARAM ) {
  1231. return (this.datum_params[0] == dest.datum_params[0]
  1232. && this.datum_params[1] == dest.datum_params[1]
  1233. && this.datum_params[2] == dest.datum_params[2]);
  1234. } else if( this.datum_type == Proj4js.common.PJD_7PARAM ) {
  1235. return (this.datum_params[0] == dest.datum_params[0]
  1236. && this.datum_params[1] == dest.datum_params[1]
  1237. && this.datum_params[2] == dest.datum_params[2]
  1238. && this.datum_params[3] == dest.datum_params[3]
  1239. && this.datum_params[4] == dest.datum_params[4]
  1240. && this.datum_params[5] == dest.datum_params[5]
  1241. && this.datum_params[6] == dest.datum_params[6]);
  1242. } else if ( this.datum_type == Proj4js.common.PJD_GRIDSHIFT ||
  1243. dest.datum_type == Proj4js.common.PJD_GRIDSHIFT ) {
  1244. alert("ERROR: Grid shift transformations are not implemented.");
  1245. return false
  1246. } else {
  1247. return true; // datums are equal
  1248. }
  1249. }, // cs_compare_datums()
  1250. /*
  1251. * The function Convert_Geodetic_To_Geocentric converts geodetic coordinates
  1252. * (latitude, longitude, and height) to geocentric coordinates (X, Y, Z),
  1253. * according to the current ellipsoid parameters.
  1254. *
  1255. * Latitude : Geodetic latitude in radians (input)
  1256. * Longitude : Geodetic longitude in radians (input)
  1257. * Height : Geodetic height, in meters (input)
  1258. * X : Calculated Geocentric X coordinate, in meters (output)
  1259. * Y : Calculated Geocentric Y coordinate, in meters (output)
  1260. * Z : Calculated Geocentric Z coordinate, in meters (output)
  1261. *
  1262. */
  1263. geodetic_to_geocentric : function(p) {
  1264. var Longitude = p.x;
  1265. var Latitude = p.y;
  1266. var Height = p.z ? p.z : 0; //Z value not always supplied
  1267. var X; // output
  1268. var Y;
  1269. var Z;
  1270. var Error_Code=0; // GEOCENT_NO_ERROR;
  1271. var Rn; /* Earth radius at location */
  1272. var Sin_Lat; /* Math.sin(Latitude) */
  1273. var Sin2_Lat; /* Square of Math.sin(Latitude) */
  1274. var Cos_Lat; /* Math.cos(Latitude) */
  1275. /*
  1276. ** Don't blow up if Latitude is just a little out of the value
  1277. ** range as it may just be a rounding issue. Also removed longitude
  1278. ** test, it should be wrapped by Math.cos() and Math.sin(). NFW for PROJ.4, Sep/2001.
  1279. */
  1280. if( Latitude < -Proj4js.common.HALF_PI && Latitude > -1.001 * Proj4js.common.HALF_PI ) {
  1281. Latitude = -Proj4js.common.HALF_PI;
  1282. } else if( Latitude > Proj4js.common.HALF_PI && Latitude < 1.001 * Proj4js.common.HALF_PI ) {
  1283. Latitude = Proj4js.common.HALF_PI;
  1284. } else if ((Latitude < -Proj4js.common.HALF_PI) || (Latitude > Proj4js.common.HALF_PI)) {
  1285. /* Latitude out of range */
  1286. Proj4js.reportError('geocent:lat out of range:'+Latitude);
  1287. return null;
  1288. }
  1289. if (Longitude > Proj4js.common.PI) Longitude -= (2*Proj4js.common.PI);
  1290. Sin_Lat = Math.sin(Latitude);
  1291. Cos_Lat = Math.cos(Latitude);
  1292. Sin2_Lat = Sin_Lat * Sin_Lat;
  1293. Rn = this.a / (Math.sqrt(1.0e0 - this.es * Sin2_Lat));
  1294. X = (Rn + Height) * Cos_Lat * Math.cos(Longitude);
  1295. Y = (Rn + Height) * Cos_Lat * Math.sin(Longitude);
  1296. Z = ((Rn * (1 - this.es)) + Height) * Sin_Lat;
  1297. p.x = X;
  1298. p.y = Y;
  1299. p.z = Z;
  1300. return Error_Code;
  1301. }, // cs_geodetic_to_geocentric()
  1302. geocentric_to_geodetic : function (p) {
  1303. /* local defintions and variables */
  1304. /* end-criterium of loop, accuracy of sin(Latitude) */
  1305. var genau = 1.E-12;
  1306. var genau2 = (genau*genau);
  1307. var maxiter = 30;
  1308. var P; /* distance between semi-minor axis and location */
  1309. var RR; /* distance between center and location */
  1310. var CT; /* sin of geocentric latitude */
  1311. var ST; /* cos of geocentric latitude */
  1312. var RX;
  1313. var RK;
  1314. var RN; /* Earth radius at location */
  1315. var CPHI0; /* cos of start or old geodetic latitude in iterations */
  1316. var SPHI0; /* sin of start or old geodetic latitude in iterations */
  1317. var CPHI; /* cos of searched geodetic latitude */
  1318. var SPHI; /* sin of searched geodetic latitude */
  1319. var SDPHI; /* end-criterium: addition-theorem of sin(Latitude(iter)-Latitude(iter-1)) */
  1320. var At_Pole; /* indicates location is in polar region */
  1321. var iter; /* # of continous iteration, max. 30 is always enough (s.a.) */
  1322. var X = p.x;
  1323. var Y = p.y;
  1324. var Z = p.z ? p.z : 0.0; //Z value not always supplied
  1325. var Longitude;
  1326. var Latitude;
  1327. var Height;
  1328. At_Pole = false;
  1329. P = Math.sqrt(X*X+Y*Y);
  1330. RR = Math.sqrt(X*X+Y*Y+Z*Z);
  1331. /* special cases for latitude and longitude */
  1332. if (P/this.a < genau) {
  1333. /* special case, if P=0. (X=0., Y=0.) */
  1334. At_Pole = true;
  1335. Longitude = 0.0;
  1336. /* if (X,Y,Z)=(0.,0.,0.) then Height becomes semi-minor axis
  1337. * of ellipsoid (=center of mass), Latitude becomes PI/2 */
  1338. if (RR/this.a < genau) {
  1339. Latitude = Proj4js.common.HALF_PI;
  1340. Height = -this.b;
  1341. return;
  1342. }
  1343. } else {
  1344. /* ellipsoidal (geodetic) longitude
  1345. * interval: -PI < Longitude <= +PI */
  1346. Longitude=Math.atan2(Y,X);
  1347. }
  1348. /* --------------------------------------------------------------
  1349. * Following iterative algorithm was developped by
  1350. * "Institut f�r Erdmessung", University of Hannover, July 1988.
  1351. * Internet: www.ife.uni-hannover.de
  1352. * Iterative computation of CPHI,SPHI and Height.
  1353. * Iteration of CPHI and SPHI to 10**-12 radian resp.
  1354. * 2*10**-7 arcsec.
  1355. * --------------------------------------------------------------
  1356. */
  1357. CT = Z/RR;
  1358. ST = P/RR;
  1359. RX = 1.0/Math.sqrt(1.0-this.es*(2.0-this.es)*ST*ST);
  1360. CPHI0 = ST*(1.0-this.es)*RX;
  1361. SPHI0 = CT*RX;
  1362. iter = 0;
  1363. /* loop to find sin(Latitude) resp. Latitude
  1364. * until |sin(Latitude(iter)-Latitude(iter-1))| < genau */
  1365. do
  1366. {
  1367. iter++;
  1368. RN = this.a/Math.sqrt(1.0-this.es*SPHI0*SPHI0);
  1369. /* ellipsoidal (geodetic) height */
  1370. Height = P*CPHI0+Z*SPHI0-RN*(1.0-this.es*SPHI0*SPHI0);
  1371. RK = this.es*RN/(RN+Height);
  1372. RX = 1.0/Math.sqrt(1.0-RK*(2.0-RK)*ST*ST);
  1373. CPHI = ST*(1.0-RK)*RX;
  1374. SPHI = CT*RX;
  1375. SDPHI = SPHI*CPHI0-CPHI*SPHI0;
  1376. CPHI0 = CPHI;
  1377. SPHI0 = SPHI;
  1378. }
  1379. while (SDPHI*SDPHI > genau2 && iter < maxiter);
  1380. /* ellipsoidal (geodetic) latitude */
  1381. Latitude=Math.atan(SPHI/Math.abs(CPHI));
  1382. p.x = Longitude;
  1383. p.y = Latitude;
  1384. p.z = Height;
  1385. return p;
  1386. }, // cs_geocentric_to_geodetic()
  1387. /** Convert_Geocentric_To_Geodetic
  1388. * The method used here is derived from 'An Improved Algorithm for
  1389. * Geocentric to Geodetic Coordinate Conversion', by Ralph Toms, Feb 1996
  1390. */
  1391. geocentric_to_geodetic_noniter : function (p) {
  1392. var X = p.x;
  1393. var Y = p.y;
  1394. var Z = p.z ? p.z : 0; //Z value not always supplied
  1395. var Longitude;
  1396. var Latitude;
  1397. var Height;
  1398. var W; /* distance from Z axis */
  1399. var W2; /* square of distance from Z axis */
  1400. var T0; /* initial estimate of vertical component */
  1401. var T1; /* corrected estimate of vertical component */
  1402. var S0; /* initial estimate of horizontal component */
  1403. var S1; /* corrected estimate of horizontal component */
  1404. var Sin_B0; /* Math.sin(B0), B0 is estimate of Bowring aux variable */
  1405. var Sin3_B0; /* cube of Math.sin(B0) */
  1406. var Cos_B0; /* Math.cos(B0) */
  1407. var Sin_p1; /* Math.sin(phi1), phi1 is estimated latitude */
  1408. var Cos_p1; /* Math.cos(phi1) */
  1409. var Rn; /* Earth radius at location */
  1410. var Sum; /* numerator of Math.cos(phi1) */
  1411. var At_Pole; /* indicates location is in polar region */
  1412. X = parseFloat(X); // cast from string to float
  1413. Y = parseFloat(Y);
  1414. Z = parseFloat(Z);
  1415. At_Pole = false;
  1416. if (X != 0.0)
  1417. {
  1418. Longitude = Math.atan2(Y,X);
  1419. }
  1420. else
  1421. {
  1422. if (Y > 0)
  1423. {
  1424. Longitude = Proj4js.common.HALF_PI;
  1425. }
  1426. else if (Y < 0)
  1427. {
  1428. Longitude = -Proj4js.common.HALF_PI;
  1429. }
  1430. else
  1431. {
  1432. At_Pole = true;
  1433. Longitude = 0.0;
  1434. if (Z > 0.0)
  1435. { /* north pole */
  1436. Latitude = Proj4js.common.HALF_PI;
  1437. }
  1438. else if (Z < 0.0)
  1439. { /* south pole */
  1440. Latitude = -Proj4js.common.HALF_PI;
  1441. }
  1442. else
  1443. { /* center of earth */
  1444. Latitude = Proj4js.common.HALF_PI;
  1445. Height = -this.b;
  1446. return;
  1447. }
  1448. }
  1449. }
  1450. W2 = X*X + Y*Y;
  1451. W = Math.sqrt(W2);
  1452. T0 = Z * Proj4js.common.AD_C;
  1453. S0 = Math.sqrt(T0 * T0 + W2);
  1454. Sin_B0 = T0 / S0;
  1455. Cos_B0 = W / S0;
  1456. Sin3_B0 = Sin_B0 * Sin_B0 * Sin_B0;
  1457. T1 = Z + this.b * this.ep2 * Sin3_B0;
  1458. Sum = W - this.a * this.es * Cos_B0 * Cos_B0 * Cos_B0;
  1459. S1 = Math.sqrt(T1*T1 + Sum * Sum);
  1460. Sin_p1 = T1 / S1;
  1461. Cos_p1 = Sum / S1;
  1462. Rn = this.a / Math.sqrt(1.0 - this.es * Sin_p1 * Sin_p1);
  1463. if (Cos_p1 >= Proj4js.common.COS_67P5)
  1464. {
  1465. Height = W / Cos_p1 - Rn;
  1466. }
  1467. else if (Cos_p1 <= -Proj4js.common.COS_67P5)
  1468. {
  1469. Height = W / -Cos_p1 - Rn;
  1470. }
  1471. else
  1472. {
  1473. Height = Z / Sin_p1 + Rn * (this.es - 1.0);
  1474. }
  1475. if (At_Pole == false)
  1476. {
  1477. Latitude = Math.atan(Sin_p1 / Cos_p1);
  1478. }
  1479. p.x = Longitude;
  1480. p.y = Latitude;
  1481. p.z = Height;
  1482. return p;
  1483. }, // geocentric_to_geodetic_noniter()
  1484. /****************************************************************/
  1485. // pj_geocentic_to_wgs84( p )
  1486. // p = point to transform in geocentric coordinates (x,y,z)
  1487. geocentric_to_wgs84 : function ( p ) {
  1488. if( this.datum_type == Proj4js.common.PJD_3PARAM )
  1489. {
  1490. // if( x[io] == HUGE_VAL )
  1491. // continue;
  1492. p.x += this.datum_params[0];
  1493. p.y += this.datum_params[1];
  1494. p.z += this.datum_params[2];
  1495. }
  1496. else if (this.datum_type == Proj4js.common.PJD_7PARAM)
  1497. {
  1498. var Dx_BF =this.datum_params[0];
  1499. var Dy_BF =this.datum_params[1];
  1500. var Dz_BF =this.datum_params[2];
  1501. var Rx_BF =this.datum_params[3];
  1502. var Ry_BF =this.datum_params[4];
  1503. var Rz_BF =this.datum_params[5];
  1504. var M_BF =this.datum_params[6];
  1505. // if( x[io] == HUGE_VAL )
  1506. // continue;
  1507. var x_out = M_BF*( p.x - Rz_BF*p.y + Ry_BF*p.z) + Dx_BF;
  1508. var y_out = M_BF*( Rz_BF*p.x + p.y - Rx_BF*p.z) + Dy_BF;
  1509. var z_out = M_BF*(-Ry_BF*p.x + Rx_BF*p.y + p.z) + Dz_BF;
  1510. p.x = x_out;
  1511. p.y = y_out;
  1512. p.z = z_out;
  1513. }
  1514. }, // cs_geocentric_to_wgs84
  1515. /****************************************************************/
  1516. // pj_geocentic_from_wgs84()
  1517. // coordinate system definition,
  1518. // point to transform in geocentric coordinates (x,y,z)
  1519. geocentric_from_wgs84 : function( p ) {
  1520. if( this.datum_type == Proj4js.common.PJD_3PARAM )
  1521. {
  1522. //if( x[io] == HUGE_VAL )
  1523. // continue;
  1524. p.x -= this.datum_params[0];
  1525. p.y -= this.datum_params[1];
  1526. p.z -= this.datum_params[2];
  1527. }
  1528. else if (this.datum_type == Proj4js.common.PJD_7PARAM)
  1529. {
  1530. var Dx_BF =this.datum_params[0];
  1531. var Dy_BF =this.datum_params[1];
  1532. var Dz_BF =this.datum_params[2];
  1533. var Rx_BF =this.datum_params[3];
  1534. var Ry_BF =this.datum_params[4];
  1535. var Rz_BF =this.datum_params[5];
  1536. var M_BF =this.datum_params[6];
  1537. var x_tmp = (p.x - Dx_BF) / M_BF;
  1538. var y_tmp = (p.y - Dy_BF) / M_BF;
  1539. var z_tmp = (p.z - Dz_BF) / M_BF;
  1540. //if( x[io] == HUGE_VAL )
  1541. // continue;
  1542. p.x = x_tmp + Rz_BF*y_tmp - Ry_BF*z_tmp;
  1543. p.y = -Rz_BF*x_tmp + y_tmp + Rx_BF*z_tmp;
  1544. p.z = Ry_BF*x_tmp - Rx_BF*y_tmp + z_tmp;
  1545. } //cs_geocentric_from_wgs84()
  1546. }
  1547. });
  1548. /** point object, nothing fancy, just allows values to be
  1549. passed back and forth by reference rather than by value.
  1550. Other point classes may be used as long as they have
  1551. x and y properties, which will get modified in the transform method.
  1552. */
  1553. Proj4js.Point = Proj4js.Class({
  1554. /**
  1555. * Constructor: Proj4js.Point
  1556. *
  1557. * Parameters:
  1558. * - x {float} or {Array} either the first coordinates component or
  1559. * the full coordinates
  1560. * - y {float} the second component
  1561. * - z {float} the third component, optional.
  1562. */
  1563. initialize : function(x,y,z) {
  1564. if (typeof x == 'object') {
  1565. this.x = x[0];
  1566. this.y = x[1];
  1567. this.z = x[2] || 0.0;
  1568. } else if (typeof x == 'string' && typeof y == 'undefined') {
  1569. var coords = x.split(',');
  1570. this.x = parseFloat(coords[0]);
  1571. this.y = parseFloat(coords[1]);
  1572. this.z = parseFloat(coords[2]) || 0.0;
  1573. } else {
  1574. this.x = x;
  1575. this.y = y;
  1576. this.z = z || 0.0;
  1577. }
  1578. },
  1579. /**
  1580. * APIMethod: clone
  1581. * Build a copy of a Proj4js.Point object.
  1582. *
  1583. * Return:
  1584. * {Proj4js}.Point the cloned point.
  1585. */
  1586. clone : function() {
  1587. return new Proj4js.Point(this.x, this.y, this.z);
  1588. },
  1589. /**
  1590. * APIMethod: toString
  1591. * Return a readable string version of the point
  1592. *
  1593. * Return:
  1594. * {String} String representation of Proj4js.Point object.
  1595. * (ex. <i>"x=5,y=42"</i>)
  1596. */
  1597. toString : function() {
  1598. return ("x=" + this.x + ",y=" + this.y);
  1599. },
  1600. /**
  1601. * APIMethod: toShortString
  1602. * Return a short string version of the point.
  1603. *
  1604. * Return:
  1605. * {String} Shortened String representation of Proj4js.Point object.
  1606. * (ex. <i>"5, 42"</i>)
  1607. */
  1608. toShortString : function() {
  1609. return (this.x + ", " + this.y);
  1610. }
  1611. });
  1612. Proj4js.PrimeMeridian = {
  1613. "greenwich": 0.0, //"0dE",
  1614. "lisbon": -9.131906111111, //"9d07'54.862\"W",
  1615. "paris": 2.337229166667, //"2d20'14.025\"E",
  1616. "bogota": -74.080916666667, //"74d04'51.3\"W",
  1617. "madrid": -3.687938888889, //"3d41'16.58\"W",
  1618. "rome": 12.452333333333, //"12d27'8.4\"E",
  1619. "bern": 7.439583333333, //"7d26'22.5\"E",
  1620. "jakarta": 106.807719444444, //"106d48'27.79\"E",
  1621. "ferro": -17.666666666667, //"17d40'W",
  1622. "brussels": 4.367975, //"4d22'4.71\"E",
  1623. "stockholm": 18.058277777778, //"18d3'29.8\"E",
  1624. "athens": 23.7163375, //"23d42'58.815\"E",
  1625. "oslo": 10.722916666667 //"10d43'22.5\"E"
  1626. };
  1627. Proj4js.Ellipsoid = {
  1628. "MERIT": {a:6378137.0, rf:298.257, ellipseName:"MERIT 1983"},
  1629. "SGS85": {a:6378136.0, rf:298.257, ellipseName:"Soviet Geodetic System 85"},
  1630. "GRS80": {a:6378137.0, rf:298.257222101, ellipseName:"GRS 1980(IUGG, 1980)"},
  1631. "IAU76": {a:6378140.0, rf:298.257, ellipseName:"IAU 1976"},
  1632. "airy": {a:6377563.396, b:6356256.910, ellipseName:"Airy 1830"},
  1633. "APL4.": {a:6378137, rf:298.25, ellipseName:"Appl. Physics. 1965"},
  1634. "NWL9D": {a:6378145.0, rf:298.25, ellipseName:"Naval Weapons Lab., 1965"},
  1635. "mod_airy": {a:6377340.189, b:6356034.446, ellipseName:"Modified Airy"},
  1636. "andrae": {a:6377104.43, rf:300.0, ellipseName:"Andrae 1876 (Den., Iclnd.)"},
  1637. "aust_SA": {a:6378160.0, rf:298.25, ellipseName:"Australian Natl & S. Amer. 1969"},
  1638. "GRS67": {a:6378160.0, rf:298.2471674270, ellipseName:"GRS 67(IUGG 1967)"},
  1639. "bessel": {a:6377397.155, rf:299.1528128, ellipseName:"Bessel 1841"},
  1640. "bess_nam": {a:6377483.865, rf:299.1528128, ellipseName:"Bessel 1841 (Namibia)"},
  1641. "clrk66": {a:6378206.4, b:6356583.8, ellipseName:"Clarke 1866"},
  1642. "clrk80": {a:6378249.145, rf:293.4663, ellipseName:"Clarke 1880 mod."},
  1643. "CPM": {a:6375738.7, rf:334.29, ellipseName:"Comm. des Poids et Mesures 1799"},
  1644. "delmbr": {a:6376428.0, rf:311.5, ellipseName:"Delambre 1810 (Belgium)"},
  1645. "engelis": {a:6378136.05, rf:298.2566, ellipseName:"Engelis 1985"},
  1646. "evrst30": {a:6377276.345, rf:300.8017, ellipseName:"Everest 1830"},
  1647. "evrst48": {a:6377304.063, rf:300.8017, ellipseName:"Everest 1948"},
  1648. "evrst56": {a:6377301.243, rf:300.8017, ellipseName:"Everest 1956"},
  1649. "evrst69": {a:6377295.664, rf:300.8017, ellipseName:"Everest 1969"},
  1650. "evrstSS": {a:6377298.556, rf:300.8017, ellipseName:"Everest (Sabah & Sarawak)"},
  1651. "fschr60": {a:6378166.0, rf:298.3, ellipseName:"Fischer (Mercury Datum) 1960"},
  1652. "fschr60m": {a:6378155.0, rf:298.3, ellipseName:"Fischer 1960"},
  1653. "fschr68": {a:6378150.0, rf:298.3, ellipseName:"Fischer 1968"},
  1654. "helmert": {a:6378200.0, rf:298.3, ellipseName:"Helmert 1906"},
  1655. "hough": {a:6378270.0, rf:297.0, ellipseName:"Hough"},
  1656. "intl": {a:6378388.0, rf:297.0, ellipseName:"International 1909 (Hayford)"},
  1657. "kaula": {a:6378163.0, rf:298.24, ellipseName:"Kaula 1961"},
  1658. "lerch": {a:6378139.0, rf:298.257, ellipseName:"Lerch 1979"},
  1659. "mprts": {a:6397300.0, rf:191.0, ellipseName:"Maupertius 1738"},
  1660. "new_intl": {a:6378157.5, b:6356772.2, ellipseName:"New International 1967"},
  1661. "plessis": {a:6376523.0, rf:6355863.0, ellipseName:"Plessis 1817 (France)"},
  1662. "krass": {a:6378245.0, rf:298.3, ellipseName:"Krassovsky, 1942"},
  1663. "SEasia": {a:6378155.0, b:6356773.3205, ellipseName:"Southeast Asia"},
  1664. "walbeck": {a:6376896.0, b:6355834.8467, ellipseName:"Walbeck"},
  1665. "WGS60": {a:6378165.0, rf:298.3, ellipseName:"WGS 60"},
  1666. "WGS66": {a:6378145.0, rf:298.25, ellipseName:"WGS 66"},
  1667. "WGS72": {a:6378135.0, rf:298.26, ellipseName:"WGS 72"},
  1668. "WGS84": {a:6378137.0, rf:298.257223563, ellipseName:"WGS 84"},
  1669. "sphere": {a:6370997.0, b:6370997.0, ellipseName:"Normal Sphere (r=6370997)"}
  1670. };
  1671. Proj4js.Datum = {
  1672. "WGS84": {towgs84: "0,0,0", ellipse: "WGS84", datumName: "WGS84"},
  1673. "GGRS87": {towgs84: "-199.87,74.79,246.62", ellipse: "GRS80", datumName: "Greek_Geodetic_Reference_System_1987"},
  1674. "NAD83": {towgs84: "0,0,0", ellipse: "GRS80", datumName: "North_American_Datum_1983"},
  1675. "NAD27": {nadgrids: "@conus,@alaska,@ntv2_0.gsb,@ntv1_can.dat", ellipse: "clrk66", datumName: "North_American_Datum_1927"},
  1676. "potsdam": {towgs84: "606.0,23.0,413.0", ellipse: "bessel", datumName: "Potsdam Rauenberg 1950 DHDN"},
  1677. "carthage": {towgs84: "-263.0,6.0,431.0", ellipse: "clark80", datumName: "Carthage 1934 Tunisia"},
  1678. "hermannskogel": {towgs84: "653.0,-212.0,449.0", ellipse: "bessel", datumName: "Hermannskogel"},
  1679. "ire65": {towgs84: "482.530,-130.596,564.557,-1.042,-0.214,-0.631,8.15", ellipse: "mod_airy", datumName: "Ireland 1965"},
  1680. "nzgd49": {towgs84: "59.47,-5.04,187.44,0.47,-0.1,1.024,-4.5993", ellipse: "intl", datumName: "New Zealand Geodetic Datum 1949"},
  1681. "OSGB36": {towgs84: "446.448,-125.157,542.060,0.1502,0.2470,0.8421,-20.4894", ellipse: "airy", datumName: "Airy 1830"}
  1682. };
  1683. Proj4js.WGS84 = new Proj4js.Proj('WGS84');
  1684. Proj4js.Datum['OSB36'] = Proj4js.Datum['OSGB36']; //as returned from spatialreference.org
  1685. //lookup table to go from the projection name in WKT to the Proj4js projection name
  1686. //build this out as required
  1687. Proj4js.wktProjections = {
  1688. "Lambert Tangential Conformal Conic Projection": "lcc",
  1689. "Mercator": "merc",
  1690. "Popular Visualisation Pseudo Mercator": "merc",
  1691. "Mercator_1SP": "merc",
  1692. "Transverse_Mercator": "tmerc",
  1693. "Transverse Mercator": "tmerc",
  1694. "Lambert Azimuthal Equal Area": "laea",
  1695. "Universal Transverse Mercator System": "utm"
  1696. };
  1697. /* ======================================================================
  1698. projCode/aea.js
  1699. ====================================================================== */
  1700. /*******************************************************************************
  1701. NAME ALBERS CONICAL EQUAL AREA
  1702. PURPOSE: Transforms input longitude and latitude to Easting and Northing
  1703. for the Albers Conical Equal Area projection. The longitude
  1704. and latitude must be in radians. The Easting and Northing
  1705. values will be returned in meters.
  1706. PROGRAMMER DATE
  1707. ---------- ----
  1708. T. Mittan, Feb, 1992
  1709. ALGORITHM REFERENCES
  1710. 1. Snyder, John P., "Map Projections--A Working Manual", U.S. Geological
  1711. Survey Professional Paper 1395 (Supersedes USGS Bulletin 1532), United
  1712. State Government Printing Office, Washington D.C., 1987.
  1713. 2. Snyder, John P. and Voxland, Philip M., "An Album of Map Projections",
  1714. U.S. Geological Survey Professional Paper 1453 , United State Government
  1715. Printing Office, Washington D.C., 1989.
  1716. *******************************************************************************/
  1717. Proj4js.Proj.aea = {
  1718. init : function() {
  1719. if (Math.abs(this.lat1 + this.lat2) < Proj4js.common.EPSLN) {
  1720. Proj4js.reportError("aeaInitEqualLatitudes");
  1721. return;
  1722. }
  1723. this.temp = this.b / this.a;
  1724. this.es = 1.0 - Math.pow(this.temp,2);
  1725. this.e3 = Math.sqrt(this.es);
  1726. this.sin_po=Math.sin(this.lat1);
  1727. this.cos_po=Math.cos(this.lat1);
  1728. this.t1=this.sin_po;
  1729. this.con = this.sin_po;
  1730. this.ms1 = Proj4js.common.msfnz(this.e3,this.sin_po,this.cos_po);
  1731. this.qs1 = Proj4js.common.qsfnz(this.e3,this.sin_po,this.cos_po);
  1732. this.sin_po=Math.sin(this.lat2);
  1733. this.cos_po=Math.cos(this.lat2);
  1734. this.t2=this.sin_po;
  1735. this.ms2 = Proj4js.common.msfnz(this.e3,this.sin_po,this.cos_po);
  1736. this.qs2 = Proj4js.common.qsfnz(this.e3,this.sin_po,this.cos_po);
  1737. this.sin_po=Math.sin(this.lat0);
  1738. this.cos_po=Math.cos(this.lat0);
  1739. this.t3=this.sin_po;
  1740. this.qs0 = Proj4js.common.qsfnz(this.e3,this.sin_po,this.cos_po);
  1741. if (Math.abs(this.lat1 - this.lat2) > Proj4js.common.EPSLN) {
  1742. this.ns0 = (this.ms1 * this.ms1 - this.ms2 *this.ms2)/ (this.qs2 - this.qs1);
  1743. } else {
  1744. this.ns0 = this.con;
  1745. }
  1746. this.c = this.ms1 * this.ms1 + this.ns0 * this.qs1;
  1747. this.rh = this.a * Math.sqrt(this.c - this.ns0 * this.qs0)/this.ns0;
  1748. },
  1749. /* Albers Conical Equal Area forward equations--mapping lat,long to x,y
  1750. -------------------------------------------------------------------*/
  1751. forward: function(p){
  1752. var lon=p.x;
  1753. var lat=p.y;
  1754. this.sin_phi=Math.sin(lat);
  1755. this.cos_phi=Math.cos(lat);
  1756. var qs = Proj4js.common.qsfnz(this.e3,this.sin_phi,this.cos_phi);
  1757. var rh1 =this.a * Math.sqrt(this.c - this.ns0 * qs)/this.ns0;
  1758. var theta = this.ns0 * Proj4js.common.adjust_lon(lon - this.long0);
  1759. var x = rh1 * Math.sin(theta) + this.x0;
  1760. var y = this.rh - rh1 * Math.cos(theta) + this.y0;
  1761. p.x = x;
  1762. p.y = y;
  1763. return p;
  1764. },
  1765. inverse: function(p) {
  1766. var rh1,qs,con,theta,lon,lat;
  1767. p.x -= this.x0;
  1768. p.y = this.rh - p.y + this.y0;
  1769. if (this.ns0 >= 0) {
  1770. rh1 = Math.sqrt(p.x *p.x + p.y * p.y);
  1771. con = 1.0;
  1772. } else {
  1773. rh1 = -Math.sqrt(p.x * p.x + p.y *p.y);
  1774. con = -1.0;
  1775. }
  1776. theta = 0.0;
  1777. if (rh1 != 0.0) {
  1778. theta = Math.atan2(con * p.x, con * p.y);
  1779. }
  1780. con = rh1 * this.ns0 / this.a;
  1781. qs = (this.c - con * con) / this.ns0;
  1782. if (this.e3 >= 1e-10) {
  1783. con = 1 - .5 * (1.0 -this.es) * Math.log((1.0 - this.e3) / (1.0 + this.e3))/this.e3;
  1784. if (Math.abs(Math.abs(con) - Math.abs(qs)) > .0000000001 ) {
  1785. lat = this.phi1z(this.e3,qs);
  1786. } else {
  1787. if (qs >= 0) {
  1788. lat = .5 * Proj4js.common.PI;
  1789. } else {
  1790. lat = -.5 * Proj4js.common.PI;
  1791. }
  1792. }
  1793. } else {
  1794. lat = this.phi1z(this.e3,qs);
  1795. }
  1796. lon = Proj4js.common.adjust_lon(theta/this.ns0 + this.long0);
  1797. p.x = lon;
  1798. p.y = lat;
  1799. return p;
  1800. },
  1801. /* Function to compute phi1, the latitude for the inverse of the
  1802. Albers Conical Equal-Area projection.
  1803. -------------------------------------------*/
  1804. phi1z: function (eccent,qs) {
  1805. var sinphi, cosphi, con, com, dphi;
  1806. var phi = Proj4js.common.asinz(.5 * qs);
  1807. if (eccent < Proj4js.common.EPSLN) return phi;
  1808. var eccnts = eccent * eccent;
  1809. for (var i = 1; i <= 25; i++) {
  1810. sinphi = Math.sin(phi);
  1811. cosphi = Math.cos(phi);
  1812. con = eccent * sinphi;
  1813. com = 1.0 - con * con;
  1814. dphi = .5 * com * com / cosphi * (qs / (1.0 - eccnts) - sinphi / com + .5 / eccent * Math.log((1.0 - con) / (1.0 + con)));
  1815. phi = phi + dphi;
  1816. if (Math.abs(dphi) <= 1e-7) return phi;
  1817. }
  1818. Proj4js.reportError("aea:phi1z:Convergence error");
  1819. return null;
  1820. }
  1821. };
  1822. /* ======================================================================
  1823. projCode/sterea.js
  1824. ====================================================================== */
  1825. Proj4js.Proj.sterea = {
  1826. dependsOn : 'gauss',
  1827. init : function() {
  1828. Proj4js.Proj['gauss'].init.apply(this);
  1829. if (!this.rc) {
  1830. Proj4js.reportError("sterea:init:E_ERROR_0");
  1831. return;
  1832. }
  1833. this.sinc0 = Math.sin(this.phic0);
  1834. this.cosc0 = Math.cos(this.phic0);
  1835. this.R2 = 2.0 * this.rc;
  1836. if (!this.title) this.title = "Oblique Stereographic Alternative";
  1837. },
  1838. forward : function(p) {
  1839. var sinc, cosc, cosl, k;
  1840. p.x = Proj4js.common.adjust_lon(p.x-this.long0); /* adjust del longitude */
  1841. Proj4js.Proj['gauss'].forward.apply(this, [p]);
  1842. sinc = Math.sin(p.y);
  1843. cosc = Math.cos(p.y);
  1844. cosl = Math.cos(p.x);
  1845. k = this.k0 * this.R2 / (1.0 + this.sinc0 * sinc + this.cosc0 * cosc * cosl);
  1846. p.x = k * cosc * Math.sin(p.x);
  1847. p.y = k * (this.cosc0 * sinc - this.sinc0 * cosc * cosl);
  1848. p.x = this.a * p.x + this.x0;
  1849. p.y = this.a * p.y + this.y0;
  1850. return p;
  1851. },
  1852. inverse : function(p) {
  1853. var sinc, cosc, lon, lat, rho;
  1854. p.x = (p.x - this.x0) / this.a; /* descale and de-offset */
  1855. p.y = (p.y - this.y0) / this.a;
  1856. p.x /= this.k0;
  1857. p.y /= this.k0;
  1858. if ( (rho = Math.sqrt(p.x*p.x + p.y*p.y)) ) {
  1859. var c = 2.0 * Math.atan2(rho, this.R2);
  1860. sinc = Math.sin(c);
  1861. cosc = Math.cos(c);
  1862. lat = Math.asin(cosc * this.sinc0 + p.y * sinc * this.cosc0 / rho);
  1863. lon = Math.atan2(p.x * sinc, rho * this.cosc0 * cosc - p.y * this.sinc0 * sinc);
  1864. } else {
  1865. lat = this.phic0;
  1866. lon = 0.;
  1867. }
  1868. p.x = lon;
  1869. p.y = lat;
  1870. Proj4js.Proj['gauss'].inverse.apply(this,[p]);
  1871. p.x = Proj4js.common.adjust_lon(p.x + this.long0); /* adjust longitude to CM */
  1872. return p;
  1873. }
  1874. };
  1875. /* ======================================================================
  1876. projCode/poly.js
  1877. ====================================================================== */
  1878. /* Function to compute, phi4, the latitude for the inverse of the
  1879. Polyconic projection.
  1880. ------------------------------------------------------------*/
  1881. function phi4z (eccent,e0,e1,e2,e3,a,b,c,phi) {
  1882. var sinphi, sin2ph, tanphi, ml, mlp, con1, con2, con3, dphi, i;
  1883. phi = a;
  1884. for (i = 1; i <= 15; i++) {
  1885. sinphi = Math.sin(phi);
  1886. tanphi = Math.tan(phi);
  1887. c = tanphi * Math.sqrt (1.0 - eccent * sinphi * sinphi);
  1888. sin2ph = Math.sin (2.0 * phi);
  1889. /*
  1890. ml = e0 * *phi - e1 * sin2ph + e2 * sin (4.0 * *phi);
  1891. mlp = e0 - 2.0 * e1 * cos (2.0 * *phi) + 4.0 * e2 * cos (4.0 * *phi);
  1892. */
  1893. ml = e0 * phi - e1 * sin2ph + e2 * Math.sin (4.0 * phi) - e3 * Math.sin (6.0 * phi);
  1894. mlp = e0 - 2.0 * e1 * Math.cos (2.0 * phi) + 4.0 * e2 * Math.cos (4.0 * phi) - 6.0 * e3 * Math.cos (6.0 * phi);
  1895. con1 = 2.0 * ml + c * (ml * ml + b) - 2.0 * a * (c * ml + 1.0);
  1896. con2 = eccent * sin2ph * (ml * ml + b - 2.0 * a * ml) / (2.0 *c);
  1897. con3 = 2.0 * (a - ml) * (c * mlp - 2.0 / sin2ph) - 2.0 * mlp;
  1898. dphi = con1 / (con2 + con3);
  1899. phi += dphi;
  1900. if (Math.abs(dphi) <= .0000000001 ) return(phi);
  1901. }
  1902. Proj4js.reportError("phi4z: No convergence");
  1903. return null;
  1904. }
  1905. /* Function to compute the constant e4 from the input of the eccentricity
  1906. of the spheroid, x. This constant is used in the Polar Stereographic
  1907. projection.
  1908. --------------------------------------------------------------------*/
  1909. function e4fn(x) {
  1910. var con, com;
  1911. con = 1.0 + x;
  1912. com = 1.0 - x;
  1913. return (Math.sqrt((Math.pow(con,con))*(Math.pow(com,com))));
  1914. }
  1915. /*******************************************************************************
  1916. NAME POLYCONIC
  1917. PURPOSE: Transforms input longitude and latitude to Easting and
  1918. Northing for the Polyconic projection. The
  1919. longitude and latitude must be in radians. The Easting
  1920. and Northing values will be returned in meters.
  1921. PROGRAMMER DATE
  1922. ---------- ----
  1923. T. Mittan Mar, 1993
  1924. ALGORITHM REFERENCES
  1925. 1. Snyder, John P., "Map Projections--A Working Manual", U.S. Geological
  1926. Survey Professional Paper 1395 (Supersedes USGS Bulletin 1532), United
  1927. State Government Printing Office, Washington D.C., 1987.
  1928. 2. Snyder, John P. and Voxland, Philip M., "An Album of Map Projections",
  1929. U.S. Geological Survey Professional Paper 1453 , United State Government
  1930. Printing Office, Washington D.C., 1989.
  1931. *******************************************************************************/
  1932. Proj4js.Proj.poly = {
  1933. /* Initialize the POLYCONIC projection
  1934. ----------------------------------*/
  1935. init: function() {
  1936. var temp; /* temporary variable */
  1937. if (this.lat0 == 0) this.lat0 = 90;//this.lat0 ca
  1938. /* Place parameters in static storage for common use
  1939. -------------------------------------------------*/
  1940. this.temp = this.b / this.a;
  1941. this.es = 1.0 - Math.pow(this.temp,2);// devait etre dans tmerc.js mais n y est pas donc je commente sinon retour de valeurs nulles
  1942. this.e = Math.sqrt(this.es);
  1943. this.e0 = Proj4js.common.e0fn(this.es);
  1944. this.e1 = Proj4js.common.e1fn(this.es);
  1945. this.e2 = Proj4js.common.e2fn(this.es);
  1946. this.e3 = Proj4js.common.e3fn(this.es);
  1947. this.ml0 = Proj4js.common.mlfn(this.e0, this.e1,this.e2, this.e3, this.lat0);//si que des zeros le calcul ne se fait pas
  1948. //if (!this.ml0) {this.ml0=0;}
  1949. },
  1950. /* Polyconic forward equations--mapping lat,long to x,y
  1951. ---------------------------------------------------*/
  1952. forward: function(p) {
  1953. var sinphi, cosphi; /* sin and cos value */
  1954. var al; /* temporary values */
  1955. var c; /* temporary values */
  1956. var con, ml; /* cone constant, small m */
  1957. var ms; /* small m */
  1958. var x,y;
  1959. var lon=p.x;
  1960. var lat=p.y;
  1961. con = Proj4js.common.adjust_lon(lon - this.long0);
  1962. if (Math.abs(lat) <= .0000001) {
  1963. x = this.x0 + this.a * con;
  1964. y = this.y0 - this.a * this.ml0;
  1965. } else {
  1966. sinphi = Math.sin(lat);
  1967. cosphi = Math.cos(lat);
  1968. ml = Proj4js.common.mlfn(this.e0, this.e1, this.e2, this.e3, lat);
  1969. ms = Proj4js.common.msfnz(this.e,sinphi,cosphi);
  1970. con = sinphi;
  1971. x = this.x0 + this.a * ms * Math.sin(con)/sinphi;
  1972. y = this.y0 + this.a * (ml - this.ml0 + ms * (1.0 - Math.cos(con))/sinphi);
  1973. }
  1974. p.x=x;
  1975. p.y=y;
  1976. return p;
  1977. },
  1978. /* Inverse equations
  1979. -----------------*/
  1980. inverse: function(p) {
  1981. var sin_phi, cos_phi; /* sin and cos value */
  1982. var al; /* temporary values */
  1983. var b; /* temporary values */
  1984. var c; /* temporary values */
  1985. var con, ml; /* cone constant, small m */
  1986. var iflg; /* error flag */
  1987. var lon,lat;
  1988. p.x -= this.x0;
  1989. p.y -= this.y0;
  1990. al = this.ml0 + p.y/this.a;
  1991. iflg = 0;
  1992. if (Math.abs(al) <= .0000001) {
  1993. lon = p.x/this.a + this.long0;
  1994. lat = 0.0;
  1995. } else {
  1996. b = al * al + (p.x/this.a) * (p.x/this.a);
  1997. iflg = phi4z(this.es,this.e0,this.e1,this.e2,this.e3,this.al,b,c,lat);
  1998. if (iflg != 1) return(iflg);
  1999. lon = Proj4js.common.adjust_lon((Proj4js.common.asinz(p.x * c / this.a) / Math.sin(lat)) + this.long0);
  2000. }
  2001. p.x=lon;
  2002. p.y=lat;
  2003. return p;
  2004. }
  2005. };
  2006. /* ======================================================================
  2007. projCode/equi.js
  2008. ====================================================================== */
  2009. /*******************************************************************************
  2010. NAME EQUIRECTANGULAR
  2011. PURPOSE: Transforms input longitude and latitude to Easting and
  2012. Northing for the Equirectangular projection. The
  2013. longitude and latitude must be in radians. The Easting
  2014. and Northing values will be returned in meters.
  2015. PROGRAMMER DATE
  2016. ---------- ----
  2017. T. Mittan Mar, 1993
  2018. ALGORITHM REFERENCES
  2019. 1. Snyder, John P., "Map Projections--A Working Manual", U.S. Geological
  2020. Survey Professional Paper 1395 (Supersedes USGS Bulletin 1532), United
  2021. State Government Printing Office, Washington D.C., 1987.
  2022. 2. Snyder, John P. and Voxland, Philip M., "An Album of Map Projections",
  2023. U.S. Geological Survey Professional Paper 1453 , United State Government
  2024. Printing Office, Washington D.C., 1989.
  2025. *******************************************************************************/
  2026. Proj4js.Proj.equi = {
  2027. init: function() {
  2028. if(!this.x0) this.x0=0;
  2029. if(!this.y0) this.y0=0;
  2030. if(!this.lat0) this.lat0=0;
  2031. if(!this.long0) this.long0=0;
  2032. ///this.t2;
  2033. },
  2034. /* Equirectangular forward equations--mapping lat,long to x,y
  2035. ---------------------------------------------------------*/
  2036. forward: function(p) {
  2037. var lon=p.x;
  2038. var lat=p.y;
  2039. var dlon = Proj4js.common.adjust_lon(lon - this.long0);
  2040. var x = this.x0 +this. a * dlon *Math.cos(this.lat0);
  2041. var y = this.y0 + this.a * lat;
  2042. this.t1=x;
  2043. this.t2=Math.cos(this.lat0);
  2044. p.x=x;
  2045. p.y=y;
  2046. return p;
  2047. }, //equiFwd()
  2048. /* Equirectangular inverse equations--mapping x,y to lat/long
  2049. ---------------------------------------------------------*/
  2050. inverse: function(p) {
  2051. p.x -= this.x0;
  2052. p.y -= this.y0;
  2053. var lat = p.y /this. a;
  2054. if ( Math.abs(lat) > Proj4js.common.HALF_PI) {
  2055. Proj4js.reportError("equi:Inv:DataError");
  2056. }
  2057. var lon = Proj4js.common.adjust_lon(this.long0 + p.x / (this.a * Math.cos(this.lat0)));
  2058. p.x=lon;
  2059. p.y=lat;
  2060. }//equiInv()
  2061. };
  2062. /* ======================================================================
  2063. projCode/merc.js
  2064. ====================================================================== */
  2065. /*******************************************************************************
  2066. NAME MERCATOR
  2067. PURPOSE: Transforms input longitude and latitude to Easting and
  2068. Northing for the Mercator projection. The
  2069. longitude and latitude must be in radians. The Easting
  2070. and Northing values will be returned in meters.
  2071. PROGRAMMER DATE
  2072. ---------- ----
  2073. D. Steinwand, EROS Nov, 1991
  2074. T. Mittan Mar, 1993
  2075. ALGORITHM REFERENCES
  2076. 1. Snyder, John P., "Map Projections--A Working Manual", U.S. Geological
  2077. Survey Professional Paper 1395 (Supersedes USGS Bulletin 1532), United
  2078. State Government Printing Office, Washington D.C., 1987.
  2079. 2. Snyder, John P. and Voxland, Philip M., "An Album of Map Projections",
  2080. U.S. Geological Survey Professional Paper 1453 , United State Government
  2081. Printing Office, Washington D.C., 1989.
  2082. *******************************************************************************/
  2083. //static double r_major = a; /* major axis */
  2084. //static double r_minor = b; /* minor axis */
  2085. //static double lon_center = long0; /* Center longitude (projection center) */
  2086. //static double lat_origin = lat0; /* center latitude */
  2087. //static double e,es; /* eccentricity constants */
  2088. //static double m1; /* small value m */
  2089. //static double false_northing = y0; /* y offset in meters */
  2090. //static double false_easting = x0; /* x offset in meters */
  2091. //scale_fact = k0
  2092. Proj4js.Proj.merc = {
  2093. init : function() {
  2094. //?this.temp = this.r_minor / this.r_major;
  2095. //this.temp = this.b / this.a;
  2096. //this.es = 1.0 - Math.sqrt(this.temp);
  2097. //this.e = Math.sqrt( this.es );
  2098. //?this.m1 = Math.cos(this.lat_origin) / (Math.sqrt( 1.0 - this.es * Math.sin(this.lat_origin) * Math.sin(this.lat_origin)));
  2099. //this.m1 = Math.cos(0.0) / (Math.sqrt( 1.0 - this.es * Math.sin(0.0) * Math.sin(0.0)));
  2100. if (this.lat_ts) {
  2101. if (this.sphere) {
  2102. this.k0 = Math.cos(this.lat_ts);
  2103. } else {
  2104. this.k0 = Proj4js.common.msfnz(this.es, Math.sin(this.lat_ts), Math.cos(this.lat_ts));
  2105. }
  2106. }
  2107. },
  2108. /* Mercator forward equations--mapping lat,long to x,y
  2109. --------------------------------------------------*/
  2110. forward : function(p) {
  2111. //alert("ll2m coords : "+coords);
  2112. var lon = p.x;
  2113. var lat = p.y;
  2114. // convert to radians
  2115. if ( lat*Proj4js.common.R2D > 90.0 &&
  2116. lat*Proj4js.common.R2D < -90.0 &&
  2117. lon*Proj4js.common.R2D > 180.0 &&
  2118. lon*Proj4js.common.R2D < -180.0) {
  2119. Proj4js.reportError("merc:forward: llInputOutOfRange: "+ lon +" : " + lat);
  2120. return null;
  2121. }
  2122. var x,y;
  2123. if(Math.abs( Math.abs(lat) - Proj4js.common.HALF_PI) <= Proj4js.common.EPSLN) {
  2124. Proj4js.reportError("merc:forward: ll2mAtPoles");
  2125. return null;
  2126. } else {
  2127. if (this.sphere) {
  2128. x = this.x0 + this.a * this.k0 * Proj4js.common.adjust_lon(lon - this.long0);
  2129. y = this.y0 + this.a * this.k0 * Math.log(Math.tan(Proj4js.common.FORTPI + 0.5*lat));
  2130. } else {
  2131. var sinphi = Math.sin(lat);
  2132. var ts = Proj4js.common.tsfnz(this.e,lat,sinphi);
  2133. x = this.x0 + this.a * this.k0 * Proj4js.common.adjust_lon(lon - this.long0);
  2134. y = this.y0 - this.a * this.k0 * Math.log(ts);
  2135. }
  2136. p.x = x;
  2137. p.y = y;
  2138. return p;
  2139. }
  2140. },
  2141. /* Mercator inverse equations--mapping x,y to lat/long
  2142. --------------------------------------------------*/
  2143. inverse : function(p) {
  2144. var x = p.x - this.x0;
  2145. var y = p.y - this.y0;
  2146. var lon,lat;
  2147. if (this.sphere) {
  2148. lat = Proj4js.common.HALF_PI - 2.0 * Math.atan(Math.exp(-y / this.a * this.k0));
  2149. } else {
  2150. var ts = Math.exp(-y / (this.a * this.k0));
  2151. lat = Proj4js.common.phi2z(this.e,ts);
  2152. if(lat == -9999) {
  2153. Proj4js.reportError("merc:inverse: lat = -9999");
  2154. return null;
  2155. }
  2156. }
  2157. lon = Proj4js.common.adjust_lon(this.long0+ x / (this.a * this.k0));
  2158. p.x = lon;
  2159. p.y = lat;
  2160. return p;
  2161. }
  2162. };
  2163. /* ======================================================================
  2164. projCode/utm.js
  2165. ====================================================================== */
  2166. /*******************************************************************************
  2167. NAME TRANSVERSE MERCATOR
  2168. PURPOSE: Transforms input longitude and latitude to Easting and
  2169. Northing for the Transverse Mercator projection. The
  2170. longitude and latitude must be in radians. The Easting
  2171. and Northing values will be returned in meters.
  2172. ALGORITHM REFERENCES
  2173. 1. Snyder, John P., "Map Projections--A Working Manual", U.S. Geological
  2174. Survey Professional Paper 1395 (Supersedes USGS Bulletin 1532), United
  2175. State Government Printing Office, Washington D.C., 1987.
  2176. 2. Snyder, John P. and Voxland, Philip M., "An Album of Map Projections",
  2177. U.S. Geological Survey Professional Paper 1453 , United State Government
  2178. Printing Office, Washington D.C., 1989.
  2179. *******************************************************************************/
  2180. /**
  2181. Initialize Transverse Mercator projection
  2182. */
  2183. Proj4js.Proj.utm = {
  2184. dependsOn : 'tmerc',
  2185. init : function() {
  2186. if (!this.zone) {
  2187. Proj4js.reportError("utm:init: zone must be specified for UTM");
  2188. return;
  2189. }
  2190. this.lat0 = 0.0;
  2191. this.long0 = ((6 * Math.abs(this.zone)) - 183) * Proj4js.common.D2R;
  2192. this.x0 = 500000.0;
  2193. this.y0 = this.utmSouth ? 10000000.0 : 0.0;
  2194. this.k0 = 0.9996;
  2195. Proj4js.Proj['tmerc'].init.apply(this);
  2196. this.forward = Proj4js.Proj['tmerc'].forward;
  2197. this.inverse = Proj4js.Proj['tmerc'].inverse;
  2198. }
  2199. };
  2200. /* ======================================================================
  2201. projCode/eqdc.js
  2202. ====================================================================== */
  2203. /*******************************************************************************
  2204. NAME EQUIDISTANT CONIC
  2205. PURPOSE: Transforms input longitude and latitude to Easting and Northing
  2206. for the Equidistant Conic projection. The longitude and
  2207. latitude must be in radians. The Easting and Northing values
  2208. will be returned in meters.
  2209. PROGRAMMER DATE
  2210. ---------- ----
  2211. T. Mittan Mar, 1993
  2212. ALGORITHM REFERENCES
  2213. 1. Snyder, John P., "Map Projections--A Working Manual", U.S. Geological
  2214. Survey Professional Paper 1395 (Supersedes USGS Bulletin 1532), United
  2215. State Government Printing Office, Washington D.C., 1987.
  2216. 2. Snyder, John P. and Voxland, Philip M., "An Album of Map Projections",
  2217. U.S. Geological Survey Professional Paper 1453 , United State Government
  2218. Printing Office, Washington D.C., 1989.
  2219. *******************************************************************************/
  2220. /* Variables common to all subroutines in this code file
  2221. -----------------------------------------------------*/
  2222. Proj4js.Proj.eqdc = {
  2223. /* Initialize the Equidistant Conic projection
  2224. ------------------------------------------*/
  2225. init: function() {
  2226. /* Place parameters in static storage for common use
  2227. -------------------------------------------------*/
  2228. if(!this.mode) this.mode=0;//chosen default mode
  2229. this.temp = this.b / this.a;
  2230. this.es = 1.0 - Math.pow(this.temp,2);
  2231. this.e = Math.sqrt(this.es);
  2232. this.e0 = Proj4js.common.e0fn(this.es);
  2233. this.e1 = Proj4js.common.e1fn(this.es);
  2234. this.e2 = Proj4js.common.e2fn(this.es);
  2235. this.e3 = Proj4js.common.e3fn(this.es);
  2236. this.sinphi=Math.sin(this.lat1);
  2237. this.cosphi=Math.cos(this.lat1);
  2238. this.ms1 = Proj4js.common.msfnz(this.e,this.sinphi,this.cosphi);
  2239. this.ml1 = Proj4js.common.mlfn(this.e0, this.e1, this.e2,this.e3, this.lat1);
  2240. /* format B
  2241. ---------*/
  2242. if (this.mode != 0) {
  2243. if (Math.abs(this.lat1 + this.lat2) < Proj4js.common.EPSLN) {
  2244. Proj4js.reportError("eqdc:Init:EqualLatitudes");
  2245. //return(81);
  2246. }
  2247. this.sinphi=Math.sin(this.lat2);
  2248. this.cosphi=Math.cos(this.lat2);
  2249. this.ms2 = Proj4js.common.msfnz(this.e,this.sinphi,this.cosphi);
  2250. this.ml2 = Proj4js.common.mlfn(this.e0, this.e1, this.e2, this.e3, this.lat2);
  2251. if (Math.abs(this.lat1 - this.lat2) >= Proj4js.common.EPSLN) {
  2252. this.ns = (this.ms1 - this.ms2) / (this.ml2 - this.ml1);
  2253. } else {
  2254. this.ns = this.sinphi;
  2255. }
  2256. } else {
  2257. this.ns = this.sinphi;
  2258. }
  2259. this.g = this.ml1 + this.ms1/this.ns;
  2260. this.ml0 = Proj4js.common.mlfn(this.e0, this.e1,this. e2, this.e3, this.lat0);
  2261. this.rh = this.a * (this.g - this.ml0);
  2262. },
  2263. /* Equidistant Conic forward equations--mapping lat,long to x,y
  2264. -----------------------------------------------------------*/
  2265. forward: function(p) {
  2266. var lon=p.x;
  2267. var lat=p.y;
  2268. /* Forward equations
  2269. -----------------*/
  2270. var ml = Proj4js.common.mlfn(this.e0, this.e1, this.e2, this.e3, lat);
  2271. var rh1 = this.a * (this.g - ml);
  2272. var theta = this.ns * Proj4js.common.adjust_lon(lon - this.long0);
  2273. var x = this.x0 + rh1 * Math.sin(theta);
  2274. var y = this.y0 + this.rh - rh1 * Math.cos(theta);
  2275. p.x=x;
  2276. p.y=y;
  2277. return p;
  2278. },
  2279. /* Inverse equations
  2280. -----------------*/
  2281. inverse: function(p) {
  2282. p.x -= this.x0;
  2283. p.y = this.rh - p.y + this.y0;
  2284. var con, rh1;
  2285. if (this.ns >= 0) {
  2286. rh1 = Math.sqrt(p.x *p.x + p.y * p.y);
  2287. con = 1.0;
  2288. } else {
  2289. rh1 = -Math.sqrt(p.x *p. x +p. y * p.y);
  2290. con = -1.0;
  2291. }
  2292. var theta = 0.0;
  2293. if (rh1 != 0.0) theta = Math.atan2(con *p.x, con *p.y);
  2294. var ml = this.g - rh1 /this.a;
  2295. var lat = this.phi3z(ml,this.e0,this.e1,this.e2,this.e3);
  2296. var lon = Proj4js.common.adjust_lon(this.long0 + theta / this.ns);
  2297. p.x=lon;
  2298. p.y=lat;
  2299. return p;
  2300. },
  2301. /* Function to compute latitude, phi3, for the inverse of the Equidistant
  2302. Conic projection.
  2303. -----------------------------------------------------------------*/
  2304. phi3z: function(ml,e0,e1,e2,e3) {
  2305. var phi;
  2306. var dphi;
  2307. phi = ml;
  2308. for (var i = 0; i < 15; i++) {
  2309. dphi = (ml + e1 * Math.sin(2.0 * phi) - e2 * Math.sin(4.0 * phi) + e3 * Math.sin(6.0 * phi))/ e0 - phi;
  2310. phi += dphi;
  2311. if (Math.abs(dphi) <= .0000000001) {
  2312. return phi;
  2313. }
  2314. }
  2315. Proj4js.reportError("PHI3Z-CONV:Latitude failed to converge after 15 iterations");
  2316. return null;
  2317. }
  2318. };
  2319. /* ======================================================================
  2320. projCode/tmerc.js
  2321. ====================================================================== */
  2322. /*******************************************************************************
  2323. NAME TRANSVERSE MERCATOR
  2324. PURPOSE: Transforms input longitude and latitude to Easting and
  2325. Northing for the Transverse Mercator projection. The
  2326. longitude and latitude must be in radians. The Easting
  2327. and Northing values will be returned in meters.
  2328. ALGORITHM REFERENCES
  2329. 1. Snyder, John P., "Map Projections--A Working Manual", U.S. Geological
  2330. Survey Professional Paper 1395 (Supersedes USGS Bulletin 1532), United
  2331. State Government Printing Office, Washington D.C., 1987.
  2332. 2. Snyder, John P. and Voxland, Philip M., "An Album of Map Projections",
  2333. U.S. Geological Survey Professional Paper 1453 , United State Government
  2334. Printing Office, Washington D.C., 1989.
  2335. *******************************************************************************/
  2336. /**
  2337. Initialize Transverse Mercator projection
  2338. */
  2339. Proj4js.Proj.tmerc = {
  2340. init : function() {
  2341. this.e0 = Proj4js.common.e0fn(this.es);
  2342. this.e1 = Proj4js.common.e1fn(this.es);
  2343. this.e2 = Proj4js.common.e2fn(this.es);
  2344. this.e3 = Proj4js.common.e3fn(this.es);
  2345. this.ml0 = this.a * Proj4js.common.mlfn(this.e0, this.e1, this.e2, this.e3, this.lat0);
  2346. },
  2347. /**
  2348. Transverse Mercator Forward - long/lat to x/y
  2349. long/lat in radians
  2350. */
  2351. forward : function(p) {
  2352. var lon = p.x;
  2353. var lat = p.y;
  2354. var delta_lon = Proj4js.common.adjust_lon(lon - this.long0); // Delta longitude
  2355. var con; // cone constant
  2356. var x, y;
  2357. var sin_phi=Math.sin(lat);
  2358. var cos_phi=Math.cos(lat);
  2359. if (this.sphere) { /* spherical form */
  2360. var b = cos_phi * Math.sin(delta_lon);
  2361. if ((Math.abs(Math.abs(b) - 1.0)) < .0000000001) {
  2362. Proj4js.reportError("tmerc:forward: Point projects into infinity");
  2363. return(93);
  2364. } else {
  2365. x = .5 * this.a * this.k0 * Math.log((1.0 + b)/(1.0 - b));
  2366. con = Math.acos(cos_phi * Math.cos(delta_lon)/Math.sqrt(1.0 - b*b));
  2367. if (lat < 0) con = - con;
  2368. y = this.a * this.k0 * (con - this.lat0);
  2369. }
  2370. } else {
  2371. var al = cos_phi * delta_lon;
  2372. var als = Math.pow(al,2);
  2373. var c = this.ep2 * Math.pow(cos_phi,2);
  2374. var tq = Math.tan(lat);
  2375. var t = Math.pow(tq,2);
  2376. con = 1.0 - this.es * Math.pow(sin_phi,2);
  2377. var n = this.a / Math.sqrt(con);
  2378. var ml = this.a * Proj4js.common.mlfn(this.e0, this.e1, this.e2, this.e3, lat);
  2379. x = this.k0 * n * al * (1.0 + als / 6.0 * (1.0 - t + c + als / 20.0 * (5.0 - 18.0 * t + Math.pow(t,2) + 72.0 * c - 58.0 * this.ep2))) + this.x0;
  2380. y = this.k0 * (ml - this.ml0 + n * tq * (als * (0.5 + als / 24.0 * (5.0 - t + 9.0 * c + 4.0 * Math.pow(c,2) + als / 30.0 * (61.0 - 58.0 * t + Math.pow(t,2) + 600.0 * c - 330.0 * this.ep2))))) + this.y0;
  2381. }
  2382. p.x = x; p.y = y;
  2383. return p;
  2384. }, // tmercFwd()
  2385. /**
  2386. Transverse Mercator Inverse - x/y to long/lat
  2387. */
  2388. inverse : function(p) {
  2389. var con, phi; /* temporary angles */
  2390. var delta_phi; /* difference between longitudes */
  2391. var i;
  2392. var max_iter = 6; /* maximun number of iterations */
  2393. var lat, lon;
  2394. if (this.sphere) { /* spherical form */
  2395. var f = Math.exp(p.x/(this.a * this.k0));
  2396. var g = .5 * (f - 1/f);
  2397. var temp = this.lat0 + p.y/(this.a * this.k0);
  2398. var h = Math.cos(temp);
  2399. con = Math.sqrt((1.0 - h * h)/(1.0 + g * g));
  2400. lat = Proj4js.common.asinz(con);
  2401. if (temp < 0)
  2402. lat = -lat;
  2403. if ((g == 0) && (h == 0)) {
  2404. lon = this.long0;
  2405. } else {
  2406. lon = Proj4js.common.adjust_lon(Math.atan2(g,h) + this.long0);
  2407. }
  2408. } else { // ellipsoidal form
  2409. var x = p.x - this.x0;
  2410. var y = p.y - this.y0;
  2411. con = (this.ml0 + y / this.k0) / this.a;
  2412. phi = con;
  2413. for (i=0;true;i++) {
  2414. delta_phi=((con + this.e1 * Math.sin(2.0*phi) - this.e2 * Math.sin(4.0*phi) + this.e3 * Math.sin(6.0*phi)) / this.e0) - phi;
  2415. phi += delta_phi;
  2416. if (Math.abs(delta_phi) <= Proj4js.common.EPSLN) break;
  2417. if (i >= max_iter) {
  2418. Proj4js.reportError("tmerc:inverse: Latitude failed to converge");
  2419. return(95);
  2420. }
  2421. } // for()
  2422. if (Math.abs(phi) < Proj4js.common.HALF_PI) {
  2423. // sincos(phi, &sin_phi, &cos_phi);
  2424. var sin_phi=Math.sin(phi);
  2425. var cos_phi=Math.cos(phi);
  2426. var tan_phi = Math.tan(phi);
  2427. var c = this.ep2 * Math.pow(cos_phi,2);
  2428. var cs = Math.pow(c,2);
  2429. var t = Math.pow(tan_phi,2);
  2430. var ts = Math.pow(t,2);
  2431. con = 1.0 - this.es * Math.pow(sin_phi,2);
  2432. var n = this.a / Math.sqrt(con);
  2433. var r = n * (1.0 - this.es) / con;
  2434. var d = x / (n * this.k0);
  2435. var ds = Math.pow(d,2);
  2436. lat = phi - (n * tan_phi * ds / r) * (0.5 - ds / 24.0 * (5.0 + 3.0 * t + 10.0 * c - 4.0 * cs - 9.0 * this.ep2 - ds / 30.0 * (61.0 + 90.0 * t + 298.0 * c + 45.0 * ts - 252.0 * this.ep2 - 3.0 * cs)));
  2437. lon = Proj4js.common.adjust_lon(this.long0 + (d * (1.0 - ds / 6.0 * (1.0 + 2.0 * t + c - ds / 20.0 * (5.0 - 2.0 * c + 28.0 * t - 3.0 * cs + 8.0 * this.ep2 + 24.0 * ts))) / cos_phi));
  2438. } else {
  2439. lat = Proj4js.common.HALF_PI * Proj4js.common.sign(y);
  2440. lon = this.long0;
  2441. }
  2442. }
  2443. p.x = lon;
  2444. p.y = lat;
  2445. return p;
  2446. } // tmercInv()
  2447. };
  2448. /* ======================================================================
  2449. defs/GOOGLE.js
  2450. ====================================================================== */
  2451. Proj4js.defs["GOOGLE"]="+proj=merc +a=6378137 +b=6378137 +lat_ts=0.0 +lon_0=0.0 +x_0=0.0 +y_0=0 +k=1.0 +units=m +nadgrids=@null +no_defs";
  2452. Proj4js.defs["EPSG:900913"]=Proj4js.defs["GOOGLE"];
  2453. /* ======================================================================
  2454. projCode/gstmerc.js
  2455. ====================================================================== */
  2456. Proj4js.Proj.gstmerc = {
  2457. init : function() {
  2458. // array of: a, b, lon0, lat0, k0, x0, y0
  2459. var temp= this.b / this.a;
  2460. this.e= Math.sqrt(1.0 - temp*temp);
  2461. this.lc= this.long0;
  2462. this.rs= Math.sqrt(1.0+this.e*this.e*Math.pow(Math.cos(this.lat0),4.0)/(1.0-this.e*this.e));
  2463. var sinz= Math.sin(this.lat0);
  2464. var pc= Math.asin(sinz/this.rs);
  2465. var sinzpc= Math.sin(pc);
  2466. this.cp= Proj4js.common.latiso(0.0,pc,sinzpc)-this.rs*Proj4js.common.latiso(this.e,this.lat0,sinz);
  2467. this.n2= this.k0*this.a*Math.sqrt(1.0-this.e*this.e)/(1.0-this.e*this.e*sinz*sinz);
  2468. this.xs= this.x0;
  2469. this.ys= this.y0-this.n2*pc;
  2470. if (!this.title) this.title = "Gauss Schreiber transverse mercator";
  2471. },
  2472. // forward equations--mapping lat,long to x,y
  2473. // -----------------------------------------------------------------
  2474. forward : function(p) {
  2475. var lon= p.x;
  2476. var lat= p.y;
  2477. var L= this.rs*(lon-this.lc);
  2478. var Ls= this.cp+(this.rs*Proj4js.common.latiso(this.e,lat,Math.sin(lat)));
  2479. var lat1= Math.asin(Math.sin(L)/Proj4js.common.cosh(Ls));
  2480. var Ls1= Proj4js.common.latiso(0.0,lat1,Math.sin(lat1));
  2481. p.x= this.xs+(this.n2*Ls1);
  2482. p.y= this.ys+(this.n2*Math.atan(Proj4js.common.sinh(Ls)/Math.cos(L)));
  2483. return p;
  2484. },
  2485. // inverse equations--mapping x,y to lat/long
  2486. // -----------------------------------------------------------------
  2487. inverse : function(p) {
  2488. var x= p.x;
  2489. var y= p.y;
  2490. var L= Math.atan(Proj4js.common.sinh((x-this.xs)/this.n2)/Math.cos((y-this.ys)/this.n2));
  2491. var lat1= Math.asin(Math.sin((y-this.ys)/this.n2)/Proj4js.common.cosh((x-this.xs)/this.n2));
  2492. var LC= Proj4js.common.latiso(0.0,lat1,Math.sin(lat1));
  2493. p.x= this.lc+L/this.rs;
  2494. p.y= Proj4js.common.invlatiso(this.e,(LC-this.cp)/this.rs);
  2495. return p;
  2496. }
  2497. };
  2498. /* ======================================================================
  2499. projCode/ortho.js
  2500. ====================================================================== */
  2501. /*******************************************************************************
  2502. NAME ORTHOGRAPHIC
  2503. PURPOSE: Transforms input longitude and latitude to Easting and
  2504. Northing for the Orthographic projection. The
  2505. longitude and latitude must be in radians. The Easting
  2506. and Northing values will be returned in meters.
  2507. PROGRAMMER DATE
  2508. ---------- ----
  2509. T. Mittan Mar, 1993
  2510. ALGORITHM REFERENCES
  2511. 1. Snyder, John P., "Map Projections--A Working Manual", U.S. Geological
  2512. Survey Professional Paper 1395 (Supersedes USGS Bulletin 1532), United
  2513. State Government Printing Office, Washington D.C., 1987.
  2514. 2. Snyder, John P. and Voxland, Philip M., "An Album of Map Projections",
  2515. U.S. Geological Survey Professional Paper 1453 , United State Government
  2516. Printing Office, Washington D.C., 1989.
  2517. *******************************************************************************/
  2518. Proj4js.Proj.ortho = {
  2519. /* Initialize the Orthographic projection
  2520. -------------------------------------*/
  2521. init: function(def) {
  2522. //double temp; /* temporary variable */
  2523. /* Place parameters in static storage for common use
  2524. -------------------------------------------------*/;
  2525. this.sin_p14=Math.sin(this.lat0);
  2526. this.cos_p14=Math.cos(this.lat0);
  2527. },
  2528. /* Orthographic forward equations--mapping lat,long to x,y
  2529. ---------------------------------------------------*/
  2530. forward: function(p) {
  2531. var sinphi, cosphi; /* sin and cos value */
  2532. var dlon; /* delta longitude value */
  2533. var coslon; /* cos of longitude */
  2534. var ksp; /* scale factor */
  2535. var g;
  2536. var lon=p.x;
  2537. var lat=p.y;
  2538. /* Forward equations
  2539. -----------------*/
  2540. dlon = Proj4js.common.adjust_lon(lon - this.long0);
  2541. sinphi=Math.sin(lat);
  2542. cosphi=Math.cos(lat);
  2543. coslon = Math.cos(dlon);
  2544. g = this.sin_p14 * sinphi + this.cos_p14 * cosphi * coslon;
  2545. ksp = 1.0;
  2546. if ((g > 0) || (Math.abs(g) <= Proj4js.common.EPSLN)) {
  2547. var x = this.a * ksp * cosphi * Math.sin(dlon);
  2548. var y = this.y0 + this.a * ksp * (this.cos_p14 * sinphi - this.sin_p14 * cosphi * coslon);
  2549. } else {
  2550. Proj4js.reportError("orthoFwdPointError");
  2551. }
  2552. p.x=x;
  2553. p.y=y;
  2554. return p;
  2555. },
  2556. inverse: function(p) {
  2557. var rh; /* height above ellipsoid */
  2558. var z; /* angle */
  2559. var sinz,cosz; /* sin of z and cos of z */
  2560. var temp;
  2561. var con;
  2562. var lon , lat;
  2563. /* Inverse equations
  2564. -----------------*/
  2565. p.x -= this.x0;
  2566. p.y -= this.y0;
  2567. rh = Math.sqrt(p.x * p.x + p.y * p.y);
  2568. if (rh > this.a + .0000001) {
  2569. Proj4js.reportError("orthoInvDataError");
  2570. }
  2571. z = Proj4js.common.asinz(rh / this.a);
  2572. sinz=Math.sin(z);
  2573. cosz=Math.cos(z);
  2574. lon = this.long0;
  2575. if (Math.abs(rh) <= Proj4js.common.EPSLN) {
  2576. lat = this.lat0;
  2577. }
  2578. lat = Proj4js.common.asinz(cosz * this.sin_p14 + (p.y * sinz * this.cos_p14)/rh);
  2579. con = Math.abs(this.lat0) - Proj4js.common.HALF_PI;
  2580. if (Math.abs(con) <= Proj4js.common.EPSLN) {
  2581. if (this.lat0 >= 0) {
  2582. lon = Proj4js.common.adjust_lon(this.long0 + Math.atan2(p.x, -p.y));
  2583. } else {
  2584. lon = Proj4js.common.adjust_lon(this.long0 -Math.atan2(-p.x, p.y));
  2585. }
  2586. }
  2587. con = cosz - this.sin_p14 * Math.sin(lat);
  2588. p.x=lon;
  2589. p.y=lat;
  2590. return p;
  2591. }
  2592. };
  2593. /* ======================================================================
  2594. projCode/krovak.js
  2595. ====================================================================== */
  2596. /**
  2597. NOTES: According to EPSG the full Krovak projection method should have
  2598. the following parameters. Within PROJ.4 the azimuth, and pseudo
  2599. standard parallel are hardcoded in the algorithm and can't be
  2600. altered from outside. The others all have defaults to match the
  2601. common usage with Krovak projection.
  2602. lat_0 = latitude of centre of the projection
  2603. lon_0 = longitude of centre of the projection
  2604. ** = azimuth (true) of the centre line passing through the centre of the projection
  2605. ** = latitude of pseudo standard parallel
  2606. k = scale factor on the pseudo standard parallel
  2607. x_0 = False Easting of the centre of the projection at the apex of the cone
  2608. y_0 = False Northing of the centre of the projection at the apex of the cone
  2609. **/
  2610. Proj4js.Proj.krovak = {
  2611. init: function() {
  2612. /* we want Bessel as fixed ellipsoid */
  2613. this.a = 6377397.155;
  2614. this.es = 0.006674372230614;
  2615. this.e = Math.sqrt(this.es);
  2616. /* if latitude of projection center is not set, use 49d30'N */
  2617. if (!this.lat0) {
  2618. this.lat0 = 0.863937979737193;
  2619. }
  2620. if (!this.long0) {
  2621. this.long0 = 0.7417649320975901 - 0.308341501185665;
  2622. }
  2623. /* if scale not set default to 0.9999 */
  2624. if (!this.k0) {
  2625. this.k0 = 0.9999;
  2626. }
  2627. this.s45 = 0.785398163397448; /* 45? */
  2628. this.s90 = 2 * this.s45;
  2629. this.fi0 = this.lat0; /* Latitude of projection centre 49? 30' */
  2630. /* Ellipsoid Bessel 1841 a = 6377397.155m 1/f = 299.1528128,
  2631. e2=0.006674372230614;
  2632. */
  2633. this.e2 = this.es; /* 0.006674372230614; */
  2634. this.e = Math.sqrt(this.e2);
  2635. this.alfa = Math.sqrt(1. + (this.e2 * Math.pow(Math.cos(this.fi0), 4)) / (1. - this.e2));
  2636. this.uq = 1.04216856380474; /* DU(2, 59, 42, 42.69689) */
  2637. this.u0 = Math.asin(Math.sin(this.fi0) / this.alfa);
  2638. this.g = Math.pow( (1. + this.e * Math.sin(this.fi0)) / (1. - this.e * Math.sin(this.fi0)) , this.alfa * this.e / 2. );
  2639. this.k = Math.tan( this.u0 / 2. + this.s45) / Math.pow (Math.tan(this.fi0 / 2. + this.s45) , this.alfa) * this.g;
  2640. this.k1 = this.k0;
  2641. this.n0 = this.a * Math.sqrt(1. - this.e2) / (1. - this.e2 * Math.pow(Math.sin(this.fi0), 2));
  2642. this.s0 = 1.37008346281555; /* Latitude of pseudo standard parallel 78? 30'00" N */
  2643. this.n = Math.sin(this.s0);
  2644. this.ro0 = this.k1 * this.n0 / Math.tan(this.s0);
  2645. this.ad = this.s90 - this.uq;
  2646. },
  2647. /* ellipsoid */
  2648. /* calculate xy from lat/lon */
  2649. /* Constants, identical to inverse transform function */
  2650. forward: function(p) {
  2651. var gfi, u, deltav, s, d, eps, ro;
  2652. var lon = p.x;
  2653. var lat = p.y;
  2654. var delta_lon = Proj4js.common.adjust_lon(lon - this.long0); // Delta longitude
  2655. /* Transformation */
  2656. gfi = Math.pow ( ((1. + this.e * Math.sin(lat)) / (1. - this.e * Math.sin(lat))) , (this.alfa * this.e / 2.));
  2657. u= 2. * (Math.atan(this.k * Math.pow( Math.tan(lat / 2. + this.s45), this.alfa) / gfi)-this.s45);
  2658. deltav = - delta_lon * this.alfa;
  2659. s = Math.asin(Math.cos(this.ad) * Math.sin(u) + Math.sin(this.ad) * Math.cos(u) * Math.cos(deltav));
  2660. d = Math.asin(Math.cos(u) * Math.sin(deltav) / Math.cos(s));
  2661. eps = this.n * d;
  2662. ro = this.ro0 * Math.pow(Math.tan(this.s0 / 2. + this.s45) , this.n) / Math.pow(Math.tan(s / 2. + this.s45) , this.n);
  2663. /* x and y are reverted! */
  2664. //p.y = ro * Math.cos(eps) / a;
  2665. //p.x = ro * Math.sin(eps) / a;
  2666. p.y = ro * Math.cos(eps) / 1.0;
  2667. p.x = ro * Math.sin(eps) / 1.0;
  2668. if(this.czech) {
  2669. p.y *= -1.0;
  2670. p.x *= -1.0;
  2671. }
  2672. return (p);
  2673. },
  2674. /* calculate lat/lon from xy */
  2675. inverse: function(p) {
  2676. /* Constants, identisch wie in der Umkehrfunktion */
  2677. var u, deltav, s, d, eps, ro, fi1;
  2678. var ok;
  2679. /* Transformation */
  2680. /* revert y, x*/
  2681. var tmp = p.x;
  2682. p.x=p.y;
  2683. p.y=tmp;
  2684. if(this.czech) {
  2685. p.y *= -1.0;
  2686. p.x *= -1.0;
  2687. }
  2688. ro = Math.sqrt(p.x * p.x + p.y * p.y);
  2689. eps = Math.atan2(p.y, p.x);
  2690. d = eps / Math.sin(this.s0);
  2691. s = 2. * (Math.atan( Math.pow(this.ro0 / ro, 1. / this.n) * Math.tan(this.s0 / 2. + this.s45)) - this.s45);
  2692. u = Math.asin(Math.cos(this.ad) * Math.sin(s) - Math.sin(this.ad) * Math.cos(s) * Math.cos(d));
  2693. deltav = Math.asin(Math.cos(s) * Math.sin(d) / Math.cos(u));
  2694. p.x = this.long0 - deltav / this.alfa;
  2695. /* ITERATION FOR lat */
  2696. fi1 = u;
  2697. ok = 0;
  2698. var iter = 0;
  2699. do {
  2700. p.y = 2. * ( Math.atan( Math.pow( this.k, -1. / this.alfa) *
  2701. Math.pow( Math.tan(u / 2. + this.s45) , 1. / this.alfa) *
  2702. Math.pow( (1. + this.e * Math.sin(fi1)) / (1. - this.e * Math.sin(fi1)) , this.e / 2.)
  2703. ) - this.s45);
  2704. if (Math.abs(fi1 - p.y) < 0.0000000001) ok=1;
  2705. fi1 = p.y;
  2706. iter += 1;
  2707. } while (ok==0 && iter < 15);
  2708. if (iter >= 15) {
  2709. Proj4js.reportError("PHI3Z-CONV:Latitude failed to converge after 15 iterations");
  2710. //console.log('iter:', iter);
  2711. return null;
  2712. }
  2713. return (p);
  2714. }
  2715. };
  2716. /* ======================================================================
  2717. projCode/somerc.js
  2718. ====================================================================== */
  2719. /*******************************************************************************
  2720. NAME SWISS OBLIQUE MERCATOR
  2721. PURPOSE: Swiss projection.
  2722. WARNING: X and Y are inverted (weird) in the swiss coordinate system. Not
  2723. here, since we want X to be horizontal and Y vertical.
  2724. ALGORITHM REFERENCES
  2725. 1. "Formules et constantes pour le Calcul pour la
  2726. projection cylindrique conforme à axe oblique et pour la transformation entre
  2727. des systèmes de référence".
  2728. http://www.swisstopo.admin.ch/internet/swisstopo/fr/home/topics/survey/sys/refsys/switzerland.parsysrelated1.31216.downloadList.77004.DownloadFile.tmp/swissprojectionfr.pdf
  2729. *******************************************************************************/
  2730. Proj4js.Proj.somerc = {
  2731. init: function() {
  2732. var phy0 = this.lat0;
  2733. this.lambda0 = this.long0;
  2734. var sinPhy0 = Math.sin(phy0);
  2735. var semiMajorAxis = this.a;
  2736. var invF = this.rf;
  2737. var flattening = 1 / invF;
  2738. var e2 = 2 * flattening - Math.pow(flattening, 2);
  2739. var e = this.e = Math.sqrt(e2);
  2740. this.R = this.k0 * semiMajorAxis * Math.sqrt(1 - e2) / (1 - e2 * Math.pow(sinPhy0, 2.0));
  2741. this.alpha = Math.sqrt(1 + e2 / (1 - e2) * Math.pow(Math.cos(phy0), 4.0));
  2742. this.b0 = Math.asin(sinPhy0 / this.alpha);
  2743. this.K = Math.log(Math.tan(Math.PI / 4.0 + this.b0 / 2.0))
  2744. - this.alpha
  2745. * Math.log(Math.tan(Math.PI / 4.0 + phy0 / 2.0))
  2746. + this.alpha
  2747. * e / 2
  2748. * Math.log((1 + e * sinPhy0)
  2749. / (1 - e * sinPhy0));
  2750. },
  2751. forward: function(p) {
  2752. var Sa1 = Math.log(Math.tan(Math.PI / 4.0 - p.y / 2.0));
  2753. var Sa2 = this.e / 2.0
  2754. * Math.log((1 + this.e * Math.sin(p.y))
  2755. / (1 - this.e * Math.sin(p.y)));
  2756. var S = -this.alpha * (Sa1 + Sa2) + this.K;
  2757. // spheric latitude
  2758. var b = 2.0 * (Math.atan(Math.exp(S)) - Math.PI / 4.0);
  2759. // spheric longitude
  2760. var I = this.alpha * (p.x - this.lambda0);
  2761. // psoeudo equatorial rotation
  2762. var rotI = Math.atan(Math.sin(I)
  2763. / (Math.sin(this.b0) * Math.tan(b) +
  2764. Math.cos(this.b0) * Math.cos(I)));
  2765. var rotB = Math.asin(Math.cos(this.b0) * Math.sin(b) -
  2766. Math.sin(this.b0) * Math.cos(b) * Math.cos(I));
  2767. p.y = this.R / 2.0
  2768. * Math.log((1 + Math.sin(rotB)) / (1 - Math.sin(rotB)))
  2769. + this.y0;
  2770. p.x = this.R * rotI + this.x0;
  2771. return p;
  2772. },
  2773. inverse: function(p) {
  2774. var Y = p.x - this.x0;
  2775. var X = p.y - this.y0;
  2776. var rotI = Y / this.R;
  2777. var rotB = 2 * (Math.atan(Math.exp(X / this.R)) - Math.PI / 4.0);
  2778. var b = Math.asin(Math.cos(this.b0) * Math.sin(rotB)
  2779. + Math.sin(this.b0) * Math.cos(rotB) * Math.cos(rotI));
  2780. var I = Math.atan(Math.sin(rotI)
  2781. / (Math.cos(this.b0) * Math.cos(rotI) - Math.sin(this.b0)
  2782. * Math.tan(rotB)));
  2783. var lambda = this.lambda0 + I / this.alpha;
  2784. var S = 0.0;
  2785. var phy = b;
  2786. var prevPhy = -1000.0;
  2787. var iteration = 0;
  2788. while (Math.abs(phy - prevPhy) > 0.0000001)
  2789. {
  2790. if (++iteration > 20)
  2791. {
  2792. Proj4js.reportError("omercFwdInfinity");
  2793. return;
  2794. }
  2795. //S = Math.log(Math.tan(Math.PI / 4.0 + phy / 2.0));
  2796. S = 1.0
  2797. / this.alpha
  2798. * (Math.log(Math.tan(Math.PI / 4.0 + b / 2.0)) - this.K)
  2799. + this.e
  2800. * Math.log(Math.tan(Math.PI / 4.0
  2801. + Math.asin(this.e * Math.sin(phy))
  2802. / 2.0));
  2803. prevPhy = phy;
  2804. phy = 2.0 * Math.atan(Math.exp(S)) - Math.PI / 2.0;
  2805. }
  2806. p.x = lambda;
  2807. p.y = phy;
  2808. return p;
  2809. }
  2810. };
  2811. /* ======================================================================
  2812. projCode/stere.js
  2813. ====================================================================== */
  2814. // Initialize the Stereographic projection
  2815. Proj4js.Proj.stere = {
  2816. ssfn_: function(phit, sinphi, eccen) {
  2817. sinphi *= eccen;
  2818. return (Math.tan (.5 * (Proj4js.common.HALF_PI + phit)) * Math.pow((1. - sinphi) / (1. + sinphi), .5 * eccen));
  2819. },
  2820. TOL: 1.e-8,
  2821. NITER: 8,
  2822. CONV: 1.e-10,
  2823. S_POLE: 0,
  2824. N_POLE: 1,
  2825. OBLIQ: 2,
  2826. EQUIT: 3,
  2827. init: function() {
  2828. this.phits = this.lat_ts ? this.lat_ts : Proj4js.common.HALF_PI;
  2829. var t = Math.abs(this.lat0);
  2830. if ((Math.abs(t) - Proj4js.common.HALF_PI) < Proj4js.common.EPSLN) {
  2831. this.mode = this.lat0 < 0. ? this.S_POLE : this.N_POLE;
  2832. } else {
  2833. this.mode = t > Proj4js.common.EPSLN ? this.OBLIQ : this.EQUIT;
  2834. }
  2835. this.phits = Math.abs(this.phits);
  2836. if (this.es) {
  2837. var X;
  2838. switch (this.mode) {
  2839. case this.N_POLE:
  2840. case this.S_POLE:
  2841. if (Math.abs(this.phits - Proj4js.common.HALF_PI) < Proj4js.common.EPSLN) {
  2842. this.akm1 = 2. * this.k0 / Math.sqrt(Math.pow(1+this.e,1+this.e)*Math.pow(1-this.e,1-this.e));
  2843. } else {
  2844. t = Math.sin(this.phits);
  2845. this.akm1 = Math.cos(this.phits) / Proj4js.common.tsfnz(this.e, this.phits, t);
  2846. t *= this.e;
  2847. this.akm1 /= Math.sqrt(1. - t * t);
  2848. }
  2849. break;
  2850. case this.EQUIT:
  2851. this.akm1 = 2. * this.k0;
  2852. break;
  2853. case this.OBLIQ:
  2854. t = Math.sin(this.lat0);
  2855. X = 2. * Math.atan(this.ssfn_(this.lat0, t, this.e)) - Proj4js.common.HALF_PI;
  2856. t *= this.e;
  2857. this.akm1 = 2. * this.k0 * Math.cos(this.lat0) / Math.sqrt(1. - t * t);
  2858. this.sinX1 = Math.sin(X);
  2859. this.cosX1 = Math.cos(X);
  2860. break;
  2861. }
  2862. } else {
  2863. switch (this.mode) {
  2864. case this.OBLIQ:
  2865. this.sinph0 = Math.sin(this.lat0);
  2866. this.cosph0 = Math.cos(this.lat0);
  2867. case this.EQUIT:
  2868. this.akm1 = 2. * this.k0;
  2869. break;
  2870. case this.S_POLE:
  2871. case this.N_POLE:
  2872. this.akm1 = Math.abs(this.phits - Proj4js.common.HALF_PI) >= Proj4js.common.EPSLN ?
  2873. Math.cos(this.phits) / Math.tan(Proj4js.common.FORTPI - .5 * this.phits) :
  2874. 2. * this.k0 ;
  2875. break;
  2876. }
  2877. }
  2878. },
  2879. // Stereographic forward equations--mapping lat,long to x,y
  2880. forward: function(p) {
  2881. var lon = p.x;
  2882. lon = Proj4js.common.adjust_lon(lon - this.long0);
  2883. var lat = p.y;
  2884. var x, y;
  2885. if (this.sphere) {
  2886. var sinphi, cosphi, coslam, sinlam;
  2887. sinphi = Math.sin(lat);
  2888. cosphi = Math.cos(lat);
  2889. coslam = Math.cos(lon);
  2890. sinlam = Math.sin(lon);
  2891. switch (this.mode) {
  2892. case this.EQUIT:
  2893. y = 1. + cosphi * coslam;
  2894. if (y <= Proj4js.common.EPSLN) {
  2895. Proj4js.reportError("stere:forward:Equit");
  2896. }
  2897. y = this.akm1 / y;
  2898. x = y * cosphi * sinlam;
  2899. y *= sinphi;
  2900. break;
  2901. case this.OBLIQ:
  2902. y = 1. + this.sinph0 * sinphi + this.cosph0 * cosphi * coslam;
  2903. if (y <= Proj4js.common.EPSLN) {
  2904. Proj4js.reportError("stere:forward:Obliq");
  2905. }
  2906. y = this.akm1 / y;
  2907. x = y * cosphi * sinlam;
  2908. y *= this.cosph0 * sinphi - this.sinph0 * cosphi * coslam;
  2909. break;
  2910. case this.N_POLE:
  2911. coslam = -coslam;
  2912. lat = -lat;
  2913. //Note no break here so it conitnues through S_POLE
  2914. case this.S_POLE:
  2915. if (Math.abs(lat - Proj4js.common.HALF_PI) < this.TOL) {
  2916. Proj4js.reportError("stere:forward:S_POLE");
  2917. }
  2918. y = this.akm1 * Math.tan(Proj4js.common.FORTPI + .5 * lat);
  2919. x = sinlam * y;
  2920. y *= coslam;
  2921. break;
  2922. }
  2923. } else {
  2924. coslam = Math.cos(lon);
  2925. sinlam = Math.sin(lon);
  2926. sinphi = Math.sin(lat);
  2927. var sinX, cosX;
  2928. if (this.mode == this.OBLIQ || this.mode == this.EQUIT) {
  2929. var Xt = 2. * Math.atan(this.ssfn_(lat, sinphi, this.e));
  2930. sinX = Math.sin(Xt - Proj4js.common.HALF_PI);
  2931. cosX = Math.cos(Xt);
  2932. }
  2933. switch (this.mode) {
  2934. case this.OBLIQ:
  2935. var A = this.akm1 / (this.cosX1 * (1. + this.sinX1 * sinX + this.cosX1 * cosX * coslam));
  2936. y = A * (this.cosX1 * sinX - this.sinX1 * cosX * coslam);
  2937. x = A * cosX;
  2938. break;
  2939. case this.EQUIT:
  2940. var A = 2. * this.akm1 / (1. + cosX * coslam);
  2941. y = A * sinX;
  2942. x = A * cosX;
  2943. break;
  2944. case this.S_POLE:
  2945. lat = -lat;
  2946. coslam = - coslam;
  2947. sinphi = -sinphi;
  2948. case this.N_POLE:
  2949. x = this.akm1 * Proj4js.common.tsfnz(this.e, lat, sinphi);
  2950. y = - x * coslam;
  2951. break;
  2952. }
  2953. x = x * sinlam;
  2954. }
  2955. p.x = x*this.a + this.x0;
  2956. p.y = y*this.a + this.y0;
  2957. return p;
  2958. },
  2959. //* Stereographic inverse equations--mapping x,y to lat/long
  2960. inverse: function(p) {
  2961. var x = (p.x - this.x0)/this.a; /* descale and de-offset */
  2962. var y = (p.y - this.y0)/this.a;
  2963. var lon, lat;
  2964. var cosphi, sinphi, tp=0.0, phi_l=0.0, rho, halfe=0.0, pi2=0.0;
  2965. var i;
  2966. if (this.sphere) {
  2967. var c, rh, sinc, cosc;
  2968. rh = Math.sqrt(x*x + y*y);
  2969. c = 2. * Math.atan(rh / this.akm1);
  2970. sinc = Math.sin(c);
  2971. cosc = Math.cos(c);
  2972. lon = 0.;
  2973. switch (this.mode) {
  2974. case this.EQUIT:
  2975. if (Math.abs(rh) <= Proj4js.common.EPSLN) {
  2976. lat = 0.;
  2977. } else {
  2978. lat = Math.asin(y * sinc / rh);
  2979. }
  2980. if (cosc != 0. || x != 0.) lon = Math.atan2(x * sinc, cosc * rh);
  2981. break;
  2982. case this.OBLIQ:
  2983. if (Math.abs(rh) <= Proj4js.common.EPSLN) {
  2984. lat = this.phi0;
  2985. } else {
  2986. lat = Math.asin(cosc * this.sinph0 + y * sinc * this.cosph0 / rh);
  2987. }
  2988. c = cosc - this.sinph0 * Math.sin(lat);
  2989. if (c != 0. || x != 0.) {
  2990. lon = Math.atan2(x * sinc * this.cosph0, c * rh);
  2991. }
  2992. break;
  2993. case this.N_POLE:
  2994. y = -y;
  2995. case this.S_POLE:
  2996. if (Math.abs(rh) <= Proj4js.common.EPSLN) {
  2997. lat = this.phi0;
  2998. } else {
  2999. lat = Math.asin(this.mode == this.S_POLE ? -cosc : cosc);
  3000. }
  3001. lon = (x == 0. && y == 0.) ? 0. : Math.atan2(x, y);
  3002. break;
  3003. }
  3004. p.x = Proj4js.common.adjust_lon(lon + this.long0);
  3005. p.y = lat;
  3006. } else {
  3007. rho = Math.sqrt(x*x + y*y);
  3008. switch (this.mode) {
  3009. case this.OBLIQ:
  3010. case this.EQUIT:
  3011. tp = 2. * Math.atan2(rho * this.cosX1 , this.akm1);
  3012. cosphi = Math.cos(tp);
  3013. sinphi = Math.sin(tp);
  3014. if( rho == 0.0 ) {
  3015. phi_l = Math.asin(cosphi * this.sinX1);
  3016. } else {
  3017. phi_l = Math.asin(cosphi * this.sinX1 + (y * sinphi * this.cosX1 / rho));
  3018. }
  3019. tp = Math.tan(.5 * (Proj4js.common.HALF_PI + phi_l));
  3020. x *= sinphi;
  3021. y = rho * this.cosX1 * cosphi - y * this.sinX1* sinphi;
  3022. pi2 = Proj4js.common.HALF_PI;
  3023. halfe = .5 * this.e;
  3024. break;
  3025. case this.N_POLE:
  3026. y = -y;
  3027. case this.S_POLE:
  3028. tp = - rho / this.akm1;
  3029. phi_l = Proj4js.common.HALF_PI - 2. * Math.atan(tp);
  3030. pi2 = -Proj4js.common.HALF_PI;
  3031. halfe = -.5 * this.e;
  3032. break;
  3033. }
  3034. for (i = this.NITER; i--; phi_l = lat) { //check this
  3035. sinphi = this.e * Math.sin(phi_l);
  3036. lat = 2. * Math.atan(tp * Math.pow((1.+sinphi)/(1.-sinphi), halfe)) - pi2;
  3037. if (Math.abs(phi_l - lat) < this.CONV) {
  3038. if (this.mode == this.S_POLE) lat = -lat;
  3039. lon = (x == 0. && y == 0.) ? 0. : Math.atan2(x, y);
  3040. p.x = Proj4js.common.adjust_lon(lon + this.long0);
  3041. p.y = lat;
  3042. return p;
  3043. }
  3044. }
  3045. }
  3046. }
  3047. };
  3048. /* ======================================================================
  3049. projCode/nzmg.js
  3050. ====================================================================== */
  3051. /*******************************************************************************
  3052. NAME NEW ZEALAND MAP GRID
  3053. PURPOSE: Transforms input longitude and latitude to Easting and
  3054. Northing for the New Zealand Map Grid projection. The
  3055. longitude and latitude must be in radians. The Easting
  3056. and Northing values will be returned in meters.
  3057. ALGORITHM REFERENCES
  3058. 1. Department of Land and Survey Technical Circular 1973/32
  3059. http://www.linz.govt.nz/docs/miscellaneous/nz-map-definition.pdf
  3060. 2. OSG Technical Report 4.1
  3061. http://www.linz.govt.nz/docs/miscellaneous/nzmg.pdf
  3062. IMPLEMENTATION NOTES
  3063. The two references use different symbols for the calculated values. This
  3064. implementation uses the variable names similar to the symbols in reference [1].
  3065. The alogrithm uses different units for delta latitude and delta longitude.
  3066. The delta latitude is assumed to be in units of seconds of arc x 10^-5.
  3067. The delta longitude is the usual radians. Look out for these conversions.
  3068. The algorithm is described using complex arithmetic. There were three
  3069. options:
  3070. * find and use a Javascript library for complex arithmetic
  3071. * write my own complex library
  3072. * expand the complex arithmetic by hand to simple arithmetic
  3073. This implementation has expanded the complex multiplication operations
  3074. into parallel simple arithmetic operations for the real and imaginary parts.
  3075. The imaginary part is way over to the right of the display; this probably
  3076. violates every coding standard in the world, but, to me, it makes it much
  3077. more obvious what is going on.
  3078. The following complex operations are used:
  3079. - addition
  3080. - multiplication
  3081. - division
  3082. - complex number raised to integer power
  3083. - summation
  3084. A summary of complex arithmetic operations:
  3085. (from http://en.wikipedia.org/wiki/Complex_arithmetic)
  3086. addition: (a + bi) + (c + di) = (a + c) + (b + d)i
  3087. subtraction: (a + bi) - (c + di) = (a - c) + (b - d)i
  3088. multiplication: (a + bi) x (c + di) = (ac - bd) + (bc + ad)i
  3089. division: (a + bi) / (c + di) = [(ac + bd)/(cc + dd)] + [(bc - ad)/(cc + dd)]i
  3090. The algorithm needs to calculate summations of simple and complex numbers. This is
  3091. implemented using a for-loop, pre-loading the summed value to zero.
  3092. The algorithm needs to calculate theta^2, theta^3, etc while doing a summation.
  3093. There are three possible implementations:
  3094. - use Math.pow in the summation loop - except for complex numbers
  3095. - precalculate the values before running the loop
  3096. - calculate theta^n = theta^(n-1) * theta during the loop
  3097. This implementation uses the third option for both real and complex arithmetic.
  3098. For example
  3099. psi_n = 1;
  3100. sum = 0;
  3101. for (n = 1; n <=6; n++) {
  3102. psi_n1 = psi_n * psi; // calculate psi^(n+1)
  3103. psi_n = psi_n1;
  3104. sum = sum + A[n] * psi_n;
  3105. }
  3106. TEST VECTORS
  3107. NZMG E, N: 2487100.638 6751049.719 metres
  3108. NZGD49 long, lat: 172.739194 -34.444066 degrees
  3109. NZMG E, N: 2486533.395 6077263.661 metres
  3110. NZGD49 long, lat: 172.723106 -40.512409 degrees
  3111. NZMG E, N: 2216746.425 5388508.765 metres
  3112. NZGD49 long, lat: 169.172062 -46.651295 degrees
  3113. Note that these test vectors convert from NZMG metres to lat/long referenced
  3114. to NZGD49, not the more usual WGS84. The difference is about 70m N/S and about
  3115. 10m E/W.
  3116. These test vectors are provided in reference [1]. Many more test
  3117. vectors are available in
  3118. http://www.linz.govt.nz/docs/topography/topographicdata/placenamesdatabase/nznamesmar08.zip
  3119. which is a catalog of names on the 260-series maps.
  3120. EPSG CODES
  3121. NZMG EPSG:27200
  3122. NZGD49 EPSG:4272
  3123. http://spatialreference.org/ defines these as
  3124. Proj4js.defs["EPSG:4272"] = "+proj=longlat +ellps=intl +datum=nzgd49 +no_defs ";
  3125. Proj4js.defs["EPSG:27200"] = "+proj=nzmg +lat_0=-41 +lon_0=173 +x_0=2510000 +y_0=6023150 +ellps=intl +datum=nzgd49 +units=m +no_defs ";
  3126. LICENSE
  3127. Copyright: Stephen Irons 2008
  3128. Released under terms of the LGPL as per: http://www.gnu.org/copyleft/lesser.html
  3129. *******************************************************************************/
  3130. /**
  3131. Initialize New Zealand Map Grip projection
  3132. */
  3133. Proj4js.Proj.nzmg = {
  3134. /**
  3135. * iterations: Number of iterations to refine inverse transform.
  3136. * 0 -> km accuracy
  3137. * 1 -> m accuracy -- suitable for most mapping applications
  3138. * 2 -> mm accuracy
  3139. */
  3140. iterations: 1,
  3141. init : function() {
  3142. this.A = new Array();
  3143. this.A[1] = +0.6399175073;
  3144. this.A[2] = -0.1358797613;
  3145. this.A[3] = +0.063294409;
  3146. this.A[4] = -0.02526853;
  3147. this.A[5] = +0.0117879;
  3148. this.A[6] = -0.0055161;
  3149. this.A[7] = +0.0026906;
  3150. this.A[8] = -0.001333;
  3151. this.A[9] = +0.00067;
  3152. this.A[10] = -0.00034;
  3153. this.B_re = new Array(); this.B_im = new Array();
  3154. this.B_re[1] = +0.7557853228; this.B_im[1] = 0.0;
  3155. this.B_re[2] = +0.249204646; this.B_im[2] = +0.003371507;
  3156. this.B_re[3] = -0.001541739; this.B_im[3] = +0.041058560;
  3157. this.B_re[4] = -0.10162907; this.B_im[4] = +0.01727609;
  3158. this.B_re[5] = -0.26623489; this.B_im[5] = -0.36249218;
  3159. this.B_re[6] = -0.6870983; this.B_im[6] = -1.1651967;
  3160. this.C_re = new Array(); this.C_im = new Array();
  3161. this.C_re[1] = +1.3231270439; this.C_im[1] = 0.0;
  3162. this.C_re[2] = -0.577245789; this.C_im[2] = -0.007809598;
  3163. this.C_re[3] = +0.508307513; this.C_im[3] = -0.112208952;
  3164. this.C_re[4] = -0.15094762; this.C_im[4] = +0.18200602;
  3165. this.C_re[5] = +1.01418179; this.C_im[5] = +1.64497696;
  3166. this.C_re[6] = +1.9660549; this.C_im[6] = +2.5127645;
  3167. this.D = new Array();
  3168. this.D[1] = +1.5627014243;
  3169. this.D[2] = +0.5185406398;
  3170. this.D[3] = -0.03333098;
  3171. this.D[4] = -0.1052906;
  3172. this.D[5] = -0.0368594;
  3173. this.D[6] = +0.007317;
  3174. this.D[7] = +0.01220;
  3175. this.D[8] = +0.00394;
  3176. this.D[9] = -0.0013;
  3177. },
  3178. /**
  3179. New Zealand Map Grid Forward - long/lat to x/y
  3180. long/lat in radians
  3181. */
  3182. forward : function(p) {
  3183. var lon = p.x;
  3184. var lat = p.y;
  3185. var delta_lat = lat - this.lat0;
  3186. var delta_lon = lon - this.long0;
  3187. // 1. Calculate d_phi and d_psi ... // and d_lambda
  3188. // For this algorithm, delta_latitude is in seconds of arc x 10-5, so we need to scale to those units. Longitude is radians.
  3189. var d_phi = delta_lat / Proj4js.common.SEC_TO_RAD * 1E-5; var d_lambda = delta_lon;
  3190. var d_phi_n = 1; // d_phi^0
  3191. var d_psi = 0;
  3192. for (var n = 1; n <= 10; n++) {
  3193. d_phi_n = d_phi_n * d_phi;
  3194. d_psi = d_psi + this.A[n] * d_phi_n;
  3195. }
  3196. // 2. Calculate theta
  3197. var th_re = d_psi; var th_im = d_lambda;
  3198. // 3. Calculate z
  3199. var th_n_re = 1; var th_n_im = 0; // theta^0
  3200. var th_n_re1; var th_n_im1;
  3201. var z_re = 0; var z_im = 0;
  3202. for (var n = 1; n <= 6; n++) {
  3203. th_n_re1 = th_n_re*th_re - th_n_im*th_im; th_n_im1 = th_n_im*th_re + th_n_re*th_im;
  3204. th_n_re = th_n_re1; th_n_im = th_n_im1;
  3205. z_re = z_re + this.B_re[n]*th_n_re - this.B_im[n]*th_n_im; z_im = z_im + this.B_im[n]*th_n_re + this.B_re[n]*th_n_im;
  3206. }
  3207. // 4. Calculate easting and northing
  3208. p.x = (z_im * this.a) + this.x0;
  3209. p.y = (z_re * this.a) + this.y0;
  3210. return p;
  3211. },
  3212. /**
  3213. New Zealand Map Grid Inverse - x/y to long/lat
  3214. */
  3215. inverse : function(p) {
  3216. var x = p.x;
  3217. var y = p.y;
  3218. var delta_x = x - this.x0;
  3219. var delta_y = y - this.y0;
  3220. // 1. Calculate z
  3221. var z_re = delta_y / this.a; var z_im = delta_x / this.a;
  3222. // 2a. Calculate theta - first approximation gives km accuracy
  3223. var z_n_re = 1; var z_n_im = 0; // z^0
  3224. var z_n_re1; var z_n_im1;
  3225. var th_re = 0; var th_im = 0;
  3226. for (var n = 1; n <= 6; n++) {
  3227. z_n_re1 = z_n_re*z_re - z_n_im*z_im; z_n_im1 = z_n_im*z_re + z_n_re*z_im;
  3228. z_n_re = z_n_re1; z_n_im = z_n_im1;
  3229. th_re = th_re + this.C_re[n]*z_n_re - this.C_im[n]*z_n_im; th_im = th_im + this.C_im[n]*z_n_re + this.C_re[n]*z_n_im;
  3230. }
  3231. // 2b. Iterate to refine the accuracy of the calculation
  3232. // 0 iterations gives km accuracy
  3233. // 1 iteration gives m accuracy -- good enough for most mapping applications
  3234. // 2 iterations bives mm accuracy
  3235. for (var i = 0; i < this.iterations; i++) {
  3236. var th_n_re = th_re; var th_n_im = th_im;
  3237. var th_n_re1; var th_n_im1;
  3238. var num_re = z_re; var num_im = z_im;
  3239. for (var n = 2; n <= 6; n++) {
  3240. th_n_re1 = th_n_re*th_re - th_n_im*th_im; th_n_im1 = th_n_im*th_re + th_n_re*th_im;
  3241. th_n_re = th_n_re1; th_n_im = th_n_im1;
  3242. num_re = num_re + (n-1)*(this.B_re[n]*th_n_re - this.B_im[n]*th_n_im); num_im = num_im + (n-1)*(this.B_im[n]*th_n_re + this.B_re[n]*th_n_im);
  3243. }
  3244. th_n_re = 1; th_n_im = 0;
  3245. var den_re = this.B_re[1]; var den_im = this.B_im[1];
  3246. for (var n = 2; n <= 6; n++) {
  3247. th_n_re1 = th_n_re*th_re - th_n_im*th_im; th_n_im1 = th_n_im*th_re + th_n_re*th_im;
  3248. th_n_re = th_n_re1; th_n_im = th_n_im1;
  3249. den_re = den_re + n * (this.B_re[n]*th_n_re - this.B_im[n]*th_n_im); den_im = den_im + n * (this.B_im[n]*th_n_re + this.B_re[n]*th_n_im);
  3250. }
  3251. // Complex division
  3252. var den2 = den_re*den_re + den_im*den_im;
  3253. th_re = (num_re*den_re + num_im*den_im) / den2; th_im = (num_im*den_re - num_re*den_im) / den2;
  3254. }
  3255. // 3. Calculate d_phi ... // and d_lambda
  3256. var d_psi = th_re; var d_lambda = th_im;
  3257. var d_psi_n = 1; // d_psi^0
  3258. var d_phi = 0;
  3259. for (var n = 1; n <= 9; n++) {
  3260. d_psi_n = d_psi_n * d_psi;
  3261. d_phi = d_phi + this.D[n] * d_psi_n;
  3262. }
  3263. // 4. Calculate latitude and longitude
  3264. // d_phi is calcuated in second of arc * 10^-5, so we need to scale back to radians. d_lambda is in radians.
  3265. var lat = this.lat0 + (d_phi * Proj4js.common.SEC_TO_RAD * 1E5);
  3266. var lon = this.long0 + d_lambda;
  3267. p.x = lon;
  3268. p.y = lat;
  3269. return p;
  3270. }
  3271. };
  3272. /* ======================================================================
  3273. projCode/mill.js
  3274. ====================================================================== */
  3275. /*******************************************************************************
  3276. NAME MILLER CYLINDRICAL
  3277. PURPOSE: Transforms input longitude and latitude to Easting and
  3278. Northing for the Miller Cylindrical projection. The
  3279. longitude and latitude must be in radians. The Easting
  3280. and Northing values will be returned in meters.
  3281. PROGRAMMER DATE
  3282. ---------- ----
  3283. T. Mittan March, 1993
  3284. This function was adapted from the Lambert Azimuthal Equal Area projection
  3285. code (FORTRAN) in the General Cartographic Transformation Package software
  3286. which is available from the U.S. Geological Survey National Mapping Division.
  3287. ALGORITHM REFERENCES
  3288. 1. "New Equal-Area Map Projections for Noncircular Regions", John P. Snyder,
  3289. The American Cartographer, Vol 15, No. 4, October 1988, pp. 341-355.
  3290. 2. Snyder, John P., "Map Projections--A Working Manual", U.S. Geological
  3291. Survey Professional Paper 1395 (Supersedes USGS Bulletin 1532), United
  3292. State Government Printing Office, Washington D.C., 1987.
  3293. 3. "Software Documentation for GCTP General Cartographic Transformation
  3294. Package", U.S. Geological Survey National Mapping Division, May 1982.
  3295. *******************************************************************************/
  3296. Proj4js.Proj.mill = {
  3297. /* Initialize the Miller Cylindrical projection
  3298. -------------------------------------------*/
  3299. init: function() {
  3300. //no-op
  3301. },
  3302. /* Miller Cylindrical forward equations--mapping lat,long to x,y
  3303. ------------------------------------------------------------*/
  3304. forward: function(p) {
  3305. var lon=p.x;
  3306. var lat=p.y;
  3307. /* Forward equations
  3308. -----------------*/
  3309. var dlon = Proj4js.common.adjust_lon(lon -this.long0);
  3310. var x = this.x0 + this.a * dlon;
  3311. var y = this.y0 + this.a * Math.log(Math.tan((Proj4js.common.PI / 4.0) + (lat / 2.5))) * 1.25;
  3312. p.x=x;
  3313. p.y=y;
  3314. return p;
  3315. },//millFwd()
  3316. /* Miller Cylindrical inverse equations--mapping x,y to lat/long
  3317. ------------------------------------------------------------*/
  3318. inverse: function(p) {
  3319. p.x -= this.x0;
  3320. p.y -= this.y0;
  3321. var lon = Proj4js.common.adjust_lon(this.long0 + p.x /this.a);
  3322. var lat = 2.5 * (Math.atan(Math.exp(0.8*p.y/this.a)) - Proj4js.common.PI / 4.0);
  3323. p.x=lon;
  3324. p.y=lat;
  3325. return p;
  3326. }//millInv()
  3327. };
  3328. /* ======================================================================
  3329. projCode/gnom.js
  3330. ====================================================================== */
  3331. /*****************************************************************************
  3332. NAME GNOMONIC
  3333. PURPOSE: Transforms input longitude and latitude to Easting and
  3334. Northing for the Gnomonic Projection.
  3335. Implementation based on the existing sterea and ortho
  3336. implementations.
  3337. PROGRAMMER DATE
  3338. ---------- ----
  3339. Richard Marsden November 2009
  3340. ALGORITHM REFERENCES
  3341. 1. Snyder, John P., "Flattening the Earth - Two Thousand Years of Map
  3342. Projections", University of Chicago Press 1993
  3343. 2. Wolfram Mathworld "Gnomonic Projection"
  3344. http://mathworld.wolfram.com/GnomonicProjection.html
  3345. Accessed: 12th November 2009
  3346. ******************************************************************************/
  3347. Proj4js.Proj.gnom = {
  3348. /* Initialize the Gnomonic projection
  3349. -------------------------------------*/
  3350. init: function(def) {
  3351. /* Place parameters in static storage for common use
  3352. -------------------------------------------------*/
  3353. this.sin_p14=Math.sin(this.lat0);
  3354. this.cos_p14=Math.cos(this.lat0);
  3355. // Approximation for projecting points to the horizon (infinity)
  3356. this.infinity_dist = 1000 * this.a;
  3357. this.rc = 1;
  3358. },
  3359. /* Gnomonic forward equations--mapping lat,long to x,y
  3360. ---------------------------------------------------*/
  3361. forward: function(p) {
  3362. var sinphi, cosphi; /* sin and cos value */
  3363. var dlon; /* delta longitude value */
  3364. var coslon; /* cos of longitude */
  3365. var ksp; /* scale factor */
  3366. var g;
  3367. var x, y;
  3368. var lon=p.x;
  3369. var lat=p.y;
  3370. /* Forward equations
  3371. -----------------*/
  3372. dlon = Proj4js.common.adjust_lon(lon - this.long0);
  3373. sinphi=Math.sin(lat);
  3374. cosphi=Math.cos(lat);
  3375. coslon = Math.cos(dlon);
  3376. g = this.sin_p14 * sinphi + this.cos_p14 * cosphi * coslon;
  3377. ksp = 1.0;
  3378. if ((g > 0) || (Math.abs(g) <= Proj4js.common.EPSLN)) {
  3379. x = this.x0 + this.a * ksp * cosphi * Math.sin(dlon) / g;
  3380. y = this.y0 + this.a * ksp * (this.cos_p14 * sinphi - this.sin_p14 * cosphi * coslon) / g;
  3381. } else {
  3382. Proj4js.reportError("orthoFwdPointError");
  3383. // Point is in the opposing hemisphere and is unprojectable
  3384. // We still need to return a reasonable point, so we project
  3385. // to infinity, on a bearing
  3386. // equivalent to the northern hemisphere equivalent
  3387. // This is a reasonable approximation for short shapes and lines that
  3388. // straddle the horizon.
  3389. x = this.x0 + this.infinity_dist * cosphi * Math.sin(dlon);
  3390. y = this.y0 + this.infinity_dist * (this.cos_p14 * sinphi - this.sin_p14 * cosphi * coslon);
  3391. }
  3392. p.x=x;
  3393. p.y=y;
  3394. return p;
  3395. },
  3396. inverse: function(p) {
  3397. var rh; /* Rho */
  3398. var z; /* angle */
  3399. var sinc, cosc;
  3400. var c;
  3401. var lon , lat;
  3402. /* Inverse equations
  3403. -----------------*/
  3404. p.x = (p.x - this.x0) / this.a;
  3405. p.y = (p.y - this.y0) / this.a;
  3406. p.x /= this.k0;
  3407. p.y /= this.k0;
  3408. if ( (rh = Math.sqrt(p.x * p.x + p.y * p.y)) ) {
  3409. c = Math.atan2(rh, this.rc);
  3410. sinc = Math.sin(c);
  3411. cosc = Math.cos(c);
  3412. lat = Proj4js.common.asinz(cosc*this.sin_p14 + (p.y*sinc*this.cos_p14) / rh);
  3413. lon = Math.atan2(p.x*sinc, rh*this.cos_p14*cosc - p.y*this.sin_p14*sinc);
  3414. lon = Proj4js.common.adjust_lon(this.long0+lon);
  3415. } else {
  3416. lat = this.phic0;
  3417. lon = 0.0;
  3418. }
  3419. p.x=lon;
  3420. p.y=lat;
  3421. return p;
  3422. }
  3423. };
  3424. /* ======================================================================
  3425. projCode/sinu.js
  3426. ====================================================================== */
  3427. /*******************************************************************************
  3428. NAME SINUSOIDAL
  3429. PURPOSE: Transforms input longitude and latitude to Easting and
  3430. Northing for the Sinusoidal projection. The
  3431. longitude and latitude must be in radians. The Easting
  3432. and Northing values will be returned in meters.
  3433. PROGRAMMER DATE
  3434. ---------- ----
  3435. D. Steinwand, EROS May, 1991
  3436. This function was adapted from the Sinusoidal projection code (FORTRAN) in the
  3437. General Cartographic Transformation Package software which is available from
  3438. the U.S. Geological Survey National Mapping Division.
  3439. ALGORITHM REFERENCES
  3440. 1. Snyder, John P., "Map Projections--A Working Manual", U.S. Geological
  3441. Survey Professional Paper 1395 (Supersedes USGS Bulletin 1532), United
  3442. State Government Printing Office, Washington D.C., 1987.
  3443. 2. "Software Documentation for GCTP General Cartographic Transformation
  3444. Package", U.S. Geological Survey National Mapping Division, May 1982.
  3445. *******************************************************************************/
  3446. Proj4js.Proj.sinu = {
  3447. /* Initialize the Sinusoidal projection
  3448. ------------------------------------*/
  3449. init: function() {
  3450. /* Place parameters in static storage for common use
  3451. -------------------------------------------------*/
  3452. if (!this.sphere) {
  3453. this.en = Proj4js.common.pj_enfn(this.es);
  3454. } else {
  3455. this.n = 1.;
  3456. this.m = 0.;
  3457. this.es = 0;
  3458. this.C_y = Math.sqrt((this.m + 1.) / this.n);
  3459. this.C_x = this.C_y/(this.m + 1.);
  3460. }
  3461. },
  3462. /* Sinusoidal forward equations--mapping lat,long to x,y
  3463. -----------------------------------------------------*/
  3464. forward: function(p) {
  3465. var x,y,delta_lon;
  3466. var lon=p.x;
  3467. var lat=p.y;
  3468. /* Forward equations
  3469. -----------------*/
  3470. lon = Proj4js.common.adjust_lon(lon - this.long0);
  3471. if (this.sphere) {
  3472. if (!this.m) {
  3473. lat = this.n != 1. ? Math.asin(this.n * Math.sin(lat)): lat;
  3474. } else {
  3475. var k = this.n * Math.sin(lat);
  3476. for (var i = Proj4js.common.MAX_ITER; i ; --i) {
  3477. var V = (this.m * lat + Math.sin(lat) - k) / (this.m + Math.cos(lat));
  3478. lat -= V;
  3479. if (Math.abs(V) < Proj4js.common.EPSLN) break;
  3480. }
  3481. }
  3482. x = this.a * this.C_x * lon * (this.m + Math.cos(lat));
  3483. y = this.a * this.C_y * lat;
  3484. } else {
  3485. var s = Math.sin(lat);
  3486. var c = Math.cos(lat);
  3487. y = this.a * Proj4js.common.pj_mlfn(lat, s, c, this.en);
  3488. x = this.a * lon * c / Math.sqrt(1. - this.es * s * s);
  3489. }
  3490. p.x=x;
  3491. p.y=y;
  3492. return p;
  3493. },
  3494. inverse: function(p) {
  3495. var lat,temp,lon;
  3496. /* Inverse equations
  3497. -----------------*/
  3498. p.x -= this.x0;
  3499. p.y -= this.y0;
  3500. lat = p.y / this.a;
  3501. if (this.sphere) {
  3502. p.y /= this.C_y;
  3503. lat = this.m ? Math.asin((this.m * p.y + Math.sin(p.y)) / this.n) :
  3504. ( this.n != 1. ? Math.asin(Math.sin(p.y) / this.n) : p.y );
  3505. lon = p.x / (this.C_x * (this.m + Math.cos(p.y)));
  3506. } else {
  3507. lat = Proj4js.common.pj_inv_mlfn(p.y/this.a, this.es, this.en)
  3508. var s = Math.abs(lat);
  3509. if (s < Proj4js.common.HALF_PI) {
  3510. s = Math.sin(lat);
  3511. temp = this.long0 + p.x * Math.sqrt(1. - this.es * s * s) /(this.a * Math.cos(lat));
  3512. //temp = this.long0 + p.x / (this.a * Math.cos(lat));
  3513. lon = Proj4js.common.adjust_lon(temp);
  3514. } else if ((s - Proj4js.common.EPSLN) < Proj4js.common.HALF_PI) {
  3515. lon = this.long0;
  3516. }
  3517. }
  3518. p.x=lon;
  3519. p.y=lat;
  3520. return p;
  3521. }
  3522. };
  3523. /* ======================================================================
  3524. projCode/vandg.js
  3525. ====================================================================== */
  3526. /*******************************************************************************
  3527. NAME VAN DER GRINTEN
  3528. PURPOSE: Transforms input Easting and Northing to longitude and
  3529. latitude for the Van der Grinten projection. The
  3530. Easting and Northing must be in meters. The longitude
  3531. and latitude values will be returned in radians.
  3532. PROGRAMMER DATE
  3533. ---------- ----
  3534. T. Mittan March, 1993
  3535. This function was adapted from the Van Der Grinten projection code
  3536. (FORTRAN) in the General Cartographic Transformation Package software
  3537. which is available from the U.S. Geological Survey National Mapping Division.
  3538. ALGORITHM REFERENCES
  3539. 1. "New Equal-Area Map Projections for Noncircular Regions", John P. Snyder,
  3540. The American Cartographer, Vol 15, No. 4, October 1988, pp. 341-355.
  3541. 2. Snyder, John P., "Map Projections--A Working Manual", U.S. Geological
  3542. Survey Professional Paper 1395 (Supersedes USGS Bulletin 1532), United
  3543. State Government Printing Office, Washington D.C., 1987.
  3544. 3. "Software Documentation for GCTP General Cartographic Transformation
  3545. Package", U.S. Geological Survey National Mapping Division, May 1982.
  3546. *******************************************************************************/
  3547. Proj4js.Proj.vandg = {
  3548. /* Initialize the Van Der Grinten projection
  3549. ----------------------------------------*/
  3550. init: function() {
  3551. this.R = 6370997.0; //Radius of earth
  3552. },
  3553. forward: function(p) {
  3554. var lon=p.x;
  3555. var lat=p.y;
  3556. /* Forward equations
  3557. -----------------*/
  3558. var dlon = Proj4js.common.adjust_lon(lon - this.long0);
  3559. var x,y;
  3560. if (Math.abs(lat) <= Proj4js.common.EPSLN) {
  3561. x = this.x0 + this.R * dlon;
  3562. y = this.y0;
  3563. }
  3564. var theta = Proj4js.common.asinz(2.0 * Math.abs(lat / Proj4js.common.PI));
  3565. if ((Math.abs(dlon) <= Proj4js.common.EPSLN) || (Math.abs(Math.abs(lat) - Proj4js.common.HALF_PI) <= Proj4js.common.EPSLN)) {
  3566. x = this.x0;
  3567. if (lat >= 0) {
  3568. y = this.y0 + Proj4js.common.PI * this.R * Math.tan(.5 * theta);
  3569. } else {
  3570. y = this.y0 + Proj4js.common.PI * this.R * - Math.tan(.5 * theta);
  3571. }
  3572. // return(OK);
  3573. }
  3574. var al = .5 * Math.abs((Proj4js.common.PI / dlon) - (dlon / Proj4js.common.PI));
  3575. var asq = al * al;
  3576. var sinth = Math.sin(theta);
  3577. var costh = Math.cos(theta);
  3578. var g = costh / (sinth + costh - 1.0);
  3579. var gsq = g * g;
  3580. var m = g * (2.0 / sinth - 1.0);
  3581. var msq = m * m;
  3582. var con = Proj4js.common.PI * this.R * (al * (g - msq) + Math.sqrt(asq * (g - msq) * (g - msq) - (msq + asq) * (gsq - msq))) / (msq + asq);
  3583. if (dlon < 0) {
  3584. con = -con;
  3585. }
  3586. x = this.x0 + con;
  3587. con = Math.abs(con / (Proj4js.common.PI * this.R));
  3588. if (lat >= 0) {
  3589. y = this.y0 + Proj4js.common.PI * this.R * Math.sqrt(1.0 - con * con - 2.0 * al * con);
  3590. } else {
  3591. y = this.y0 - Proj4js.common.PI * this.R * Math.sqrt(1.0 - con * con - 2.0 * al * con);
  3592. }
  3593. p.x = x;
  3594. p.y = y;
  3595. return p;
  3596. },
  3597. /* Van Der Grinten inverse equations--mapping x,y to lat/long
  3598. ---------------------------------------------------------*/
  3599. inverse: function(p) {
  3600. var lon, lat;
  3601. var xx,yy,xys,c1,c2,c3;
  3602. var al,asq;
  3603. var a1;
  3604. var m1;
  3605. var con;
  3606. var th1;
  3607. var d;
  3608. /* inverse equations
  3609. -----------------*/
  3610. p.x -= this.x0;
  3611. p.y -= this.y0;
  3612. con = Proj4js.common.PI * this.R;
  3613. xx = p.x / con;
  3614. yy =p.y / con;
  3615. xys = xx * xx + yy * yy;
  3616. c1 = -Math.abs(yy) * (1.0 + xys);
  3617. c2 = c1 - 2.0 * yy * yy + xx * xx;
  3618. c3 = -2.0 * c1 + 1.0 + 2.0 * yy * yy + xys * xys;
  3619. d = yy * yy / c3 + (2.0 * c2 * c2 * c2 / c3 / c3 / c3 - 9.0 * c1 * c2 / c3 /c3) / 27.0;
  3620. a1 = (c1 - c2 * c2 / 3.0 / c3) / c3;
  3621. m1 = 2.0 * Math.sqrt( -a1 / 3.0);
  3622. con = ((3.0 * d) / a1) / m1;
  3623. if (Math.abs(con) > 1.0) {
  3624. if (con >= 0.0) {
  3625. con = 1.0;
  3626. } else {
  3627. con = -1.0;
  3628. }
  3629. }
  3630. th1 = Math.acos(con) / 3.0;
  3631. if (p.y >= 0) {
  3632. lat = (-m1 *Math.cos(th1 + Proj4js.common.PI / 3.0) - c2 / 3.0 / c3) * Proj4js.common.PI;
  3633. } else {
  3634. lat = -(-m1 * Math.cos(th1 + Proj4js.common.PI / 3.0) - c2 / 3.0 / c3) * Proj4js.common.PI;
  3635. }
  3636. if (Math.abs(xx) < Proj4js.common.EPSLN) {
  3637. lon = this.long0;
  3638. }
  3639. lon = Proj4js.common.adjust_lon(this.long0 + Proj4js.common.PI * (xys - 1.0 + Math.sqrt(1.0 + 2.0 * (xx * xx - yy * yy) + xys * xys)) / 2.0 / xx);
  3640. p.x=lon;
  3641. p.y=lat;
  3642. return p;
  3643. }
  3644. };
  3645. /* ======================================================================
  3646. projCode/cea.js
  3647. ====================================================================== */
  3648. /*******************************************************************************
  3649. NAME LAMBERT CYLINDRICAL EQUAL AREA
  3650. PURPOSE: Transforms input longitude and latitude to Easting and
  3651. Northing for the Lambert Cylindrical Equal Area projection.
  3652. This class of projection includes the Behrmann and
  3653. Gall-Peters Projections. The
  3654. longitude and latitude must be in radians. The Easting
  3655. and Northing values will be returned in meters.
  3656. PROGRAMMER DATE
  3657. ---------- ----
  3658. R. Marsden August 2009
  3659. Winwaed Software Tech LLC, http://www.winwaed.com
  3660. This function was adapted from the Miller Cylindrical Projection in the Proj4JS
  3661. library.
  3662. Note: This implementation assumes a Spherical Earth. The (commented) code
  3663. has been included for the ellipsoidal forward transform, but derivation of
  3664. the ellispoidal inverse transform is beyond me. Note that most of the
  3665. Proj4JS implementations do NOT currently support ellipsoidal figures.
  3666. Therefore this is not seen as a problem - especially this lack of support
  3667. is explicitly stated here.
  3668. ALGORITHM REFERENCES
  3669. 1. "Cartographic Projection Procedures for the UNIX Environment -
  3670. A User's Manual" by Gerald I. Evenden, USGS Open File Report 90-284
  3671. and Release 4 Interim Reports (2003)
  3672. 2. Snyder, John P., "Flattening the Earth - Two Thousand Years of Map
  3673. Projections", Univ. Chicago Press, 1993
  3674. *******************************************************************************/
  3675. Proj4js.Proj.cea = {
  3676. /* Initialize the Cylindrical Equal Area projection
  3677. -------------------------------------------*/
  3678. init: function() {
  3679. //no-op
  3680. },
  3681. /* Cylindrical Equal Area forward equations--mapping lat,long to x,y
  3682. ------------------------------------------------------------*/
  3683. forward: function(p) {
  3684. var lon=p.x;
  3685. var lat=p.y;
  3686. /* Forward equations
  3687. -----------------*/
  3688. var dlon = Proj4js.common.adjust_lon(lon -this.long0);
  3689. var x = this.x0 + this.a * dlon * Math.cos(this.lat_ts);
  3690. var y = this.y0 + this.a * Math.sin(lat) / Math.cos(this.lat_ts);
  3691. /* Elliptical Forward Transform
  3692. Not implemented due to a lack of a matchign inverse function
  3693. {
  3694. var Sin_Lat = Math.sin(lat);
  3695. var Rn = this.a * (Math.sqrt(1.0e0 - this.es * Sin_Lat * Sin_Lat ));
  3696. x = this.x0 + this.a * dlon * Math.cos(this.lat_ts);
  3697. y = this.y0 + Rn * Math.sin(lat) / Math.cos(this.lat_ts);
  3698. }
  3699. */
  3700. p.x=x;
  3701. p.y=y;
  3702. return p;
  3703. },//ceaFwd()
  3704. /* Cylindrical Equal Area inverse equations--mapping x,y to lat/long
  3705. ------------------------------------------------------------*/
  3706. inverse: function(p) {
  3707. p.x -= this.x0;
  3708. p.y -= this.y0;
  3709. var lon = Proj4js.common.adjust_lon( this.long0 + (p.x / this.a) / Math.cos(this.lat_ts) );
  3710. var lat = Math.asin( (p.y/this.a) * Math.cos(this.lat_ts) );
  3711. p.x=lon;
  3712. p.y=lat;
  3713. return p;
  3714. }//ceaInv()
  3715. };
  3716. /* ======================================================================
  3717. projCode/eqc.js
  3718. ====================================================================== */
  3719. /* similar to equi.js FIXME proj4 uses eqc */
  3720. Proj4js.Proj.eqc = {
  3721. init : function() {
  3722. if(!this.x0) this.x0=0;
  3723. if(!this.y0) this.y0=0;
  3724. if(!this.lat0) this.lat0=0;
  3725. if(!this.long0) this.long0=0;
  3726. if(!this.lat_ts) this.lat_ts=0;
  3727. if (!this.title) this.title = "Equidistant Cylindrical (Plate Carre)";
  3728. this.rc= Math.cos(this.lat_ts);
  3729. },
  3730. // forward equations--mapping lat,long to x,y
  3731. // -----------------------------------------------------------------
  3732. forward : function(p) {
  3733. var lon= p.x;
  3734. var lat= p.y;
  3735. var dlon = Proj4js.common.adjust_lon(lon - this.long0);
  3736. var dlat = Proj4js.common.adjust_lat(lat - this.lat0 );
  3737. p.x= this.x0 + (this.a*dlon*this.rc);
  3738. p.y= this.y0 + (this.a*dlat );
  3739. return p;
  3740. },
  3741. // inverse equations--mapping x,y to lat/long
  3742. // -----------------------------------------------------------------
  3743. inverse : function(p) {
  3744. var x= p.x;
  3745. var y= p.y;
  3746. p.x= Proj4js.common.adjust_lon(this.long0 + ((x - this.x0)/(this.a*this.rc)));
  3747. p.y= Proj4js.common.adjust_lat(this.lat0 + ((y - this.y0)/(this.a )));
  3748. return p;
  3749. }
  3750. };
  3751. /* ======================================================================
  3752. projCode/cass.js
  3753. ====================================================================== */
  3754. /*******************************************************************************
  3755. NAME CASSINI
  3756. PURPOSE: Transforms input longitude and latitude to Easting and
  3757. Northing for the Cassini projection. The
  3758. longitude and latitude must be in radians. The Easting
  3759. and Northing values will be returned in meters.
  3760. Ported from PROJ.4.
  3761. ALGORITHM REFERENCES
  3762. 1. Snyder, John P., "Map Projections--A Working Manual", U.S. Geological
  3763. Survey Professional Paper 1395 (Supersedes USGS Bulletin 1532), United
  3764. State Government Printing Office, Washington D.C., 1987.
  3765. 2. Snyder, John P. and Voxland, Philip M., "An Album of Map Projections",
  3766. U.S. Geological Survey Professional Paper 1453 , United State Government
  3767. *******************************************************************************/
  3768. //Proj4js.defs["EPSG:28191"] = "+proj=cass +lat_0=31.73409694444445 +lon_0=35.21208055555556 +x_0=170251.555 +y_0=126867.909 +a=6378300.789 +b=6356566.435 +towgs84=-275.722,94.7824,340.894,-8.001,-4.42,-11.821,1 +units=m +no_defs";
  3769. // Initialize the Cassini projection
  3770. // -----------------------------------------------------------------
  3771. Proj4js.Proj.cass = {
  3772. init : function() {
  3773. if (!this.sphere) {
  3774. this.en = Proj4js.common.pj_enfn(this.es)
  3775. this.m0 = Proj4js.common.pj_mlfn(this.lat0, Math.sin(this.lat0), Math.cos(this.lat0), this.en);
  3776. }
  3777. },
  3778. C1: .16666666666666666666,
  3779. C2: .00833333333333333333,
  3780. C3: .04166666666666666666,
  3781. C4: .33333333333333333333,
  3782. C5: .06666666666666666666,
  3783. /* Cassini forward equations--mapping lat,long to x,y
  3784. -----------------------------------------------------------------------*/
  3785. forward: function(p) {
  3786. /* Forward equations
  3787. -----------------*/
  3788. var x,y;
  3789. var lam=p.x;
  3790. var phi=p.y;
  3791. lam = Proj4js.common.adjust_lon(lam - this.long0);
  3792. if (this.sphere) {
  3793. x = Math.asin(Math.cos(phi) * Math.sin(lam));
  3794. y = Math.atan2(Math.tan(phi) , Math.cos(lam)) - this.phi0;
  3795. } else {
  3796. //ellipsoid
  3797. this.n = Math.sin(phi);
  3798. this.c = Math.cos(phi);
  3799. y = Proj4js.common.pj_mlfn(phi, this.n, this.c, this.en);
  3800. this.n = 1./Math.sqrt(1. - this.es * this.n * this.n);
  3801. this.tn = Math.tan(phi);
  3802. this.t = this.tn * this.tn;
  3803. this.a1 = lam * this.c;
  3804. this.c *= this.es * this.c / (1 - this.es);
  3805. this.a2 = this.a1 * this.a1;
  3806. x = this.n * this.a1 * (1. - this.a2 * this.t * (this.C1 - (8. - this.t + 8. * this.c) * this.a2 * this.C2));
  3807. y -= this.m0 - this.n * this.tn * this.a2 * (.5 + (5. - this.t + 6. * this.c) * this.a2 * this.C3);
  3808. }
  3809. p.x = this.a*x + this.x0;
  3810. p.y = this.a*y + this.y0;
  3811. return p;
  3812. },//cassFwd()
  3813. /* Inverse equations
  3814. -----------------*/
  3815. inverse: function(p) {
  3816. p.x -= this.x0;
  3817. p.y -= this.y0;
  3818. var x = p.x/this.a;
  3819. var y = p.y/this.a;
  3820. var phi, lam;
  3821. if (this.sphere) {
  3822. this.dd = y + this.lat0;
  3823. phi = Math.asin(Math.sin(this.dd) * Math.cos(x));
  3824. lam = Math.atan2(Math.tan(x), Math.cos(this.dd));
  3825. } else {
  3826. /* ellipsoid */
  3827. var ph1 = Proj4js.common.pj_inv_mlfn(this.m0 + y, this.es, this.en);
  3828. this.tn = Math.tan(ph1);
  3829. this.t = this.tn * this.tn;
  3830. this.n = Math.sin(ph1);
  3831. this.r = 1. / (1. - this.es * this.n * this.n);
  3832. this.n = Math.sqrt(this.r);
  3833. this.r *= (1. - this.es) * this.n;
  3834. this.dd = x / this.n;
  3835. this.d2 = this.dd * this.dd;
  3836. phi = ph1 - (this.n * this.tn / this.r) * this.d2 * (.5 - (1. + 3. * this.t) * this.d2 * this.C3);
  3837. lam = this.dd * (1. + this.t * this.d2 * (-this.C4 + (1. + 3. * this.t) * this.d2 * this.C5)) / Math.cos(ph1);
  3838. }
  3839. p.x = Proj4js.common.adjust_lon(this.long0+lam);
  3840. p.y = phi;
  3841. return p;
  3842. }//cassInv()
  3843. }
  3844. /* ======================================================================
  3845. projCode/gauss.js
  3846. ====================================================================== */
  3847. Proj4js.Proj.gauss = {
  3848. init : function() {
  3849. var sphi = Math.sin(this.lat0);
  3850. var cphi = Math.cos(this.lat0);
  3851. cphi *= cphi;
  3852. this.rc = Math.sqrt(1.0 - this.es) / (1.0 - this.es * sphi * sphi);
  3853. this.C = Math.sqrt(1.0 + this.es * cphi * cphi / (1.0 - this.es));
  3854. this.phic0 = Math.asin(sphi / this.C);
  3855. this.ratexp = 0.5 * this.C * this.e;
  3856. this.K = Math.tan(0.5 * this.phic0 + Proj4js.common.FORTPI) / (Math.pow(Math.tan(0.5*this.lat0 + Proj4js.common.FORTPI), this.C) * Proj4js.common.srat(this.e*sphi, this.ratexp));
  3857. },
  3858. forward : function(p) {
  3859. var lon = p.x;
  3860. var lat = p.y;
  3861. p.y = 2.0 * Math.atan( this.K * Math.pow(Math.tan(0.5 * lat + Proj4js.common.FORTPI), this.C) * Proj4js.common.srat(this.e * Math.sin(lat), this.ratexp) ) - Proj4js.common.HALF_PI;
  3862. p.x = this.C * lon;
  3863. return p;
  3864. },
  3865. inverse : function(p) {
  3866. var DEL_TOL = 1e-14;
  3867. var lon = p.x / this.C;
  3868. var lat = p.y;
  3869. var num = Math.pow(Math.tan(0.5 * lat + Proj4js.common.FORTPI)/this.K, 1./this.C);
  3870. for (var i = Proj4js.common.MAX_ITER; i>0; --i) {
  3871. lat = 2.0 * Math.atan(num * Proj4js.common.srat(this.e * Math.sin(p.y), -0.5 * this.e)) - Proj4js.common.HALF_PI;
  3872. if (Math.abs(lat - p.y) < DEL_TOL) break;
  3873. p.y = lat;
  3874. }
  3875. /* convergence failed */
  3876. if (!i) {
  3877. Proj4js.reportError("gauss:inverse:convergence failed");
  3878. return null;
  3879. }
  3880. p.x = lon;
  3881. p.y = lat;
  3882. return p;
  3883. }
  3884. };
  3885. /* ======================================================================
  3886. projCode/omerc.js
  3887. ====================================================================== */
  3888. /*******************************************************************************
  3889. NAME OBLIQUE MERCATOR (HOTINE)
  3890. PURPOSE: Transforms input longitude and latitude to Easting and
  3891. Northing for the Oblique Mercator projection. The
  3892. longitude and latitude must be in radians. The Easting
  3893. and Northing values will be returned in meters.
  3894. PROGRAMMER DATE
  3895. ---------- ----
  3896. T. Mittan Mar, 1993
  3897. ALGORITHM REFERENCES
  3898. 1. Snyder, John P., "Map Projections--A Working Manual", U.S. Geological
  3899. Survey Professional Paper 1395 (Supersedes USGS Bulletin 1532), United
  3900. State Government Printing Office, Washington D.C., 1987.
  3901. 2. Snyder, John P. and Voxland, Philip M., "An Album of Map Projections",
  3902. U.S. Geological Survey Professional Paper 1453 , United State Government
  3903. Printing Office, Washington D.C., 1989.
  3904. *******************************************************************************/
  3905. Proj4js.Proj.omerc = {
  3906. /* Initialize the Oblique Mercator projection
  3907. ------------------------------------------*/
  3908. init: function() {
  3909. if (!this.mode) this.mode=0;
  3910. if (!this.lon1) {this.lon1=0;this.mode=1;}
  3911. if (!this.lon2) this.lon2=0;
  3912. if (!this.lat2) this.lat2=0;
  3913. /* Place parameters in static storage for common use
  3914. -------------------------------------------------*/
  3915. var temp = this.b/ this.a;
  3916. var es = 1.0 - Math.pow(temp,2);
  3917. var e = Math.sqrt(es);
  3918. this.sin_p20=Math.sin(this.lat0);
  3919. this.cos_p20=Math.cos(this.lat0);
  3920. this.con = 1.0 - this.es * this.sin_p20 * this.sin_p20;
  3921. this.com = Math.sqrt(1.0 - es);
  3922. this.bl = Math.sqrt(1.0 + this.es * Math.pow(this.cos_p20,4.0)/(1.0 - es));
  3923. this.al = this.a * this.bl * this.k0 * this.com / this.con;
  3924. if (Math.abs(this.lat0) < Proj4js.common.EPSLN) {
  3925. this.ts = 1.0;
  3926. this.d = 1.0;
  3927. this.el = 1.0;
  3928. } else {
  3929. this.ts = Proj4js.common.tsfnz(this.e,this.lat0,this.sin_p20);
  3930. this.con = Math.sqrt(this.con);
  3931. this.d = this.bl * this.com / (this.cos_p20 * this.con);
  3932. if ((this.d * this.d - 1.0) > 0.0) {
  3933. if (this.lat0 >= 0.0) {
  3934. this.f = this.d + Math.sqrt(this.d * this.d - 1.0);
  3935. } else {
  3936. this.f = this.d - Math.sqrt(this.d * this.d - 1.0);
  3937. }
  3938. } else {
  3939. this.f = this.d;
  3940. }
  3941. this.el = this.f * Math.pow(this.ts,this.bl);
  3942. }
  3943. //this.longc=52.60353916666667;
  3944. if (this.mode != 0) {
  3945. this.g = .5 * (this.f - 1.0/this.f);
  3946. this.gama = Proj4js.common.asinz(Math.sin(this.alpha) / this.d);
  3947. this.longc= this.longc - Proj4js.common.asinz(this.g * Math.tan(this.gama))/this.bl;
  3948. /* Report parameters common to format B
  3949. -------------------------------------*/
  3950. //genrpt(azimuth * R2D,"Azimuth of Central Line: ");
  3951. //cenlon(lon_origin);
  3952. // cenlat(lat_origin);
  3953. this.con = Math.abs(this.lat0);
  3954. if ((this.con > Proj4js.common.EPSLN) && (Math.abs(this.con - Proj4js.common.HALF_PI) > Proj4js.common.EPSLN)) {
  3955. this.singam=Math.sin(this.gama);
  3956. this.cosgam=Math.cos(this.gama);
  3957. this.sinaz=Math.sin(this.alpha);
  3958. this.cosaz=Math.cos(this.alpha);
  3959. if (this.lat0>= 0) {
  3960. this.u = (this.al / this.bl) * Math.atan(Math.sqrt(this.d*this.d - 1.0)/this.cosaz);
  3961. } else {
  3962. this.u = -(this.al / this.bl) *Math.atan(Math.sqrt(this.d*this.d - 1.0)/this.cosaz);
  3963. }
  3964. } else {
  3965. Proj4js.reportError("omerc:Init:DataError");
  3966. }
  3967. } else {
  3968. this.sinphi =Math. sin(this.at1);
  3969. this.ts1 = Proj4js.common.tsfnz(this.e,this.lat1,this.sinphi);
  3970. this.sinphi = Math.sin(this.lat2);
  3971. this.ts2 = Proj4js.common.tsfnz(this.e,this.lat2,this.sinphi);
  3972. this.h = Math.pow(this.ts1,this.bl);
  3973. this.l = Math.pow(this.ts2,this.bl);
  3974. this.f = this.el/this.h;
  3975. this.g = .5 * (this.f - 1.0/this.f);
  3976. this.j = (this.el * this.el - this.l * this.h)/(this.el * this.el + this.l * this.h);
  3977. this.p = (this.l - this.h) / (this.l + this.h);
  3978. this.dlon = this.lon1 - this.lon2;
  3979. if (this.dlon < -Proj4js.common.PI) this.lon2 = this.lon2 - 2.0 * Proj4js.common.PI;
  3980. if (this.dlon > Proj4js.common.PI) this.lon2 = this.lon2 + 2.0 * Proj4js.common.PI;
  3981. this.dlon = this.lon1 - this.lon2;
  3982. this.longc = .5 * (this.lon1 + this.lon2) -Math.atan(this.j * Math.tan(.5 * this.bl * this.dlon)/this.p)/this.bl;
  3983. this.dlon = Proj4js.common.adjust_lon(this.lon1 - this.longc);
  3984. this.gama = Math.atan(Math.sin(this.bl * this.dlon)/this.g);
  3985. this.alpha = Proj4js.common.asinz(this.d * Math.sin(this.gama));
  3986. /* Report parameters common to format A
  3987. -------------------------------------*/
  3988. if (Math.abs(this.lat1 - this.lat2) <= Proj4js.common.EPSLN) {
  3989. Proj4js.reportError("omercInitDataError");
  3990. //return(202);
  3991. } else {
  3992. this.con = Math.abs(this.lat1);
  3993. }
  3994. if ((this.con <= Proj4js.common.EPSLN) || (Math.abs(this.con - Proj4js.common.HALF_PI) <= Proj4js.common.EPSLN)) {
  3995. Proj4js.reportError("omercInitDataError");
  3996. //return(202);
  3997. } else {
  3998. if (Math.abs(Math.abs(this.lat0) - Proj4js.common.HALF_PI) <= Proj4js.common.EPSLN) {
  3999. Proj4js.reportError("omercInitDataError");
  4000. //return(202);
  4001. }
  4002. }
  4003. this.singam=Math.sin(this.gam);
  4004. this.cosgam=Math.cos(this.gam);
  4005. this.sinaz=Math.sin(this.alpha);
  4006. this.cosaz=Math.cos(this.alpha);
  4007. if (this.lat0 >= 0) {
  4008. this.u = (this.al/this.bl) * Math.atan(Math.sqrt(this.d * this.d - 1.0)/this.cosaz);
  4009. } else {
  4010. this.u = -(this.al/this.bl) * Math.atan(Math.sqrt(this.d * this.d - 1.0)/this.cosaz);
  4011. }
  4012. }
  4013. },
  4014. /* Oblique Mercator forward equations--mapping lat,long to x,y
  4015. ----------------------------------------------------------*/
  4016. forward: function(p) {
  4017. var theta; /* angle */
  4018. var sin_phi, cos_phi;/* sin and cos value */
  4019. var b; /* temporary values */
  4020. var c, t, tq; /* temporary values */
  4021. var con, n, ml; /* cone constant, small m */
  4022. var q,us,vl;
  4023. var ul,vs;
  4024. var s;
  4025. var dlon;
  4026. var ts1;
  4027. var lon=p.x;
  4028. var lat=p.y;
  4029. /* Forward equations
  4030. -----------------*/
  4031. sin_phi = Math.sin(lat);
  4032. dlon = Proj4js.common.adjust_lon(lon - this.longc);
  4033. vl = Math.sin(this.bl * dlon);
  4034. if (Math.abs(Math.abs(lat) - Proj4js.common.HALF_PI) > Proj4js.common.EPSLN) {
  4035. ts1 = Proj4js.common.tsfnz(this.e,lat,sin_phi);
  4036. q = this.el / (Math.pow(ts1,this.bl));
  4037. s = .5 * (q - 1.0 / q);
  4038. t = .5 * (q + 1.0/ q);
  4039. ul = (s * this.singam - vl * this.cosgam) / t;
  4040. con = Math.cos(this.bl * dlon);
  4041. if (Math.abs(con) < .0000001) {
  4042. us = this.al * this.bl * dlon;
  4043. } else {
  4044. us = this.al * Math.atan((s * this.cosgam + vl * this.singam) / con)/this.bl;
  4045. if (con < 0) us = us + Proj4js.common.PI * this.al / this.bl;
  4046. }
  4047. } else {
  4048. if (lat >= 0) {
  4049. ul = this.singam;
  4050. } else {
  4051. ul = -this.singam;
  4052. }
  4053. us = this.al * lat / this.bl;
  4054. }
  4055. if (Math.abs(Math.abs(ul) - 1.0) <= Proj4js.common.EPSLN) {
  4056. //alert("Point projects into infinity","omer-for");
  4057. Proj4js.reportError("omercFwdInfinity");
  4058. //return(205);
  4059. }
  4060. vs = .5 * this.al * Math.log((1.0 - ul)/(1.0 + ul)) / this.bl;
  4061. us = us - this.u;
  4062. var x = this.x0 + vs * this.cosaz + us * this.sinaz;
  4063. var y = this.y0 + us * this.cosaz - vs * this.sinaz;
  4064. p.x=x;
  4065. p.y=y;
  4066. return p;
  4067. },
  4068. inverse: function(p) {
  4069. var delta_lon; /* Delta longitude (Given longitude - center */
  4070. var theta; /* angle */
  4071. var delta_theta; /* adjusted longitude */
  4072. var sin_phi, cos_phi;/* sin and cos value */
  4073. var b; /* temporary values */
  4074. var c, t, tq; /* temporary values */
  4075. var con, n, ml; /* cone constant, small m */
  4076. var vs,us,q,s,ts1;
  4077. var vl,ul,bs;
  4078. var lon, lat;
  4079. var flag;
  4080. /* Inverse equations
  4081. -----------------*/
  4082. p.x -= this.x0;
  4083. p.y -= this.y0;
  4084. flag = 0;
  4085. vs = p.x * this.cosaz - p.y * this.sinaz;
  4086. us = p.y * this.cosaz + p.x * this.sinaz;
  4087. us = us + this.u;
  4088. q = Math.exp(-this.bl * vs / this.al);
  4089. s = .5 * (q - 1.0/q);
  4090. t = .5 * (q + 1.0/q);
  4091. vl = Math.sin(this.bl * us / this.al);
  4092. ul = (vl * this.cosgam + s * this.singam)/t;
  4093. if (Math.abs(Math.abs(ul) - 1.0) <= Proj4js.common.EPSLN)
  4094. {
  4095. lon = this.longc;
  4096. if (ul >= 0.0) {
  4097. lat = Proj4js.common.HALF_PI;
  4098. } else {
  4099. lat = -Proj4js.common.HALF_PI;
  4100. }
  4101. } else {
  4102. con = 1.0 / this.bl;
  4103. ts1 =Math.pow((this.el / Math.sqrt((1.0 + ul) / (1.0 - ul))),con);
  4104. lat = Proj4js.common.phi2z(this.e,ts1);
  4105. //if (flag != 0)
  4106. //return(flag);
  4107. //~ con = Math.cos(this.bl * us /al);
  4108. theta = this.longc - Math.atan2((s * this.cosgam - vl * this.singam) , con)/this.bl;
  4109. lon = Proj4js.common.adjust_lon(theta);
  4110. }
  4111. p.x=lon;
  4112. p.y=lat;
  4113. return p;
  4114. }
  4115. };
  4116. /* ======================================================================
  4117. projCode/lcc.js
  4118. ====================================================================== */
  4119. /*******************************************************************************
  4120. NAME LAMBERT CONFORMAL CONIC
  4121. PURPOSE: Transforms input longitude and latitude to Easting and
  4122. Northing for the Lambert Conformal Conic projection. The
  4123. longitude and latitude must be in radians. The Easting
  4124. and Northing values will be returned in meters.
  4125. ALGORITHM REFERENCES
  4126. 1. Snyder, John P., "Map Projections--A Working Manual", U.S. Geological
  4127. Survey Professional Paper 1395 (Supersedes USGS Bulletin 1532), United
  4128. State Government Printing Office, Washington D.C., 1987.
  4129. 2. Snyder, John P. and Voxland, Philip M., "An Album of Map Projections",
  4130. U.S. Geological Survey Professional Paper 1453 , United State Government
  4131. *******************************************************************************/
  4132. //<2104> +proj=lcc +lat_1=10.16666666666667 +lat_0=10.16666666666667 +lon_0=-71.60561777777777 +k_0=1 +x0=-17044 +x0=-23139.97 +ellps=intl +units=m +no_defs no_defs
  4133. // Initialize the Lambert Conformal conic projection
  4134. // -----------------------------------------------------------------
  4135. //Proj4js.Proj.lcc = Class.create();
  4136. Proj4js.Proj.lcc = {
  4137. init : function() {
  4138. // array of: r_maj,r_min,lat1,lat2,c_lon,c_lat,false_east,false_north
  4139. //double c_lat; /* center latitude */
  4140. //double c_lon; /* center longitude */
  4141. //double lat1; /* first standard parallel */
  4142. //double lat2; /* second standard parallel */
  4143. //double r_maj; /* major axis */
  4144. //double r_min; /* minor axis */
  4145. //double false_east; /* x offset in meters */
  4146. //double false_north; /* y offset in meters */
  4147. if (!this.lat2){this.lat2=this.lat0;}//if lat2 is not defined
  4148. if (!this.k0) this.k0 = 1.0;
  4149. // Standard Parallels cannot be equal and on opposite sides of the equator
  4150. if (Math.abs(this.lat1+this.lat2) < Proj4js.common.EPSLN) {
  4151. Proj4js.reportError("lcc:init: Equal Latitudes");
  4152. return;
  4153. }
  4154. var temp = this.b / this.a;
  4155. this.e = Math.sqrt(1.0 - temp*temp);
  4156. var sin1 = Math.sin(this.lat1);
  4157. var cos1 = Math.cos(this.lat1);
  4158. var ms1 = Proj4js.common.msfnz(this.e, sin1, cos1);
  4159. var ts1 = Proj4js.common.tsfnz(this.e, this.lat1, sin1);
  4160. var sin2 = Math.sin(this.lat2);
  4161. var cos2 = Math.cos(this.lat2);
  4162. var ms2 = Proj4js.common.msfnz(this.e, sin2, cos2);
  4163. var ts2 = Proj4js.common.tsfnz(this.e, this.lat2, sin2);
  4164. var ts0 = Proj4js.common.tsfnz(this.e, this.lat0, Math.sin(this.lat0));
  4165. if (Math.abs(this.lat1 - this.lat2) > Proj4js.common.EPSLN) {
  4166. this.ns = Math.log(ms1/ms2)/Math.log(ts1/ts2);
  4167. } else {
  4168. this.ns = sin1;
  4169. }
  4170. this.f0 = ms1 / (this.ns * Math.pow(ts1, this.ns));
  4171. this.rh = this.a * this.f0 * Math.pow(ts0, this.ns);
  4172. if (!this.title) this.title = "Lambert Conformal Conic";
  4173. },
  4174. // Lambert Conformal conic forward equations--mapping lat,long to x,y
  4175. // -----------------------------------------------------------------
  4176. forward : function(p) {
  4177. var lon = p.x;
  4178. var lat = p.y;
  4179. // convert to radians
  4180. if ( lat <= 90.0 && lat >= -90.0 && lon <= 180.0 && lon >= -180.0) {
  4181. //lon = lon * Proj4js.common.D2R;
  4182. //lat = lat * Proj4js.common.D2R;
  4183. } else {
  4184. Proj4js.reportError("lcc:forward: llInputOutOfRange: "+ lon +" : " + lat);
  4185. return null;
  4186. }
  4187. var con = Math.abs( Math.abs(lat) - Proj4js.common.HALF_PI);
  4188. var ts, rh1;
  4189. if (con > Proj4js.common.EPSLN) {
  4190. ts = Proj4js.common.tsfnz(this.e, lat, Math.sin(lat) );
  4191. rh1 = this.a * this.f0 * Math.pow(ts, this.ns);
  4192. } else {
  4193. con = lat * this.ns;
  4194. if (con <= 0) {
  4195. Proj4js.reportError("lcc:forward: No Projection");
  4196. return null;
  4197. }
  4198. rh1 = 0;
  4199. }
  4200. var theta = this.ns * Proj4js.common.adjust_lon(lon - this.long0);
  4201. p.x = this.k0 * (rh1 * Math.sin(theta)) + this.x0;
  4202. p.y = this.k0 * (this.rh - rh1 * Math.cos(theta)) + this.y0;
  4203. return p;
  4204. },
  4205. // Lambert Conformal Conic inverse equations--mapping x,y to lat/long
  4206. // -----------------------------------------------------------------
  4207. inverse : function(p) {
  4208. var rh1, con, ts;
  4209. var lat, lon;
  4210. var x = (p.x - this.x0)/this.k0;
  4211. var y = (this.rh - (p.y - this.y0)/this.k0);
  4212. if (this.ns > 0) {
  4213. rh1 = Math.sqrt (x * x + y * y);
  4214. con = 1.0;
  4215. } else {
  4216. rh1 = -Math.sqrt (x * x + y * y);
  4217. con = -1.0;
  4218. }
  4219. var theta = 0.0;
  4220. if (rh1 != 0) {
  4221. theta = Math.atan2((con * x),(con * y));
  4222. }
  4223. if ((rh1 != 0) || (this.ns > 0.0)) {
  4224. con = 1.0/this.ns;
  4225. ts = Math.pow((rh1/(this.a * this.f0)), con);
  4226. lat = Proj4js.common.phi2z(this.e, ts);
  4227. if (lat == -9999) return null;
  4228. } else {
  4229. lat = -Proj4js.common.HALF_PI;
  4230. }
  4231. lon = Proj4js.common.adjust_lon(theta/this.ns + this.long0);
  4232. p.x = lon;
  4233. p.y = lat;
  4234. return p;
  4235. }
  4236. };
  4237. /* ======================================================================
  4238. projCode/laea.js
  4239. ====================================================================== */
  4240. /*******************************************************************************
  4241. NAME LAMBERT AZIMUTHAL EQUAL-AREA
  4242. PURPOSE: Transforms input longitude and latitude to Easting and
  4243. Northing for the Lambert Azimuthal Equal-Area projection. The
  4244. longitude and latitude must be in radians. The Easting
  4245. and Northing values will be returned in meters.
  4246. PROGRAMMER DATE
  4247. ---------- ----
  4248. D. Steinwand, EROS March, 1991
  4249. This function was adapted from the Lambert Azimuthal Equal Area projection
  4250. code (FORTRAN) in the General Cartographic Transformation Package software
  4251. which is available from the U.S. Geological Survey National Mapping Division.
  4252. ALGORITHM REFERENCES
  4253. 1. "New Equal-Area Map Projections for Noncircular Regions", John P. Snyder,
  4254. The American Cartographer, Vol 15, No. 4, October 1988, pp. 341-355.
  4255. 2. Snyder, John P., "Map Projections--A Working Manual", U.S. Geological
  4256. Survey Professional Paper 1395 (Supersedes USGS Bulletin 1532), United
  4257. State Government Printing Office, Washington D.C., 1987.
  4258. 3. "Software Documentation for GCTP General Cartographic Transformation
  4259. Package", U.S. Geological Survey National Mapping Division, May 1982.
  4260. *******************************************************************************/
  4261. Proj4js.Proj.laea = {
  4262. S_POLE: 1,
  4263. N_POLE: 2,
  4264. EQUIT: 3,
  4265. OBLIQ: 4,
  4266. /* Initialize the Lambert Azimuthal Equal Area projection
  4267. ------------------------------------------------------*/
  4268. init: function() {
  4269. var t = Math.abs(this.lat0);
  4270. if (Math.abs(t - Proj4js.common.HALF_PI) < Proj4js.common.EPSLN) {
  4271. this.mode = this.lat0 < 0. ? this.S_POLE : this.N_POLE;
  4272. } else if (Math.abs(t) < Proj4js.common.EPSLN) {
  4273. this.mode = this.EQUIT;
  4274. } else {
  4275. this.mode = this.OBLIQ;
  4276. }
  4277. if (this.es > 0) {
  4278. var sinphi;
  4279. this.qp = Proj4js.common.qsfnz(this.e, 1.0);
  4280. this.mmf = .5 / (1. - this.es);
  4281. this.apa = this.authset(this.es);
  4282. switch (this.mode) {
  4283. case this.N_POLE:
  4284. case this.S_POLE:
  4285. this.dd = 1.;
  4286. break;
  4287. case this.EQUIT:
  4288. this.rq = Math.sqrt(.5 * this.qp);
  4289. this.dd = 1. / this.rq;
  4290. this.xmf = 1.;
  4291. this.ymf = .5 * this.qp;
  4292. break;
  4293. case this.OBLIQ:
  4294. this.rq = Math.sqrt(.5 * this.qp);
  4295. sinphi = Math.sin(this.lat0);
  4296. this.sinb1 = Proj4js.common.qsfnz(this.e, sinphi) / this.qp;
  4297. this.cosb1 = Math.sqrt(1. - this.sinb1 * this.sinb1);
  4298. this.dd = Math.cos(this.lat0) / (Math.sqrt(1. - this.es * sinphi * sinphi) * this.rq * this.cosb1);
  4299. this.ymf = (this.xmf = this.rq) / this.dd;
  4300. this.xmf *= this.dd;
  4301. break;
  4302. }
  4303. } else {
  4304. if (this.mode == this.OBLIQ) {
  4305. this.sinph0 = Math.sin(this.lat0);
  4306. this.cosph0 = Math.cos(this.lat0);
  4307. }
  4308. }
  4309. },
  4310. /* Lambert Azimuthal Equal Area forward equations--mapping lat,long to x,y
  4311. -----------------------------------------------------------------------*/
  4312. forward: function(p) {
  4313. /* Forward equations
  4314. -----------------*/
  4315. var x,y;
  4316. var lam=p.x;
  4317. var phi=p.y;
  4318. lam = Proj4js.common.adjust_lon(lam - this.long0);
  4319. if (this.sphere) {
  4320. var coslam, cosphi, sinphi;
  4321. sinphi = Math.sin(phi);
  4322. cosphi = Math.cos(phi);
  4323. coslam = Math.cos(lam);
  4324. switch (this.mode) {
  4325. case this.OBLIQ:
  4326. case this.EQUIT:
  4327. y = (this.mode == this.EQUIT) ? 1. + cosphi * coslam : 1. + this.sinph0 * sinphi + this.cosph0 * cosphi * coslam;
  4328. if (y <= Proj4js.common.EPSLN) {
  4329. Proj4js.reportError("laea:fwd:y less than eps");
  4330. return null;
  4331. }
  4332. y = Math.sqrt(2. / y);
  4333. x = y * cosphi * Math.sin(lam);
  4334. y *= (this.mode == this.EQUIT) ? sinphi : this.cosph0 * sinphi - this.sinph0 * cosphi * coslam;
  4335. break;
  4336. case this.N_POLE:
  4337. coslam = -coslam;
  4338. case this.S_POLE:
  4339. if (Math.abs(phi + this.phi0) < Proj4js.common.EPSLN) {
  4340. Proj4js.reportError("laea:fwd:phi < eps");
  4341. return null;
  4342. }
  4343. y = Proj4js.common.FORTPI - phi * .5;
  4344. y = 2. * ((this.mode == this.S_POLE) ? Math.cos(y) : Math.sin(y));
  4345. x = y * Math.sin(lam);
  4346. y *= coslam;
  4347. break;
  4348. }
  4349. } else {
  4350. var coslam, sinlam, sinphi, q, sinb=0.0, cosb=0.0, b=0.0;
  4351. coslam = Math.cos(lam);
  4352. sinlam = Math.sin(lam);
  4353. sinphi = Math.sin(phi);
  4354. q = Proj4js.common.qsfnz(this.e, sinphi);
  4355. if (this.mode == this.OBLIQ || this.mode == this.EQUIT) {
  4356. sinb = q / this.qp;
  4357. cosb = Math.sqrt(1. - sinb * sinb);
  4358. }
  4359. switch (this.mode) {
  4360. case this.OBLIQ:
  4361. b = 1. + this.sinb1 * sinb + this.cosb1 * cosb * coslam;
  4362. break;
  4363. case this.EQUIT:
  4364. b = 1. + cosb * coslam;
  4365. break;
  4366. case this.N_POLE:
  4367. b = Proj4js.common.HALF_PI + phi;
  4368. q = this.qp - q;
  4369. break;
  4370. case this.S_POLE:
  4371. b = phi - Proj4js.common.HALF_PI;
  4372. q = this.qp + q;
  4373. break;
  4374. }
  4375. if (Math.abs(b) < Proj4js.common.EPSLN) {
  4376. Proj4js.reportError("laea:fwd:b < eps");
  4377. return null;
  4378. }
  4379. switch (this.mode) {
  4380. case this.OBLIQ:
  4381. case this.EQUIT:
  4382. b = Math.sqrt(2. / b);
  4383. if (this.mode == this.OBLIQ) {
  4384. y = this.ymf * b * (this.cosb1 * sinb - this.sinb1 * cosb * coslam);
  4385. } else {
  4386. y = (b = Math.sqrt(2. / (1. + cosb * coslam))) * sinb * this.ymf;
  4387. }
  4388. x = this.xmf * b * cosb * sinlam;
  4389. break;
  4390. case this.N_POLE:
  4391. case this.S_POLE:
  4392. if (q >= 0.) {
  4393. x = (b = Math.sqrt(q)) * sinlam;
  4394. y = coslam * ((this.mode == this.S_POLE) ? b : -b);
  4395. } else {
  4396. x = y = 0.;
  4397. }
  4398. break;
  4399. }
  4400. }
  4401. //v 1.0
  4402. /*
  4403. var sin_lat=Math.sin(lat);
  4404. var cos_lat=Math.cos(lat);
  4405. var sin_delta_lon=Math.sin(delta_lon);
  4406. var cos_delta_lon=Math.cos(delta_lon);
  4407. var g =this.sin_lat_o * sin_lat +this.cos_lat_o * cos_lat * cos_delta_lon;
  4408. if (g == -1.0) {
  4409. Proj4js.reportError("laea:fwd:Point projects to a circle of radius "+ 2.0 * R);
  4410. return null;
  4411. }
  4412. var ksp = this.a * Math.sqrt(2.0 / (1.0 + g));
  4413. var x = ksp * cos_lat * sin_delta_lon + this.x0;
  4414. var y = ksp * (this.cos_lat_o * sin_lat - this.sin_lat_o * cos_lat * cos_delta_lon) + this.y0;
  4415. */
  4416. p.x = this.a*x + this.x0;
  4417. p.y = this.a*y + this.y0;
  4418. return p;
  4419. },//lamazFwd()
  4420. /* Inverse equations
  4421. -----------------*/
  4422. inverse: function(p) {
  4423. p.x -= this.x0;
  4424. p.y -= this.y0;
  4425. var x = p.x/this.a;
  4426. var y = p.y/this.a;
  4427. var lam, phi;
  4428. if (this.sphere) {
  4429. var cosz=0.0, rh, sinz=0.0;
  4430. rh = Math.sqrt(x*x + y*y);
  4431. phi = rh * .5;
  4432. if (phi > 1.) {
  4433. Proj4js.reportError("laea:Inv:DataError");
  4434. return null;
  4435. }
  4436. phi = 2. * Math.asin(phi);
  4437. if (this.mode == this.OBLIQ || this.mode == this.EQUIT) {
  4438. sinz = Math.sin(phi);
  4439. cosz = Math.cos(phi);
  4440. }
  4441. switch (this.mode) {
  4442. case this.EQUIT:
  4443. phi = (Math.abs(rh) <= Proj4js.common.EPSLN) ? 0. : Math.asin(y * sinz / rh);
  4444. x *= sinz;
  4445. y = cosz * rh;
  4446. break;
  4447. case this.OBLIQ:
  4448. phi = (Math.abs(rh) <= Proj4js.common.EPSLN) ? this.phi0 : Math.asin(cosz * this.sinph0 + y * sinz * this.cosph0 / rh);
  4449. x *= sinz * this.cosph0;
  4450. y = (cosz - Math.sin(phi) * this.sinph0) * rh;
  4451. break;
  4452. case this.N_POLE:
  4453. y = -y;
  4454. phi = Proj4js.common.HALF_PI - phi;
  4455. break;
  4456. case this.S_POLE:
  4457. phi -= Proj4js.common.HALF_PI;
  4458. break;
  4459. }
  4460. lam = (y == 0. && (this.mode == this.EQUIT || this.mode == this.OBLIQ)) ? 0. : Math.atan2(x, y);
  4461. } else {
  4462. var cCe, sCe, q, rho, ab=0.0;
  4463. switch (this.mode) {
  4464. case this.EQUIT:
  4465. case this.OBLIQ:
  4466. x /= this.dd;
  4467. y *= this.dd;
  4468. rho = Math.sqrt(x*x + y*y);
  4469. if (rho < Proj4js.common.EPSLN) {
  4470. p.x = 0.;
  4471. p.y = this.phi0;
  4472. return p;
  4473. }
  4474. sCe = 2. * Math.asin(.5 * rho / this.rq);
  4475. cCe = Math.cos(sCe);
  4476. x *= (sCe = Math.sin(sCe));
  4477. if (this.mode == this.OBLIQ) {
  4478. ab = cCe * this.sinb1 + y * sCe * this.cosb1 / rho
  4479. q = this.qp * ab;
  4480. y = rho * this.cosb1 * cCe - y * this.sinb1 * sCe;
  4481. } else {
  4482. ab = y * sCe / rho;
  4483. q = this.qp * ab;
  4484. y = rho * cCe;
  4485. }
  4486. break;
  4487. case this.N_POLE:
  4488. y = -y;
  4489. case this.S_POLE:
  4490. q = (x * x + y * y);
  4491. if (!q ) {
  4492. p.x = 0.;
  4493. p.y = this.phi0;
  4494. return p;
  4495. }
  4496. /*
  4497. q = this.qp - q;
  4498. */
  4499. ab = 1. - q / this.qp;
  4500. if (this.mode == this.S_POLE) {
  4501. ab = - ab;
  4502. }
  4503. break;
  4504. }
  4505. lam = Math.atan2(x, y);
  4506. phi = this.authlat(Math.asin(ab), this.apa);
  4507. }
  4508. /*
  4509. var Rh = Math.Math.sqrt(p.x *p.x +p.y * p.y);
  4510. var temp = Rh / (2.0 * this.a);
  4511. if (temp > 1) {
  4512. Proj4js.reportError("laea:Inv:DataError");
  4513. return null;
  4514. }
  4515. var z = 2.0 * Proj4js.common.asinz(temp);
  4516. var sin_z=Math.sin(z);
  4517. var cos_z=Math.cos(z);
  4518. var lon =this.long0;
  4519. if (Math.abs(Rh) > Proj4js.common.EPSLN) {
  4520. var lat = Proj4js.common.asinz(this.sin_lat_o * cos_z +this. cos_lat_o * sin_z *p.y / Rh);
  4521. var temp =Math.abs(this.lat0) - Proj4js.common.HALF_PI;
  4522. if (Math.abs(temp) > Proj4js.common.EPSLN) {
  4523. temp = cos_z -this.sin_lat_o * Math.sin(lat);
  4524. if(temp!=0.0) lon=Proj4js.common.adjust_lon(this.long0+Math.atan2(p.x*sin_z*this.cos_lat_o,temp*Rh));
  4525. } else if (this.lat0 < 0.0) {
  4526. lon = Proj4js.common.adjust_lon(this.long0 - Math.atan2(-p.x,p.y));
  4527. } else {
  4528. lon = Proj4js.common.adjust_lon(this.long0 + Math.atan2(p.x, -p.y));
  4529. }
  4530. } else {
  4531. lat = this.lat0;
  4532. }
  4533. */
  4534. //return(OK);
  4535. p.x = Proj4js.common.adjust_lon(this.long0+lam);
  4536. p.y = phi;
  4537. return p;
  4538. },//lamazInv()
  4539. /* determine latitude from authalic latitude */
  4540. P00: .33333333333333333333,
  4541. P01: .17222222222222222222,
  4542. P02: .10257936507936507936,
  4543. P10: .06388888888888888888,
  4544. P11: .06640211640211640211,
  4545. P20: .01641501294219154443,
  4546. authset: function(es) {
  4547. var t;
  4548. var APA = new Array();
  4549. APA[0] = es * this.P00;
  4550. t = es * es;
  4551. APA[0] += t * this.P01;
  4552. APA[1] = t * this.P10;
  4553. t *= es;
  4554. APA[0] += t * this.P02;
  4555. APA[1] += t * this.P11;
  4556. APA[2] = t * this.P20;
  4557. return APA;
  4558. },
  4559. authlat: function(beta, APA) {
  4560. var t = beta+beta;
  4561. return(beta + APA[0] * Math.sin(t) + APA[1] * Math.sin(t+t) + APA[2] * Math.sin(t+t+t));
  4562. }
  4563. };
  4564. /* ======================================================================
  4565. projCode/aeqd.js
  4566. ====================================================================== */
  4567. Proj4js.Proj.aeqd = {
  4568. init : function() {
  4569. this.sin_p12=Math.sin(this.lat0);
  4570. this.cos_p12=Math.cos(this.lat0);
  4571. },
  4572. forward: function(p) {
  4573. var lon=p.x;
  4574. var lat=p.y;
  4575. var ksp;
  4576. var sinphi=Math.sin(p.y);
  4577. var cosphi=Math.cos(p.y);
  4578. var dlon = Proj4js.common.adjust_lon(lon - this.long0);
  4579. var coslon = Math.cos(dlon);
  4580. var g = this.sin_p12 * sinphi + this.cos_p12 * cosphi * coslon;
  4581. if (Math.abs(Math.abs(g) - 1.0) < Proj4js.common.EPSLN) {
  4582. ksp = 1.0;
  4583. if (g < 0.0) {
  4584. Proj4js.reportError("aeqd:Fwd:PointError");
  4585. return;
  4586. }
  4587. } else {
  4588. var z = Math.acos(g);
  4589. ksp = z/Math.sin(z);
  4590. }
  4591. p.x = this.x0 + this.a * ksp * cosphi * Math.sin(dlon);
  4592. p.y = this.y0 + this.a * ksp * (this.cos_p12 * sinphi - this.sin_p12 * cosphi * coslon);
  4593. return p;
  4594. },
  4595. inverse: function(p){
  4596. p.x -= this.x0;
  4597. p.y -= this.y0;
  4598. var rh = Math.sqrt(p.x * p.x + p.y *p.y);
  4599. if (rh > (2.0 * Proj4js.common.HALF_PI * this.a)) {
  4600. Proj4js.reportError("aeqdInvDataError");
  4601. return;
  4602. }
  4603. var z = rh / this.a;
  4604. var sinz=Math.sin(z);
  4605. var cosz=Math.cos(z);
  4606. var lon = this.long0;
  4607. var lat;
  4608. if (Math.abs(rh) <= Proj4js.common.EPSLN) {
  4609. lat = this.lat0;
  4610. } else {
  4611. lat = Proj4js.common.asinz(cosz * this.sin_p12 + (p.y * sinz * this.cos_p12) / rh);
  4612. var con = Math.abs(this.lat0) - Proj4js.common.HALF_PI;
  4613. if (Math.abs(con) <= Proj4js.common.EPSLN) {
  4614. if (this.lat0 >= 0.0) {
  4615. lon = Proj4js.common.adjust_lon(this.long0 + Math.atan2(p.x , -p.y));
  4616. } else {
  4617. lon = Proj4js.common.adjust_lon(this.long0 - Math.atan2(-p.x , p.y));
  4618. }
  4619. } else {
  4620. con = cosz - this.sin_p12 * Math.sin(lat);
  4621. if ((Math.abs(con) < Proj4js.common.EPSLN) && (Math.abs(p.x) < Proj4js.common.EPSLN)) {
  4622. //no-op, just keep the lon value as is
  4623. } else {
  4624. var temp = Math.atan2((p.x * sinz * this.cos_p12), (con * rh));
  4625. lon = Proj4js.common.adjust_lon(this.long0 + Math.atan2((p.x * sinz * this.cos_p12), (con * rh)));
  4626. }
  4627. }
  4628. }
  4629. p.x = lon;
  4630. p.y = lat;
  4631. return p;
  4632. }
  4633. };
  4634. /* ======================================================================
  4635. projCode/moll.js
  4636. ====================================================================== */
  4637. /*******************************************************************************
  4638. NAME MOLLWEIDE
  4639. PURPOSE: Transforms input longitude and latitude to Easting and
  4640. Northing for the MOllweide projection. The
  4641. longitude and latitude must be in radians. The Easting
  4642. and Northing values will be returned in meters.
  4643. PROGRAMMER DATE
  4644. ---------- ----
  4645. D. Steinwand, EROS May, 1991; Updated Sept, 1992; Updated Feb, 1993
  4646. S. Nelson, EDC Jun, 2993; Made corrections in precision and
  4647. number of iterations.
  4648. ALGORITHM REFERENCES
  4649. 1. Snyder, John P. and Voxland, Philip M., "An Album of Map Projections",
  4650. U.S. Geological Survey Professional Paper 1453 , United State Government
  4651. Printing Office, Washington D.C., 1989.
  4652. 2. Snyder, John P., "Map Projections--A Working Manual", U.S. Geological
  4653. Survey Professional Paper 1395 (Supersedes USGS Bulletin 1532), United
  4654. State Government Printing Office, Washington D.C., 1987.
  4655. *******************************************************************************/
  4656. Proj4js.Proj.moll = {
  4657. /* Initialize the Mollweide projection
  4658. ------------------------------------*/
  4659. init: function(){
  4660. //no-op
  4661. },
  4662. /* Mollweide forward equations--mapping lat,long to x,y
  4663. ----------------------------------------------------*/
  4664. forward: function(p) {
  4665. /* Forward equations
  4666. -----------------*/
  4667. var lon=p.x;
  4668. var lat=p.y;
  4669. var delta_lon = Proj4js.common.adjust_lon(lon - this.long0);
  4670. var theta = lat;
  4671. var con = Proj4js.common.PI * Math.sin(lat);
  4672. /* Iterate using the Newton-Raphson method to find theta
  4673. -----------------------------------------------------*/
  4674. for (var i=0;true;i++) {
  4675. var delta_theta = -(theta + Math.sin(theta) - con)/ (1.0 + Math.cos(theta));
  4676. theta += delta_theta;
  4677. if (Math.abs(delta_theta) < Proj4js.common.EPSLN) break;
  4678. if (i >= 50) {
  4679. Proj4js.reportError("moll:Fwd:IterationError");
  4680. //return(241);
  4681. }
  4682. }
  4683. theta /= 2.0;
  4684. /* If the latitude is 90 deg, force the x coordinate to be "0 + false easting"
  4685. this is done here because of precision problems with "cos(theta)"
  4686. --------------------------------------------------------------------------*/
  4687. if (Proj4js.common.PI/2 - Math.abs(lat) < Proj4js.common.EPSLN) delta_lon =0;
  4688. var x = 0.900316316158 * this.a * delta_lon * Math.cos(theta) + this.x0;
  4689. var y = 1.4142135623731 * this.a * Math.sin(theta) + this.y0;
  4690. p.x=x;
  4691. p.y=y;
  4692. return p;
  4693. },
  4694. inverse: function(p){
  4695. var theta;
  4696. var arg;
  4697. /* Inverse equations
  4698. -----------------*/
  4699. p.x-= this.x0;
  4700. //~ p.y -= this.y0;
  4701. var arg = p.y / (1.4142135623731 * this.a);
  4702. /* Because of division by zero problems, 'arg' can not be 1.0. Therefore
  4703. a number very close to one is used instead.
  4704. -------------------------------------------------------------------*/
  4705. if(Math.abs(arg) > 0.999999999999) arg=0.999999999999;
  4706. var theta =Math.asin(arg);
  4707. var lon = Proj4js.common.adjust_lon(this.long0 + (p.x / (0.900316316158 * this.a * Math.cos(theta))));
  4708. if(lon < (-Proj4js.common.PI)) lon= -Proj4js.common.PI;
  4709. if(lon > Proj4js.common.PI) lon= Proj4js.common.PI;
  4710. arg = (2.0 * theta + Math.sin(2.0 * theta)) / Proj4js.common.PI;
  4711. if(Math.abs(arg) > 1.0)arg=1.0;
  4712. var lat = Math.asin(arg);
  4713. //return(OK);
  4714. p.x=lon;
  4715. p.y=lat;
  4716. return p;
  4717. }
  4718. };