Skip to content

HTTPS clone URL

Subversion checkout URL

You can clone with HTTPS or Subversion.

Download ZIP
Browse files

Merge branch 'master' into history

Conflicts:
	TODO.txt
	net/systemeD/halcyon/connection/Changeset.as
	net/systemeD/halcyon/connection/Connection.as
	net/systemeD/halcyon/connection/Entity.as
	net/systemeD/halcyon/connection/EntityCollection.as
	net/systemeD/halcyon/connection/Marker.as
	net/systemeD/halcyon/connection/Node.as
	net/systemeD/halcyon/connection/Relation.as
	net/systemeD/halcyon/connection/Way.as
	net/systemeD/halcyon/connection/XMLBaseConnection.as
	net/systemeD/potlatch2/TagViewer.mxml
	net/systemeD/potlatch2/controller/ControllerState.as
  • Loading branch information...
commit f478d8505372152b475201b0a01e2feff42b8227 2 parents 7158279 + aa899ca
@gravitystorm gravitystorm authored
Showing with 7,385 additions and 1,751 deletions.
  1. +5 −0 .gitignore
  2. +7 −2 TODO.txt
  3. +413 −0 com/gradoservice/proj4as/Datum.as
  4. +10 −0 com/gradoservice/proj4as/LICENCE.txt
  5. +157 −0 com/gradoservice/proj4as/Proj4as.as
  6. +288 −0 com/gradoservice/proj4as/ProjConstants.as
  7. +50 −0 com/gradoservice/proj4as/ProjPoint.as
  8. +282 −0 com/gradoservice/proj4as/ProjProjection.as
  9. +113 −0 com/gradoservice/proj4as/proj/AbstractProjProjection.as
  10. +14 −0 com/gradoservice/proj4as/proj/IProjection.as
  11. +145 −0 com/gradoservice/proj4as/proj/ProjAea.as
  12. +93 −0 com/gradoservice/proj4as/proj/ProjAeqd.as
  13. +55 −0 com/gradoservice/proj4as/proj/ProjEqc.as
  14. +156 −0 com/gradoservice/proj4as/proj/ProjEqdc.as
  15. +90 −0 com/gradoservice/proj4as/proj/ProjEqui.as
  16. +62 −0 com/gradoservice/proj4as/proj/ProjGauss.as
  17. +74 −0 com/gradoservice/proj4as/proj/ProjGstmerc.as
  18. +127 −0 com/gradoservice/proj4as/proj/ProjLaea.as
  19. +161 −0 com/gradoservice/proj4as/proj/ProjLcc.as
  20. +13 −0 com/gradoservice/proj4as/proj/ProjLonglat.as
  21. +120 −0 com/gradoservice/proj4as/proj/ProjMerc.as
  22. +83 −0 com/gradoservice/proj4as/proj/ProjMill.as
  23. +113 −0 com/gradoservice/proj4as/proj/ProjMoll.as
  24. +292 −0 com/gradoservice/proj4as/proj/ProjNzmg.as
  25. +299 −0 com/gradoservice/proj4as/proj/ProjOmerc.as
  26. +131 −0 com/gradoservice/proj4as/proj/ProjOrtho.as
  27. +71 −0 com/gradoservice/proj4as/proj/ProjParams.as
  28. +95 −0 com/gradoservice/proj4as/proj/ProjSinu.as
  29. +135 −0 com/gradoservice/proj4as/proj/ProjSoMerc.as
  30. +278 −0 com/gradoservice/proj4as/proj/ProjStere.as
  31. +74 −0 com/gradoservice/proj4as/proj/ProjSterea.as
  32. +154 −0 com/gradoservice/proj4as/proj/ProjTmerc.as
  33. +50 −0 com/gradoservice/proj4as/proj/ProjUtm.as
  34. +154 −0 com/gradoservice/proj4as/proj/ProjVandg.as
  35. +35 −0 embedded/search.svg
  36. BIN  embedded/warning.png
  37. +1 −1  halcyon_viewer.as
  38. +1 −0  l10n/locale/de_DE/p2_main.properties
  39. +1 −0  l10n/locale/en_GB/p2_main.properties
  40. +1 −0  l10n/locale/en_US/p2_main.properties
  41. +1 −0  l10n/locale/fr_FR/p2_main.properties
  42. +1 −0  l10n/locale/pl_PL/p2_main.properties
  43. +2 −1  l10n/map/LocalizationMap.mxml
  44. +1 −0  net/systemeD/controls/AutoComplete.as
  45. +42 −0 net/systemeD/controls/DataGridWarningField.as
  46. +39 −0 net/systemeD/controls/PromptingTextInputWarning.as
  47. +5 −3 net/systemeD/halcyon/Elastic.as
  48. +10 −4 net/systemeD/halcyon/EntityUI.as
  49. +81 −194 net/systemeD/halcyon/Map.as
  50. +202 −28 net/systemeD/halcyon/MapPaint.as
  51. +19 −19 net/systemeD/halcyon/MarkerUI.as
  52. +20 −19 net/systemeD/halcyon/NodeUI.as
  53. +1 −3 net/systemeD/halcyon/TileSet.as
  54. +0 −201 net/systemeD/halcyon/VectorLayer.as
  55. +25 −30 net/systemeD/halcyon/WayUI.as
  56. +12 −12 net/systemeD/halcyon/connection/AMFConnection.as
  57. +2 −2 net/systemeD/halcyon/connection/Changeset.as
  58. +75 −38 net/systemeD/halcyon/connection/Connection.as
  59. +35 −17 net/systemeD/halcyon/connection/Entity.as
  60. +4 −1 net/systemeD/halcyon/connection/EntityCollection.as
  61. +13 −0 net/systemeD/halcyon/connection/MainUndoStack.as
  62. +2 −2 net/systemeD/halcyon/connection/Marker.as
  63. +2 −5 net/systemeD/halcyon/connection/Node.as
  64. +6 −6 net/systemeD/halcyon/connection/OSMConnection.as
  65. +2 −2 net/systemeD/halcyon/connection/Relation.as
  66. +85 −0 net/systemeD/halcyon/connection/StatusFetcher.as
  67. +37 −19 net/systemeD/halcyon/connection/Trace.as
  68. +3 −3 net/systemeD/halcyon/connection/UndoableEntityAction.as
  69. +53 −5 net/systemeD/halcyon/connection/Way.as
  70. +163 −145 net/systemeD/halcyon/connection/XMLBaseConnection.as
  71. +26 −22 net/systemeD/halcyon/connection/XMLConnection.as
  72. +33 −4 net/systemeD/halcyon/connection/actions/AddNodeToWayAction.as
  73. +6 −4 net/systemeD/halcyon/connection/actions/CreatePOIAction.as
  74. +1 −1  net/systemeD/halcyon/connection/actions/DeleteNodeAction.as
  75. +2 −1  net/systemeD/halcyon/connection/actions/DeleteRelationAction.as
  76. +2 −2 net/systemeD/halcyon/connection/actions/DeleteWayAction.as
  77. +55 −52 net/systemeD/halcyon/connection/actions/MergeNodesAction.as
  78. +7 −3 net/systemeD/halcyon/connection/actions/MergeWaysAction.as
  79. +29 −20 net/systemeD/halcyon/connection/actions/RemoveNodeByIndexAction.as
  80. +16 −6 net/systemeD/halcyon/connection/actions/RemoveNodeFromWayAction.as
  81. +3 −3 net/systemeD/halcyon/connection/actions/SetTagAction.as
  82. +1 −1  net/systemeD/halcyon/connection/actions/SplitWayAction.as
  83. +1 −1  net/systemeD/halcyon/connection/actions/UnjoinNodeAction.as
  84. +1 −1  net/systemeD/halcyon/styleparser/Condition.as
  85. +69 −0 net/systemeD/halcyon/styleparser/RuleChain.as
  86. +20 −10 net/systemeD/halcyon/styleparser/RuleSet.as
  87. +1 −1  net/systemeD/halcyon/styleparser/ShapeStyle.as
  88. +62 −96 net/systemeD/halcyon/styleparser/StyleChooser.as
  89. +5 −5 net/systemeD/halcyon/styleparser/StyleList.as
  90. +1 −0  net/systemeD/potlatch2/BackgroundSelector.mxml
  91. +31 −25 net/systemeD/potlatch2/{BugLayer.as → BugConnection.as}
  92. +17 −18 net/systemeD/potlatch2/EditController.as
  93. +65 −0 net/systemeD/potlatch2/RelationLoaderPanel.mxml
  94. +10 −1 net/systemeD/potlatch2/RelationSelectPanel.mxml
  95. +4 −2 net/systemeD/potlatch2/TagGrid.mxml
  96. +46 −16 net/systemeD/potlatch2/TagViewer.mxml
  97. +1 −1  net/systemeD/potlatch2/Toolbox.mxml
  98. +70 −31 net/systemeD/potlatch2/VectorSourceDialog.mxml
  99. +32 −18 net/systemeD/potlatch2/Yahoo.as
  100. +17 −0 net/systemeD/potlatch2/collections/CollectionEvent.as
  101. +23 −23 net/systemeD/potlatch2/collections/Imagery.as
  102. +19 −9 net/systemeD/potlatch2/collections/Stylesheets.as
  103. +33 −13 net/systemeD/potlatch2/collections/VectorBackgrounds.as
  104. +53 −39 net/systemeD/potlatch2/controller/ControllerState.as
  105. +2 −2 net/systemeD/potlatch2/controller/DragSelection.as
  106. +13 −19 net/systemeD/potlatch2/controller/DragWayNode.as
  107. +87 −0 net/systemeD/potlatch2/controller/DrawQuadrilateral.as
  108. +20 −17 net/systemeD/potlatch2/controller/DrawWay.as
  109. +4 −2 net/systemeD/potlatch2/controller/NoSelection.as
  110. +78 −0 net/systemeD/potlatch2/controller/SelectArea.as
  111. +7 −8 net/systemeD/potlatch2/controller/SelectedMarker.as
  112. +23 −25 net/systemeD/potlatch2/controller/SelectedMultiple.as
  113. +17 −8 net/systemeD/potlatch2/controller/SelectedPOINode.as
  114. +1 −1  net/systemeD/potlatch2/controller/SelectedParallelWay.as
  115. +31 −27 net/systemeD/potlatch2/controller/SelectedWay.as
  116. +31 −35 net/systemeD/potlatch2/controller/SelectedWayNode.as
  117. +111 −0 net/systemeD/potlatch2/find/FindDialog.mxml
  118. +0 −1  net/systemeD/potlatch2/mapfeatures/Feature.as
  119. +26 −0 net/systemeD/potlatch2/mapfeatures/MapFeatures.as
  120. +2 −1  net/systemeD/potlatch2/mapfeatures/editors/FreeTextEditor.mxml
  121. +2 −2 net/systemeD/potlatch2/mapfeatures/editors/RouteIcon.mxml
  122. +1 −2  net/systemeD/potlatch2/mapfeatures/editors/TurnRestrictionEditor.mxml
  123. +5 −4 net/systemeD/potlatch2/mapfeatures/editors/TurnRestrictionIcon.mxml
  124. +3 −3 net/systemeD/potlatch2/mygpx/MyGpxDialog.mxml
  125. +19 −0 net/systemeD/potlatch2/options/OptionsDialog.mxml
  126. +54 −0 net/systemeD/potlatch2/panels/BackgroundPanel.mxml
  127. +9 −10 net/systemeD/potlatch2/panels/BugPanel.mxml
  128. +3 −4 net/systemeD/potlatch2/panels/MarkerPanel.mxml
  129. +41 −15 net/systemeD/potlatch2/save/OAuthPanel.mxml
  130. +26 −13 net/systemeD/potlatch2/save/SaveDialog.mxml
  131. +11 −10 net/systemeD/potlatch2/save/SaveManager.as
  132. +1 −1  net/systemeD/potlatch2/tools/Circularise.as
  133. +1 −1  net/systemeD/potlatch2/tools/Parallelise.as
  134. +1 −1  net/systemeD/potlatch2/tools/Quadrilateralise.as
  135. +4 −1 net/systemeD/potlatch2/tools/Simplify.as
  136. +50 −0 net/systemeD/potlatch2/utils/BikeShopConnection.as
  137. +7 −41 net/systemeD/potlatch2/utils/BikeShopLoader.as
  138. +7 −15 net/systemeD/potlatch2/utils/BugLoader.as
  139. +10 −9 net/systemeD/potlatch2/utils/GpxImporter.as
  140. +18 −20 net/systemeD/potlatch2/utils/Importer.as
  141. +19 −18 net/systemeD/potlatch2/utils/KmlImporter.as
  142. +7 −7 net/systemeD/potlatch2/utils/OsmImporter.as
  143. +46 −11 net/systemeD/potlatch2/utils/ShpImporter.as
  144. +36 −0 net/systemeD/potlatch2/utils/SnapshotConnection.as
  145. +27 −0 net/systemeD/potlatch2/utils/SnapshotLoader.as
  146. +30 −17 net/systemeD/potlatch2/utils/TrackLoader.as
  147. +114 −51 potlatch2.mxml
  148. BIN  resources/features/pois/transport_car_wash.n.24.png
  149. BIN  resources/icons/accommodation_blank.png
  150. BIN  resources/icons/shopping_garden_centre.n.16.png
  151. BIN  resources/icons/transport_car_wash.n.16.png
  152. +28 −5 resources/imagery.xml
  153. +2 −1  resources/map_features/buildings.xml
  154. +3 −3 resources/map_features/tourism.xml
  155. +23 −0 resources/map_features/transport.xml
  156. +20 −0 resources/ok_go.html
  157. +36 −22 resources/potlatch2.html
  158. +9 −6 resources/stylesheets/core_interactive.css
  159. +2 −2 resources/stylesheets/core_landuse.css
  160. +2 −1  resources/stylesheets/core_pois.css
  161. +5 −5 resources/stylesheets/core_relations.css
  162. +53 −55 resources/stylesheets/core_ways.css
  163. +7 −7 resources/stylesheets/enhanced.css
  164. +7 −7 resources/stylesheets/network.css
  165. +23 −35 resources/stylesheets/opencyclemap.css
  166. +8 −0 resources/stylesheets/potlatch.css
  167. +4 −8 resources/swfobject.js
  168. +2 −0  tests/src/AllHalcyonTests.as
  169. +36 −0 tests/src/net/systemeD/halcyon/connection/actions/SetTagActionTest.as
  170. +2 −1  version.as.template
View
5 .gitignore
@@ -2,13 +2,18 @@ build.properties
l10n/locale/bundles
version.as
halcyon.tmproj
+Potlatch2.as3proj
resources/locales
resources/*.swf
resources/*.cache
resources/docs
+resources/mapquest
/tests/bin/
/tests/report/
/generated
+
+bin/
+obj/
View
9 TODO.txt
@@ -1,10 +1,10 @@
-Potlatch 2: main outstanding issues
------------------------------------
+= Potlatch 2: main outstanding issues =
== Core geometry ==
* P1-style J (join)
* Doing a '-' to remove a point from a junction doesn't redraw the point on other ways
+* Circularise doesn't redraw the nodes on the selected way
== Vector background layers ==
@@ -33,6 +33,7 @@ Potlatch 2: main outstanding issues
** Keypress detection is very erratic, depending on focus - need to work out where events are going (Application.application?) and sense them there
* Failing to parse map_features should be an error state
+* Quadrilateralise should throw an AttentionEvent if it's too sharp to straighten
* Escape should rewind the entity to how it was before the current ControllerState. (Record a position in the undo stack when exiting a ControllerState, and escape would rewind to that)
* Custom imagery dialog fixes
* Ctrl-clicking two areas (one inside the other) should create a multipolygon
@@ -75,6 +76,10 @@ Potlatch 2: main outstanding issues
== history ==
* Think about what happens if a node, which used to be part of a way and isn't any more, changes. Does that put a fake "version" in?
+== other ==
+* Simplify.as shouldn't add an action to the global undo stack, since it's called from e.g. importing into other layers
+
+
Requested enhancements
----------------------
View
413 com/gradoservice/proj4as/Datum.as
@@ -0,0 +1,413 @@
+package com.gradoservice.proj4as
+{
+ import com.gradoservice.proj4as.proj.AbstractProjProjection;
+ import com.gradoservice.proj4as.ProjConstants;
+
+ public class Datum
+ {
+ public var datum_type:int;
+ public var a:Number;
+ public var b:Number;
+ public var es:Number;
+ public var ep2:Number;
+ public var datum_params:Array;
+ public var params:Array;
+
+ public function Datum(proj:ProjProjection)
+ {
+ this.datum_type = ProjConstants.PJD_WGS84; //default setting
+ if (proj.datumCode && proj.datumCode == 'none')
+ {
+ this.datum_type = ProjConstants.PJD_NODATUM;
+ }
+ if (proj && proj.datum_params)
+ {
+ for (var i:int=0; i<proj.datum_params.length; i++)
+ {
+ proj.datum_params[i]=parseFloat(proj.datum_params[i]);
+ }
+ if (proj.datum_params[0] != 0 || proj.datum_params[1] != 0 || proj.datum_params[2] != 0 )
+ {
+ this.datum_type = ProjConstants.PJD_3PARAM;
+ }
+ if (proj.datum_params.length > 3)
+ {
+ if (proj.datum_params[3] != 0 || proj.datum_params[4] != 0 ||
+ proj.datum_params[5] != 0 || proj.datum_params[6] != 0 )
+ {
+ this.datum_type = ProjConstants.PJD_7PARAM;
+ proj.datum_params[3] *= ProjConstants.SEC_TO_RAD;
+ proj.datum_params[4] *= ProjConstants.SEC_TO_RAD;
+ proj.datum_params[5] *= ProjConstants.SEC_TO_RAD;
+ proj.datum_params[6] = (proj.datum_params[6]/1000000.0) + 1.0;
+ }
+ }
+ }
+ if (proj)
+ {
+ this.a = proj.a; //datum object also uses these values
+ this.b = proj.b;
+ this.es = proj.es;
+ this.ep2 = proj.ep2;
+ this.datum_params = proj.datum_params;
+ }
+ }
+
+ /****************************************************************/
+ // cs_compare_datums()
+ // Returns 1 (TRUE) if the two datums match, otherwise 0 (FALSE).
+ public function compare_datums( dest:Datum ):Boolean
+ {
+ if( this.datum_type != dest.datum_type )
+ {
+ return false; // false, datums are not equal
+ }
+ else if( this.a != dest.a || Math.abs(this.es-dest.es) > 0.000000000050 )
+ {
+ // the tolerence for es is to ensure that GRS80 and WGS84
+ // are considered identical
+ return false;
+ }
+ else if( this.datum_type == ProjConstants.PJD_3PARAM )
+ {
+ return (this.datum_params[0] == dest.datum_params[0]
+ && this.datum_params[1] == dest.datum_params[1]
+ && this.datum_params[2] == dest.datum_params[2]);
+ } else if( this.datum_type == ProjConstants.PJD_7PARAM )
+ {
+ return (this.datum_params[0] == dest.datum_params[0]
+ && this.datum_params[1] == dest.datum_params[1]
+ && this.datum_params[2] == dest.datum_params[2]
+ && this.datum_params[3] == dest.datum_params[3]
+ && this.datum_params[4] == dest.datum_params[4]
+ && this.datum_params[5] == dest.datum_params[5]
+ && this.datum_params[6] == dest.datum_params[6]);
+ }
+ else if( this.datum_type == ProjConstants.PJD_GRIDSHIFT )
+ {
+ /*return strcmp( pj_param(this.params,"snadgrids").s,
+ pj_param(dest.params,"snadgrids").s ) == 0; */
+ return false;
+ } else
+ {
+ return true; // datums are equal
+ }
+ } // cs_compare_datums()
+
+
+ public function geodetic_to_geocentric(p:ProjPoint):int
+ {
+ var Longitude:Number = p.x;
+ var Latitude:Number = p.y;
+ var Height:Number = p.z ? p.z : 0; //Z value not always supplied
+ var X:Number; // output
+ var Y:Number;
+ var Z:Number;
+
+ var Error_Code:int=0; // GEOCENT_NO_ERROR;
+ var Rn:Number; /* Earth radius at location */
+ var Sin_Lat:Number; /* Math.sin(Latitude) */
+ var Sin2_Lat:Number; /* Square of Math.sin(Latitude) */
+ var Cos_Lat:Number; /* Math.cos(Latitude) */
+
+ /*
+ ** Don't blow up if Latitude is just a little out of the value
+ ** range as it may just be a rounding issue. Also removed longitude
+ ** test, it should be wrapped by Math.cos() and Math.sin(). NFW for PROJ.4, Sep/2001.
+ */
+ if( Latitude < -ProjConstants.HALF_PI && Latitude > -1.001 *ProjConstants.HALF_PI ) {
+ Latitude = -ProjConstants.HALF_PI;
+ } else if( Latitude > ProjConstants.HALF_PI && Latitude < 1.001 * ProjConstants.HALF_PI ) {
+ Latitude = ProjConstants.HALF_PI;
+ } else if ((Latitude < -ProjConstants.HALF_PI) || (Latitude > ProjConstants.HALF_PI)) {
+ /* Latitude out of range */
+ trace('geocent:lat out of range:'+Latitude);
+ return 0;
+ }
+
+ if (Longitude > ProjConstants.PI) {Longitude -= (2*ProjConstants.PI);}
+ Sin_Lat = Math.sin(Latitude);
+ Cos_Lat = Math.cos(Latitude);
+ Sin2_Lat = Sin_Lat * Sin_Lat;
+ Rn = this.a / (Math.sqrt(1.0e0 - this.es * Sin2_Lat));
+ X = (Rn + Height) * Cos_Lat * Math.cos(Longitude);
+ Y = (Rn + Height) * Cos_Lat * Math.sin(Longitude);
+ Z = ((Rn * (1 - this.es)) + Height) * Sin_Lat;
+
+ p.x = X;
+ p.y = Y;
+ p.z = Z;
+ return Error_Code;
+ } // cs_geodetic_to_geocentric()
+
+
+ public function geocentric_to_geodetic(p:ProjPoint):ProjPoint
+ {
+ /* local defintions and variables */
+ /* end-criterium of loop, accuracy of sin(Latitude) */
+ var genau:Number = 1.E-12;
+ var genau2:Number = (genau*genau);
+ var maxiter:int = 30;
+
+ var P:Number; /* distance between semi-minor axis and location */
+ var RR:Number; /* distance between center and location */
+ var CT:Number; /* sin of geocentric latitude */
+ var ST:Number; /* cos of geocentric latitude */
+ var RX:Number;
+ var RK:Number;
+ var RN:Number; /* Earth radius at location */
+ var CPHI0:Number; /* cos of start or old geodetic latitude in iterations */
+ var SPHI0:Number; /* sin of start or old geodetic latitude in iterations */
+ var CPHI:Number; /* cos of searched geodetic latitude */
+ var SPHI:Number; /* sin of searched geodetic latitude */
+ var SDPHI:Number; /* end-criterium: addition-theorem of sin(Latitude(iter)-Latitude(iter-1)) */
+ var At_Pole:Boolean; /* indicates location is in polar region */
+ var iter:Number; /* # of continous iteration, max. 30 is always enough (s.a.) */
+
+ var X:Number = p.x;
+ var Y:Number = p.y;
+ var Z:Number = p.z ? p.z : 0.0; //Z value not always supplied
+ var Longitude:Number;
+ var Latitude:Number;
+ var Height:Number;
+
+ At_Pole = false;
+ P = Math.sqrt(X*X+Y*Y);
+ RR = Math.sqrt(X*X+Y*Y+Z*Z);
+
+/* special cases for latitude and longitude */
+ if (P/this.a < genau)
+ {
+ /* special case, if P=0. (X=0., Y=0.) */
+ At_Pole = true;
+ Longitude = 0.0;
+/* if (X,Y,Z)=(0.,0.,0.) then Height becomes semi-minor axis
+ * of ellipsoid (=center of mass), Latitude becomes PI/2 */
+ if (RR/this.a < genau) {
+ Latitude = ProjConstants.HALF_PI;
+ Height = -this.b;
+ return null;
+ }
+ } else {
+/* ellipsoidal (geodetic) longitude
+ * interval: -PI < Longitude <= +PI */
+ Longitude=Math.atan2(Y,X);
+ }
+
+/* --------------------------------------------------------------
+ * Following iterative algorithm was developped by
+ * "Institut fьr Erdmessung", University of Hannover, July 1988.
+ * Internet: www.ife.uni-hannover.de
+ * Iterative computation of CPHI,SPHI and Height.
+ * Iteration of CPHI and SPHI to 10**-12 radian resp.
+ * 2*10**-7 arcsec.
+ * --------------------------------------------------------------
+ */
+ CT = Z/RR;
+ ST = P/RR;
+ RX = 1.0/Math.sqrt(1.0-this.es*(2.0-this.es)*ST*ST);
+ CPHI0 = ST*(1.0-this.es)*RX;
+ SPHI0 = CT*RX;
+ iter = 0;
+
+/* loop to find sin(Latitude) resp. Latitude
+ * until |sin(Latitude(iter)-Latitude(iter-1))| < genau */
+ do
+ {
+ iter++;
+ RN = this.a/Math.sqrt(1.0-this.es*SPHI0*SPHI0);
+
+/* ellipsoidal (geodetic) height */
+ Height = P*CPHI0+Z*SPHI0-RN*(1.0-this.es*SPHI0*SPHI0);
+
+ RK = this.es*RN/(RN+Height);
+ RX = 1.0/Math.sqrt(1.0-RK*(2.0-RK)*ST*ST);
+ CPHI = ST*(1.0-RK)*RX;
+ SPHI = CT*RX;
+ SDPHI = SPHI*CPHI0-CPHI*SPHI0;
+ CPHI0 = CPHI;
+ SPHI0 = SPHI;
+ }
+ while (SDPHI*SDPHI > genau2 && iter < maxiter);
+
+/* ellipsoidal (geodetic) latitude */
+ Latitude=Math.atan(SPHI/Math.abs(CPHI));
+
+ p.x = Longitude;
+ p.y = Latitude;
+ p.z = Height;
+ return p;
+ } // cs_geocentric_to_geodetic()
+
+
+ public function geocentric_to_geodetic_noniter(p:ProjPoint):ProjPoint
+ {
+ var X:Number = p.x;
+ var Y:Number = p.y;
+ var Z:Number = p.z ? p.z : 0; //Z value not always supplied
+ var Longitude:Number;
+ var Latitude:Number;
+ var Height:Number;
+
+ var W:Number; /* distance from Z axis */
+ var W2:Number; /* square of distance from Z axis */
+ var T0:Number; /* initial estimate of vertical component */
+ var T1:Number; /* corrected estimate of vertical component */
+ var S0:Number; /* initial estimate of horizontal component */
+ var S1:Number; /* corrected estimate of horizontal component */
+ var Sin_B0:Number; /* Math.sin(B0), B0 is estimate of Bowring aux variable */
+ var Sin3_B0:Number; /* cube of Math.sin(B0) */
+ var Cos_B0:Number; /* Math.cos(B0) */
+ var Sin_p1:Number; /* Math.sin(phi1), phi1 is estimated latitude */
+ var Cos_p1:Number; /* Math.cos(phi1) */
+ var Rn:Number; /* Earth radius at location */
+ var Sum:Number; /* numerator of Math.cos(phi1) */
+ var At_Pole:Boolean; /* indicates location is in polar region */
+
+ At_Pole = false;
+ if (X != 0.0)
+ {
+ Longitude = Math.atan2(Y,X);
+ }
+ else
+ {
+ if (Y > 0)
+ {
+ Longitude = ProjConstants.HALF_PI;
+ }
+ else if (Y < 0)
+ {
+ Longitude = -ProjConstants.HALF_PI;
+ }
+ else
+ {
+ At_Pole = true;
+ Longitude = 0.0;
+ if (Z > 0.0)
+ { /* north pole */
+ Latitude = ProjConstants.HALF_PI;
+ }
+ else if (Z < 0.0)
+ { /* south pole */
+ Latitude = -ProjConstants.HALF_PI;
+ }
+ else
+ { /* center of earth */
+ Latitude = ProjConstants.HALF_PI;
+ Height = -this.b;
+ return null;
+ }
+ }
+ }
+ W2 = X*X + Y*Y;
+ W = Math.sqrt(W2);
+ T0 = Z * ProjConstants.AD_C;
+ S0 = Math.sqrt(T0 * T0 + W2);
+ Sin_B0 = T0 / S0;
+ Cos_B0 = W / S0;
+ Sin3_B0 = Sin_B0 * Sin_B0 * Sin_B0;
+ T1 = Z + this.b * this.ep2 * Sin3_B0;
+ Sum = W - this.a * this.es * Cos_B0 * Cos_B0 * Cos_B0;
+ S1 = Math.sqrt(T1*T1 + Sum * Sum);
+ Sin_p1 = T1 / S1;
+ Cos_p1 = Sum / S1;
+ Rn = this.a / Math.sqrt(1.0 - this.es * Sin_p1 * Sin_p1);
+ if (Cos_p1 >= ProjConstants.COS_67P5)
+ {
+ Height = W / Cos_p1 - Rn;
+ }
+ else if (Cos_p1 <= -ProjConstants.COS_67P5)
+ {
+ Height = W / -Cos_p1 - Rn;
+ }
+ else
+ {
+ Height = Z / Sin_p1 + Rn * (this.es - 1.0);
+ }
+ if (At_Pole == false)
+ {
+ Latitude = Math.atan(Sin_p1 / Cos_p1);
+ }
+
+ p.x = Longitude;
+ p.y = Latitude;
+ p.z = Height;
+ return p;
+ } // geocentric_to_geodetic_noniter()
+
+ /****************************************************************/
+ // pj_geocentic_to_wgs84( p )
+ // p = point to transform in geocentric coordinates (x,y,z)
+ public function geocentric_to_wgs84( p:ProjPoint ):void
+ {
+
+ if( this.datum_type == ProjConstants.PJD_3PARAM )
+ {
+ // if( x[io] == HUGE_VAL )
+ // continue;
+ p.x += this.datum_params[0];
+ p.y += this.datum_params[1];
+ p.z += this.datum_params[2];
+
+ }
+ else if (this.datum_type == ProjConstants.PJD_7PARAM)
+ {
+ var Dx_BF:Number =this.datum_params[0];
+ var Dy_BF:Number =this.datum_params[1];
+ var Dz_BF:Number =this.datum_params[2];
+ var Rx_BF:Number =this.datum_params[3];
+ var Ry_BF:Number =this.datum_params[4];
+ var Rz_BF:Number =this.datum_params[5];
+ var M_BF:Number =this.datum_params[6];
+ // if( x[io] == HUGE_VAL )
+ // continue;
+ var x_out:Number = M_BF*( p.x - Rz_BF*p.y + Ry_BF*p.z) + Dx_BF;
+ var y_out:Number = M_BF*( Rz_BF*p.x + p.y - Rx_BF*p.z) + Dy_BF;
+ var z_out:Number = M_BF*(-Ry_BF*p.x + Rx_BF*p.y + p.z) + Dz_BF;
+ p.x = x_out;
+ p.y = y_out;
+ p.z = z_out;
+ }
+ } // cs_geocentric_to_wgs84
+
+ /****************************************************************/
+ // pj_geocentic_from_wgs84()
+ // coordinate system definition,
+ // point to transform in geocentric coordinates (x,y,z)
+ public function geocentric_from_wgs84( p:ProjPoint ):void
+ {
+
+ if( this.datum_type == ProjConstants.PJD_3PARAM )
+ {
+ //if( x[io] == HUGE_VAL )
+ // continue;
+ p.x -= this.datum_params[0];
+ p.y -= this.datum_params[1];
+ p.z -= this.datum_params[2];
+
+ }
+ else if (this.datum_type == ProjConstants.PJD_7PARAM)
+ {
+ var Dx_BF:Number =this.datum_params[0];
+ var Dy_BF:Number =this.datum_params[1];
+ var Dz_BF:Number =this.datum_params[2];
+ var Rx_BF:Number =this.datum_params[3];
+ var Ry_BF:Number =this.datum_params[4];
+ var Rz_BF:Number =this.datum_params[5];
+ var M_BF:Number =this.datum_params[6];
+ var x_tmp:Number = (p.x - Dx_BF) / M_BF;
+ var y_tmp:Number = (p.y - Dy_BF) / M_BF;
+ var z_tmp:Number = (p.z - Dz_BF) / M_BF;
+ //if( x[io] == HUGE_VAL )
+ // continue;
+
+ p.x = x_tmp + Rz_BF*y_tmp - Ry_BF*z_tmp;
+ p.y = -Rz_BF*x_tmp + y_tmp + Rx_BF*z_tmp;
+ p.z = Ry_BF*x_tmp - Rx_BF*y_tmp + z_tmp;
+ } //cs_geocentric_from_wgs84()
+ }
+
+
+
+ }
+}
View
10 com/gradoservice/proj4as/LICENCE.txt
@@ -0,0 +1,10 @@
+Copyright (c) German Osin, 2009
+All rights reserved.
+[see http://groups.google.com/group/openscales-dev/msg/425f736fd9d07884 for licence declaration]
+
+Redistribution and use in source and binary forms, with or without modification, are permitted provided that the following conditions are met:
+
+Redistributions of source code must retain the above copyright notice, this list of conditions and the following disclaimer.
+Redistributions in binary form must reproduce the above copyright notice, this list of conditions and the following disclaimer in the documentation and/or other materials provided with the distribution.
+THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS "AS IS" AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT HOLDER OR CONTRIBUTORS BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.
+
View
157 com/gradoservice/proj4as/Proj4as.as
@@ -0,0 +1,157 @@
+package com.gradoservice.proj4as
+{
+ import com.gradoservice.proj4as.proj.AbstractProjProjection;
+
+ public class Proj4as
+ {
+
+ static public const defaultDatum:String = 'WGS84';
+ static public const WGS84:ProjProjection = new ProjProjection('WGS84');
+
+
+ public function Proj4as()
+ {
+ }
+
+ public function transform(source:ProjProjection, dest:ProjProjection, point:ProjPoint):ProjPoint
+ {
+
+ if (source==null || dest==null || point==null)
+ {
+ trace("Parametrs not created!");
+ return null;
+ }
+
+ if (!source.readyToUse || !dest.readyToUse)
+ {
+ trace("Proj4js initialization for "+source.srsCode+" not yet complete");
+ return point;
+ }
+
+ // Workaround for Spherical Mercator
+ if ((source.srsProjNumber =="900913" && dest.datumCode != "WGS84") ||
+ (dest.srsProjNumber == "900913" && source.datumCode != "WGS84")) {
+ var wgs84:ProjProjection = WGS84;
+ this.transform(source, wgs84, point);
+ source = wgs84;
+ }
+
+ // Transform source points to long/lat, if they aren't already.
+ if ( source.projName=="longlat") {
+ point.x *= ProjConstants.D2R; // convert degrees to radians
+ point.y *= ProjConstants.D2R;
+ } else {
+ if (source.to_meter) {
+ point.x *= source.to_meter;
+ point.y *= source.to_meter;
+ }
+ source.inverse(point); // Convert Cartesian to longlat
+ }
+
+ // Adjust for the prime meridian if necessary
+ if (source.from_greenwich) {
+ point.x += source.from_greenwich;
+ }
+
+ // Convert datums if needed, and if possible.
+ point = this.datum_transform( source.datum, dest.datum, point );
+
+ // Adjust for the prime meridian if necessary
+ if (dest.from_greenwich) {
+ point.x -= dest.from_greenwich;
+ }
+
+ if( dest.projName=="longlat" ) {
+ // convert radians to decimal degrees
+ point.x *= ProjConstants.R2D;
+ point.y *= ProjConstants.R2D;
+ } else { // else project
+ dest.forward(point);
+ if (dest.to_meter) {
+ point.x /= dest.to_meter;
+ point.y /= dest.to_meter;
+ }
+ }
+ return point;
+ }
+
+
+ public function datum_transform( source:Datum, dest:Datum, point:ProjPoint ):ProjPoint
+ {
+
+ // Short cut if the datums are identical.
+ if( source.compare_datums( dest ) ) {
+ return point; // in this case, zero is sucess,
+ // whereas cs_compare_datums returns 1 to indicate TRUE
+ // confusing, should fix this
+ }
+
+ // Explicitly skip datum transform by setting 'datum=none' as parameter for either source or dest
+ if( source.datum_type == ProjConstants.PJD_NODATUM
+ || dest.datum_type == ProjConstants.PJD_NODATUM) {
+ return point;
+ }
+
+ // If this datum requires grid shifts, then apply it to geodetic coordinates.
+ if( source.datum_type == ProjConstants.PJD_GRIDSHIFT )
+ {
+ trace("ERROR: Grid shift transformations are not implemented yet.");
+ /*
+ pj_apply_gridshift( pj_param(source.params,"snadgrids").s, 0,
+ point_count, point_offset, x, y, z );
+ CHECK_RETURN;
+
+ src_a = SRS_WGS84_SEMIMAJOR;
+ src_es = 0.006694379990;
+ */
+ }
+
+ if( dest.datum_type == ProjConstants.PJD_GRIDSHIFT )
+ {
+ trace("ERROR: Grid shift transformations are not implemented yet.");
+ /*
+ dst_a = ;
+ dst_es = 0.006694379990;
+ */
+ }
+
+ // Do we need to go through geocentric coordinates?
+ if( source.es != dest.es || source.a != dest.a
+ || source.datum_type == ProjConstants.PJD_3PARAM
+ || source.datum_type == ProjConstants.PJD_7PARAM
+ || dest.datum_type == ProjConstants.PJD_3PARAM
+ || dest.datum_type == ProjConstants.PJD_7PARAM)
+ {
+
+ // Convert to geocentric coordinates.
+ source.geodetic_to_geocentric( point );
+ // CHECK_RETURN;
+
+ // Convert between datums
+ if( source.datum_type == ProjConstants.PJD_3PARAM || source.datum_type == ProjConstants.PJD_7PARAM ) {
+ source.geocentric_to_wgs84(point);
+ // CHECK_RETURN;
+ }
+
+ if( dest.datum_type == ProjConstants.PJD_3PARAM || dest.datum_type == ProjConstants.PJD_7PARAM ) {
+ dest.geocentric_from_wgs84(point);
+ // CHECK_RETURN;
+ }
+
+ // Convert back to geodetic coordinates
+ dest.geocentric_to_geodetic( point );
+ // CHECK_RETURN;
+ }
+
+ // Apply grid shift to destination if required
+ if( dest.datum_type == ProjConstants.PJD_GRIDSHIFT )
+ {
+ trace("ERROR: Grid shift transformations are not implemented yet.");
+ // pj_apply_gridshift( pj_param(dest.params,"snadgrids").s, 1, point);
+ // CHECK_RETURN;
+ }
+ return point;
+ }
+
+ }
+}
View
288 com/gradoservice/proj4as/ProjConstants.as
@@ -0,0 +1,288 @@
+package com.gradoservice.proj4as
+{
+ public class ProjConstants
+ {
+
+ static public const PI:Number=3.141592653589793238; //Math.PI,
+ static public const HALF_PI:Number=1.570796326794896619; //Math.PI*0.5,
+ static public const TWO_PI:Number=6.283185307179586477; //Math.PI*2,
+ static public const FORTPI:Number=0.78539816339744833;
+ static public const R2D:Number=57.29577951308232088;
+ static public const D2R:Number=0.01745329251994329577;
+ static public const SEC_TO_RAD:Number=4.84813681109535993589914102357e-6; /* SEC_TO_RAD = Pi/180/3600 */
+ static public const EPSLN:Number=1.0e-10;
+ static public const MAX_ITER:Number=20;
+ // following constants from geocent.c
+ static public const COS_67P5:Number=0.38268343236508977; /* cosine of 67.5 degrees */
+ static public const AD_C:Number=1.0026000; /* Toms region 1 constant */
+
+ /* datum_type values */
+ static public const PJD_UNKNOWN:int=0;
+ static public const PJD_3PARAM:int=1;
+ static public const PJD_7PARAM:int=2;
+ static public const PJD_GRIDSHIFT:int=3;
+ static public const PJD_WGS84:int=4; // WGS84 or equivalent
+ static public const PJD_NODATUM:int=5; // WGS84 or equivalent
+ static public const SRS_WGS84_SEMIMAJOR:int=6378137; // only used in grid shift transforms
+
+ // ellipoid pj_set_ell.c
+ static public const SIXTH :Number=0.1666666666666666667; /* 1/6 */
+ static public const RA4:Number=0.04722222222222222222; /* 17/360 */
+ static public const RA6:Number=0.02215608465608465608; /* 67/3024 */
+ static public const RV4:Number=0.06944444444444444444; /* 5/72 */
+ static public const RV6:Number=0.04243827160493827160; /* 55/1296 */
+
+
+
+ static public const PrimeMeridian:Object = {
+ "greenwich": 0.0, //"0dE",
+ "lisbon": -9.131906111111, //"9d07'54.862\"W",
+ "paris": 2.337229166667, //"2d20'14.025\"E",
+ "bogota": -74.080916666667, //"74d04'51.3\"W",
+ "madrid": -3.687938888889, //"3d41'16.58\"W",
+ "rome": 12.452333333333, //"12d27'8.4\"E",
+ "bern": 7.439583333333, //"7d26'22.5\"E",
+ "jakarta": 106.807719444444, //"106d48'27.79\"E",
+ "ferro": -17.666666666667, //"17d40'W",
+ "brussels": 4.367975, //"4d22'4.71\"E",
+ "stockholm": 18.058277777778, //"18d3'29.8\"E",
+ "athens": 23.7163375, //"23d42'58.815\"E",
+ "oslo": 10.722916666667 //"10d43'22.5\"E"
+ };
+
+ static public const Ellipsoid:Object = {
+ "MERIT": {a:6378137.0, rf:298.257, ellipseName:"MERIT 1983"},
+ "SGS85": {a:6378136.0, rf:298.257, ellipseName:"Soviet Geodetic System 85"},
+ "GRS80": {a:6378137.0, rf:298.257222101, ellipseName:"GRS 1980(IUGG, 1980)"},
+ "IAU76": {a:6378140.0, rf:298.257, ellipseName:"IAU 1976"},
+ "airy": {a:6377563.396, b:6356256.910, ellipseName:"Airy 1830"},
+ "APL4.": {a:6378137, rf:298.25, ellipseName:"Appl. Physics. 1965"},
+ "NWL9D": {a:6378145.0, rf:298.25, ellipseName:"Naval Weapons Lab., 1965"},
+ "mod_airy": {a:6377340.189, b:6356034.446, ellipseName:"Modified Airy"},
+ "andrae": {a:6377104.43, rf:300.0, ellipseName:"Andrae 1876 (Den., Iclnd.)"},
+ "aust_SA": {a:6378160.0, rf:298.25, ellipseName:"Australian Natl & S. Amer. 1969"},
+ "GRS67": {a:6378160.0, rf:298.2471674270, ellipseName:"GRS 67(IUGG 1967)"},
+ "bessel": {a:6377397.155, rf:299.1528128, ellipseName:"Bessel 1841"},
+ "bess_nam": {a:6377483.865, rf:299.1528128, ellipseName:"Bessel 1841 (Namibia)"},
+ "clrk66": {a:6378206.4, b:6356583.8, ellipseName:"Clarke 1866"},
+ "clrk80": {a:6378249.145, rf:293.4663, ellipseName:"Clarke 1880 mod."},
+ "CPM": {a:6375738.7, rf:334.29, ellipseName:"Comm. des Poids et Mesures 1799"},
+ "delmbr": {a:6376428.0, rf:311.5, ellipseName:"Delambre 1810 (Belgium)"},
+ "engelis": {a:6378136.05, rf:298.2566, ellipseName:"Engelis 1985"},
+ "evrst30": {a:6377276.345, rf:300.8017, ellipseName:"Everest 1830"},
+ "evrst48": {a:6377304.063, rf:300.8017, ellipseName:"Everest 1948"},
+ "evrst56": {a:6377301.243, rf:300.8017, ellipseName:"Everest 1956"},
+ "evrst69": {a:6377295.664, rf:300.8017, ellipseName:"Everest 1969"},
+ "evrstSS": {a:6377298.556, rf:300.8017, ellipseName:"Everest (Sabah & Sarawak)"},
+ "fschr60": {a:6378166.0, rf:298.3, ellipseName:"Fischer (Mercury Datum) 1960"},
+ "fschr60m": {a:6378155.0, rf:298.3, ellipseName:"Fischer 1960"},
+ "fschr68": {a:6378150.0, rf:298.3, ellipseName:"Fischer 1968"},
+ "helmert": {a:6378200.0, rf:298.3, ellipseName:"Helmert 1906"},
+ "hough": {a:6378270.0, rf:297.0, ellipseName:"Hough"},
+ "intl": {a:6378388.0, rf:297.0, ellipseName:"International 1909 (Hayford)"},
+ "kaula": {a:6378163.0, rf:298.24, ellipseName:"Kaula 1961"},
+ "lerch": {a:6378139.0, rf:298.257, ellipseName:"Lerch 1979"},
+ "mprts": {a:6397300.0, rf:191.0, ellipseName:"Maupertius 1738"},
+ "new_intl": {a:6378157.5, b:6356772.2, ellipseName:"New International 1967"},
+ "plessis": {a:6376523.0, rf:6355863.0, ellipseName:"Plessis 1817 (France)"},
+ "krass": {a:6378245.0, rf:298.3, ellipseName:"Krassovsky, 1942"},
+ "SEasia": {a:6378155.0, b:6356773.3205, ellipseName:"Southeast Asia"},
+ "walbeck": {a:6376896.0, b:6355834.8467, ellipseName:"Walbeck"},
+ "WGS60": {a:6378165.0, rf:298.3, ellipseName:"WGS 60"},
+ "WGS66": {a:6378145.0, rf:298.25, ellipseName:"WGS 66"},
+ "WGS72": {a:6378135.0, rf:298.26, ellipseName:"WGS 72"},
+ "WGS84": {a:6378137.0, rf:298.257223563, ellipseName:"WGS 84"},
+ "sphere": {a:6370997.0, b:6370997.0, ellipseName:"Normal Sphere (r=6370997)"}
+};
+
+ static public const Datum:Object = {
+ "WGS84": {towgs84: "0,0,0", ellipse: "WGS84", datumName: "WGS84"},
+ "GGRS87": {towgs84: "-199.87,74.79,246.62", ellipse: "GRS80", datumName: "Greek_Geodetic_Reference_System_1987"},
+ "NAD83": {towgs84: "0,0,0", ellipse: "GRS80", datumName: "North_American_Datum_1983"},
+ "NAD27": {nadgrids: "@conus,@alaska,@ntv2_0.gsb,@ntv1_can.dat", ellipse: "clrk66", datumName: "North_American_Datum_1927"},
+ "potsdam": {towgs84: "606.0,23.0,413.0", ellipse: "bessel", datumName: "Potsdam Rauenberg 1950 DHDN"},
+ "carthage": {towgs84: "-263.0,6.0,431.0", ellipse: "clark80", datumName: "Carthage 1934 Tunisia"},
+ "hermannskogel": {towgs84: "653.0,-212.0,449.0", ellipse: "bessel", datumName: "Hermannskogel"},
+ "ire65": {towgs84: "482.530,-130.596,564.557,-1.042,-0.214,-0.631,8.15", ellipse: "mod_airy", datumName: "Ireland 1965"},
+ "nzgd49": {towgs84: "59.47,-5.04,187.44,0.47,-0.1,1.024,-4.5993", ellipse: "intl", datumName: "New Zealand Geodetic Datum 1949"},
+ "OSGB36": {towgs84: "446.448,-125.157,542.060,0.1502,0.2470,0.8421,-20.4894", ellipse: "airy", datumName: "Airy 1830"}
+};
+
+
+
+ public function ProjConstants()
+ {
+ }
+
+
+ // Function to compute the constant small m which is the radius of
+ // a parallel of latitude, phi, divided by the semimajor axis.
+ // -----------------------------------------------------------------
+ static public function msfnz (eccent:Number, sinphi:Number, cosphi:Number):Number
+ {
+ var con:Number = eccent * sinphi;
+ return cosphi/(Math.sqrt(1.0 - con * con));
+ }
+
+ // Function to compute the constant small t for use in the forward
+ // computations in the Lambert Conformal Conic and the Polar
+ // Stereographic projections.
+ // -----------------------------------------------------------------
+ static public function tsfnz(eccent:Number, phi:Number, sinphi:Number):Number
+ {
+ var con:Number = eccent * sinphi;
+ var com:Number = 0.5 * eccent;
+ con = Math.pow(((1.0 - con) / (1.0 + con)), com);
+ return (Math.tan(0.5 * (ProjConstants.HALF_PI - phi))/con);
+ }
+
+ // Function to compute the latitude angle, phi2, for the inverse of the
+ // Lambert Conformal Conic and Polar Stereographic projections.
+ // ----------------------------------------------------------------
+ static public function phi2z(eccent:Number, ts:Number):Number
+ {
+ var eccnth:Number = .5 * eccent;
+ var con:Number =0;
+ var dphi:Number =0;
+ var phi:Number = ProjConstants.HALF_PI - 2 * Math.atan(ts);
+ for (var i:int = 0; i <= 15; i++) {
+ con = eccent * Math.sin(phi);
+ dphi = ProjConstants.HALF_PI - 2 * Math.atan(ts *(Math.pow(((1.0 - con)/(1.0 + con)),eccnth))) - phi;
+ phi += dphi;
+ if (Math.abs(dphi) <= .0000000001) return phi;
+ }
+ trace("phi2z has NoConvergence");
+ return -9999;
+ }
+
+ /* Function to compute constant small q which is the radius of a
+ parallel of latitude, phi, divided by the semimajor axis.
+ ------------------------------------------------------------*/
+ static public function qsfnz(eccent:Number,sinphi:Number,cosphi:Number):Number
+ {
+ var con:Number = 0;
+ if (eccent > 1.0e-7) {
+ con = eccent * sinphi;
+ return (( 1.0- eccent * eccent) * (sinphi /(1.0 - con * con) - (.5/eccent)*Math.log((1.0 - con)/(1.0 + con))));
+ } else {
+ return 2.0 * sinphi;
+ }
+ }
+
+ /* Function to eliminate roundoff errors in asin
+ ----------------------------------------------*/
+ static public function asinz(x:Number):Number
+ {
+ if (Math.abs(x)>1.0) {
+ x=(x>1.0)?1.0:-1.0;
+ }
+ return Math.asin(x);
+ }
+
+ // following functions from gctpc cproj.c for transverse mercator projections
+ static public function e0fn(x:Number):Number {return(1.0-0.25*x*(1.0+x/16.0*(3.0+1.25*x)));}
+ static public function e1fn(x:Number):Number {return(0.375*x*(1.0+0.25*x*(1.0+0.46875*x)));}
+ static public function e2fn(x:Number):Number {return(0.05859375*x*x*(1.0+0.75*x));}
+ static public function e3fn(x:Number):Number {return(x*x*x*(35.0/3072.0));}
+ static public function mlfn(e0:Number,e1:Number,e2:Number,e3:Number,phi:Number):Number {return(e0*phi-e1*Math.sin(2.0*phi)+e2*Math.sin(4.0*phi)-e3*Math.sin(6.0*phi));}
+
+ static public function srat(esinp:Number, exp:Number):Number
+ {
+ return(Math.pow((1.0-esinp)/(1.0+esinp), exp));
+ }
+
+// Function to return the sign of an argument
+ static public function sign(x:Number):Number { if (x < 0.0) return(-1); else return(1);}
+
+// Function to adjust longitude to -180 to 180; input in radians
+ static public function adjust_lon(x:Number):Number {
+ x = (Math.abs(x) < ProjConstants.PI) ? x: (x - (ProjConstants.sign(x)*ProjConstants.TWO_PI) );
+ return x;
+ }
+
+// IGNF - DGR : algorithms used by IGN France
+
+// Function to adjust latitude to -90 to 90; input in radians
+ static public function adjust_lat(x:Number):Number {
+ x= (Math.abs(x) < ProjConstants.HALF_PI) ? x: (x - (ProjConstants.sign(x)*ProjConstants.PI) );
+ return x;
+ }
+
+// Latitude Isometrique - close to tsfnz ...
+ static public function latiso(eccent:Number, phi:Number, sinphi:Number):Number
+ {
+ if (Math.abs(phi) > ProjConstants.HALF_PI) return +Number.NaN;
+ if (phi==ProjConstants.HALF_PI) return Number.POSITIVE_INFINITY;
+ if (phi==-1.0*ProjConstants.HALF_PI) return -1.0*Number.POSITIVE_INFINITY;
+
+ var con:Number= eccent*sinphi;
+ return Math.log(Math.tan((ProjConstants.HALF_PI+phi)/2.0))+eccent*Math.log((1.0-con)/(1.0+con))/2.0;
+ }
+
+ static public function fL(x:Number,L:Number):Number {
+ return 2.0*Math.atan(x*Math.exp(L)) - ProjConstants.HALF_PI;
+ }
+
+// Inverse Latitude Isometrique - close to ph2z
+ static public function invlatiso(eccent:Number, ts:Number):Number {
+ var phi:Number= ProjConstants.fL(1.0,ts);
+ var Iphi:Number= 0.0;
+ var con:Number= 0.0;
+ do {
+ Iphi= phi;
+ con= eccent*Math.sin(Iphi);
+ phi= ProjConstants.fL(Math.exp(eccent*Math.log((1.0+con)/(1.0-con))/2.0),ts)
+ } while (Math.abs(phi-Iphi)>1.0e-12);
+ return phi;
+ }
+
+// Needed for Gauss Laborde
+// Original: Denis Makarov (info@binarythings.com)
+// Web Site: http://www.binarythings.com
+ static public function sinh(x:Number):Number
+ {
+ var r:Number= Math.exp(x);
+ r= (r-1.0/r)/2.0;
+ return r;
+ }
+
+ static public function cosh(x:Number):Number
+ {
+ var r:Number= Math.exp(x);
+ r= (r+1.0/r)/2.0;
+ return r;
+ }
+
+ static public function tanh(x:Number):Number
+ {
+ var r:Number= Math.exp(x);
+ r= (r-1.0/r)/(r+1.0/r);
+ return r;
+ }
+
+ static public function asinh(x:Number):Number
+ {
+ var s:Number= (x>= 0? 1.0:-1.0);
+ return s*(Math.log( Math.abs(x) + Math.sqrt(x*x+1.0) ));
+ }
+
+ static public function acosh(x:Number):Number
+ {
+ return 2.0*Math.log(Math.sqrt((x+1.0)/2.0) + Math.sqrt((x-1.0)/2.0));
+ }
+
+ static public function atanh(x:Number):Number
+ {
+ return Math.log((x-1.0)/(x+1.0))/2.0;
+ }
+
+// Grande Normale
+ static public function gN(a:Number,e:Number,sinphi:Number):Number
+ {
+ var temp:Number= e*sinphi;
+ return a/Math.sqrt(1.0 - temp*temp);
+ }
+
+
+ }
+}
View
50 com/gradoservice/proj4as/ProjPoint.as
@@ -0,0 +1,50 @@
+package com.gradoservice.proj4as
+{
+ public class ProjPoint
+ {
+ public var x:Number;
+ public var y:Number;
+ public var z:Number;
+
+ public function ProjPoint(x:Number,y:Number,z:Number)
+ {
+ this.x = x;
+ this.y = y;
+ this.z = z;
+ }
+
+ public function clone():ProjPoint
+ {
+ return new ProjPoint(this.x, this.y, this.z);
+ }
+
+ /**
+ * APIMethod: toString
+ * Return a readable string version of the point
+ *
+ * Return:
+ * {String} String representation of Proj4js.Point object.
+ * (ex. <i>"x=5,y=42"</i>)
+ */
+ public function toString():String
+ {
+ return ("x=" + this.x + ",y=" + this.y);
+ }
+
+ /**
+ * APIMethod: toShortString
+ * Return a short string version of the point.
+ *
+ * Return:
+ * {String} Shortened String representation of Proj4js.Point object.
+ * (ex. <i>"5, 42"</i>)
+ */
+ public function toShortString ():String
+ {
+ return (this.x + ", " + this.y);
+ }
+
+
+
+ }
+}
View
282 com/gradoservice/proj4as/ProjProjection.as
@@ -0,0 +1,282 @@
+package com.gradoservice.proj4as
+{
+ import com.gradoservice.proj4as.proj.*;
+
+ public class ProjProjection
+ {
+ /**
+ * Property: readyToUse
+ * Flag to indicate if initialization is complete for this Proj object
+ */
+ public var readyToUse:Boolean = false;
+
+ /**
+ * Property: title
+ * The title to describe the projection
+ */
+ protected var projParams:ProjParams = new ProjParams();
+
+ static public const defs:Object = {
+ 'EPSG:900913': "+title=Google Mercator EPSG:900913 +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",
+ 'WGS84': "+title=long/lat:WGS84 +proj=longlat +ellps=WGS84 +datum=WGS84 +units=degrees",
+ 'EPSG:4326': "+title=long/lat:WGS84 +proj=longlat +a=6378137.0 +b=6356752.31424518 +ellps=WGS84 +datum=WGS84 +units=degrees",
+ 'EPSG:4269': "+title=long/lat:NAD83 +proj=longlat +a=6378137.0 +b=6356752.31414036 +ellps=GRS80 +datum=NAD83 +units=degrees",
+ 'EPSG:32639': "+title=WGS 84 / UTM zone 39N +proj=utm +zone=39 +ellps=WGS84 +datum=WGS84 +units=m +no_defs",
+ 'EPSG:27700': "+proj=tmerc +lat_0=49 +lon_0=-2 +k=0.9996012717 +x_0=400000 +y_0=-100000 +ellps=airy +datum=OSGB36 +units=m +no_defs"
+ }
+
+
+
+ protected var proj:IProjection;
+
+ public function get srsCode():String
+ {
+ return projParams.srsCode;
+ }
+
+ public function get srsProjNumber():String
+ {
+ return projParams.srsProjNumber;
+ }
+
+ public function get projName():String
+ {
+ return projParams.projName;
+ }
+
+ public function get datum():Datum
+ {
+ return projParams.datum;
+ }
+
+ public function get datumCode():String
+ {
+ return projParams.datumCode;
+ }
+
+ public function get from_greenwich():Number
+ {
+ return projParams.from_greenwich;
+ }
+
+ public function get to_meter():Number
+ {
+ return projParams.to_meter;
+ }
+
+ public function get a():Number
+ {
+ return projParams.a;
+ }
+
+ public function get b():Number
+ {
+ return projParams.b;
+ }
+
+ public function get ep2():Number
+ {
+ return projParams.ep2;
+ }
+
+ public function get es():Number
+ {
+ return projParams.es;
+ }
+
+ public function get datum_params():Array
+ {
+ return projParams.datum_params;
+ }
+
+ public function ProjProjection(srsCode:String)
+ {
+ this.projParams.srsCode = srsCode.toUpperCase();
+
+ if (this.projParams.srsCode.indexOf("EPSG") == 0) {
+ this.projParams.srsAuth = 'epsg';
+ this.projParams.srsProjNumber = this.projParams.srsCode.substring(5);
+ // DGR 2007-11-20 : authority IGNF
+ } else if (this.projParams.srsCode.indexOf("IGNF") == 0) {
+ this.projParams.srsAuth = 'IGNF';
+ this.projParams.srsProjNumber = this.projParams.srsCode.substring(5);
+ // DGR 2008-06-19 : pseudo-authority CRS for WMS
+ } else if (this.projParams.srsCode.indexOf("CRS") == 0) {
+ this.projParams.srsAuth = 'CRS';
+ this.projParams.srsProjNumber = this.projParams.srsCode.substring(4);
+ } else {
+ this.projParams.srsAuth = '';
+ this.projParams.srsProjNumber = this.projParams.srsCode;
+ }
+ this.loadProjDefinition();
+ }
+
+ private function loadProjDefinition():void
+ {
+ if (this.srsCode!=null && ProjProjection.defs[this.srsCode]!=null)
+ {
+ this.parseDef(ProjProjection.defs[this.projParams.srsCode]);
+ this.initTransforms();
+ }
+ }
+
+ protected function initTransforms():void
+ {
+ switch (this.projParams.projName)
+ {
+ case "aea": this.proj = new ProjAea(this.projParams); break;
+ case "aeqd": this.proj = new ProjAeqd(this.projParams); break;
+ case "eqc": this.proj = new ProjEqc(this.projParams); break;
+ case "eqdc": this.proj = new ProjEqdc(this.projParams); break;
+ case "equi": this.proj = new ProjEqui(this.projParams); break;
+ case "gauss": this.proj = new ProjGauss(this.projParams); break;
+ case "gstmerc": this.proj = new ProjGstmerc(this.projParams); break;
+ case "laea": this.proj = new ProjLaea(this.projParams); break;
+ case "lcc": this.proj = new ProjLcc(this.projParams); break;
+ case "longlat": this.proj = new ProjLonglat(this.projParams); break;
+ case "merc": this.proj = new ProjMerc(this.projParams); break;
+ case "mill": this.proj = new ProjMill(this.projParams); break;
+ case "moll": this.proj = new ProjMoll(this.projParams); break;
+ case "nzmg": this.proj = new ProjNzmg(this.projParams); break;
+ case "omerc": this.proj = new ProjOmerc(this.projParams); break;
+ case "ortho": this.proj = new ProjOrtho(this.projParams); break;
+ case "sinu": this.proj = new ProjSinu(this.projParams); break;
+ case "omerc": this.proj = new ProjOmerc(this.projParams); break;
+ case "stere": this.proj = new ProjStere(this.projParams); break;
+ case "sterea": this.proj = new ProjSterea(this.projParams); break;
+ case "tmerc": this.proj = new ProjTmerc(this.projParams); break;
+ case "utm": this.proj = new ProjUtm(this.projParams); break;
+ case "vandg": this.proj = new ProjVandg(this.projParams); break;
+ }
+ if (this.proj!=null) {
+ this.proj.init();
+ this.readyToUse = true;
+ }
+ }
+
+ private function parseDef(definition:String):void
+ {
+ var paramName:String = '';
+ var paramVal:String = '';
+ var paramArray:Array=definition.split("+");
+ for (var prop:int=0; prop<paramArray.length; prop++) {
+ var property:Array = paramArray[prop].split("=");
+ paramName = property[0].toLowerCase();
+ paramVal = property[1];
+
+ switch (paramName.replace(/\s/gi,"")) { // trim out spaces
+ case "": break; // throw away nameless parameter
+ case "title": this.projParams.title = paramVal; break;
+ case "proj": this.projParams.projName = paramVal.replace(/\s/gi,""); break;
+ case "units": this.projParams.units = paramVal.replace(/\s/gi,""); break;
+ case "datum": this.projParams.datumCode = paramVal.replace(/\s/gi,""); break;
+ case "nadgrids": this.projParams.nagrids = paramVal.replace(/\s/gi,""); break;
+ case "ellps": this.projParams.ellps = paramVal.replace(/\s/gi,""); break;
+ case "a": this.projParams.a = parseFloat(paramVal); break; // semi-major radius
+ case "b": this.projParams.b = parseFloat(paramVal); break; // semi-minor radius
+ // DGR 2007-11-20
+ case "rf": this.projParams.rf = parseFloat(paramVal); break; // inverse flattening rf= a/(a-b)
+ case "lat_0": this.projParams.lat0 = parseFloat(paramVal)*ProjConstants.D2R; break; // phi0, central latitude
+ case "lat_1": this.projParams.lat1 = parseFloat(paramVal)*ProjConstants.D2R; break; //standard parallel 1
+ case "lat_2": this.projParams.lat2 = parseFloat(paramVal)*ProjConstants.D2R; break; //standard parallel 2
+ case "lat_ts": this.projParams.lat_ts = parseFloat(paramVal)*ProjConstants.D2R; break; // used in merc and eqc
+ case "lon_0": this.projParams.long0 = parseFloat(paramVal)*ProjConstants.D2R; break; // lam0, central longitude
+ case "alpha": this.projParams.alpha = parseFloat(paramVal)*ProjConstants.D2R; break; //for somerc projection
+ case "lonc": this.projParams.longc = parseFloat(paramVal)*ProjConstants.D2R; break; //for somerc projection
+ case "x_0": this.projParams.x0 = parseFloat(paramVal); break; // false easting
+ case "y_0": this.projParams.y0 = parseFloat(paramVal); break; // false northing
+ case "k_0": this.projParams.k0 = parseFloat(paramVal); break; // projection scale factor
+ case "k": this.projParams.k0 = parseFloat(paramVal); break; // both forms returned
+ case "R_A": this.projParams.R_A = true; break; //Spheroid radius
+ case "zone": this.projParams.zone = parseInt(paramVal); break; // UTM Zone
+ case "south": this.projParams.utmSouth = true; break; // UTM north/south
+ case "towgs84":this.projParams.datum_params = paramVal.split(","); break;
+ case "to_meter": this.projParams.to_meter = parseFloat(paramVal); break; // cartesian scaling
+ case "from_greenwich": this.projParams.from_greenwich = parseFloat(paramVal)*ProjConstants.D2R; break;
+ // DGR 2008-07-09 : if pm is not a well-known prime meridian take
+ // the value instead of 0.0, then convert to radians
+ case "pm": paramVal = paramVal.replace(/\s/gi,"");
+ this.projParams.from_greenwich = ProjConstants.PrimeMeridian[paramVal] ?
+ ProjConstants.PrimeMeridian[paramVal] : parseFloat(paramVal);
+ this.projParams.from_greenwich *= ProjConstants.D2R;
+ break;
+ case "no_defs": break;
+ default: trace("Unrecognized parameter: " + paramName); break;
+ } // switch()
+ } // for paramArray
+ this.deriveConstants();
+
+ }
+
+ private function deriveConstants():void
+ {
+ if (this.projParams.nagrids == '@null') this.projParams.datumCode = 'none';
+ if (this.projParams.datumCode && this.projParams.datumCode != 'none')
+ {
+ var datumDef:Object = ProjConstants.Datum[this.projParams.datumCode];
+ if (datumDef)
+ {
+ this.projParams.datum_params = datumDef.towgs84.split(',');
+ this.projParams.ellps = datumDef.ellipse;
+ this.projParams.datumName = datumDef.datumName ? datumDef.datumName : this.projParams.datumCode;
+ }
+ }
+
+ if (!this.projParams.a) { // do we have an ellipsoid?
+ var ellipse:Object = ProjConstants.Ellipsoid[this.projParams.ellps] ? ProjConstants.Ellipsoid[this.projParams.ellps] : ProjConstants.Ellipsoid['WGS84'];
+ extend(this.projParams, ellipse);
+ }
+ if (this.projParams.rf && !this.projParams.b) this.projParams.b = (1.0 - 1.0/this.projParams.rf) * this.projParams.a;
+ if (Math.abs(this.projParams.a - this.projParams.b)<ProjConstants.EPSLN) {
+ this.projParams.sphere = true;
+ this.projParams.b= this.projParams.a;
+ }
+ this.projParams.a2 = this.projParams.a * this.projParams.a; // used in geocentric
+ this.projParams.b2 = this.projParams.b * this.projParams.b; // used in geocentric
+ this.projParams.es = (this.projParams.a2-this.projParams.b2)/this.projParams.a2; // e ^ 2
+ this.projParams.e = Math.sqrt(this.projParams.es); // eccentricity
+ if (this.projParams.R_A) {
+ this.projParams.a *= 1. - this.projParams.es * (ProjConstants.SIXTH + this.projParams.es * (ProjConstants.RA4 + this.projParams.es * ProjConstants.RA6));
+ this.projParams.a2 = this.projParams.a * this.projParams.a;
+ this.projParams.b2 = this.projParams.b * this.projParams.b;
+ this.projParams.es = 0.;
+ }
+ this.projParams.ep2=(this.projParams.a2-this.projParams.b2)/this.projParams.b2; // used in geocentric
+ if (!this.projParams.k0) this.projParams.k0 = 1.0; //default value
+
+ this.projParams.datum = new Datum(this);
+ }
+
+ private function extend(destination:Object, source:Object):void
+ {
+ destination = destination || {};
+ if(source) {
+ for(var property:String in source) {
+ var value:Object = source[property];
+ if(value != null) {
+ destination[property] = value;
+ }
+ }
+ }
+ }
+
+ public function forward(p:ProjPoint):ProjPoint
+ {
+ if (this.proj!=null)
+ {
+ return this.proj.forward(p);
+ }
+ return p;
+ }
+
+ public function inverse(p:ProjPoint):ProjPoint
+ {
+ if (this.proj!=null)
+ {
+ return this.proj.inverse(p);
+ }
+ return p;
+ }
+
+ }
+}
View
113 com/gradoservice/proj4as/proj/AbstractProjProjection.as
@@ -0,0 +1,113 @@
+package com.gradoservice.proj4as.proj
+{
+ import com.gradoservice.proj4as.ProjPoint;
+
+ public class AbstractProjProjection extends ProjParams implements IProjection
+ {
+ protected var sinphi:Number;
+ protected var cosphi:Number;
+ protected var temp:Number;
+ protected var e0:Number;
+ protected var e1:Number;
+ protected var e2:Number;
+ protected var e3:Number;
+ protected var sin_po:Number;
+ protected var cos_po:Number;
+ protected var t1:Number;
+ protected var t2:Number;
+ protected var t3:Number;
+ protected var con:Number;
+ protected var ms1:Number;
+ protected var ms2:Number;
+ protected var ns:Number;
+ protected var ns0:Number;
+ protected var qs0:Number;
+ protected var qs1:Number;
+ protected var qs2:Number;
+ protected var c:Number;
+ protected var rh:Number;
+ protected var cos_phi:Number;
+ protected var sin_phi:Number;
+ protected var g:Number;
+ protected var ml:Number;
+ protected var ml0:Number;
+ protected var ml1:Number;
+ protected var ml2:Number;
+ protected var mode:int;
+
+ protected var cos_p12:Number;
+ protected var sin_p12:Number;
+
+ protected var rc:Number;
+
+
+ public function AbstractProjProjection(data:ProjParams)
+ {
+ this.extend(data);
+ }
+
+ public function init():void
+ {
+
+ }
+
+ public function forward(p:ProjPoint):ProjPoint
+ {
+ return p;
+ }
+
+ public function inverse(p:ProjPoint):ProjPoint
+ {
+ return p;
+ }
+
+ protected function extend(source:ProjParams):void
+ {
+
+ this.title = source.title;
+ this.projName= source.projName;
+ this.units= source.units;
+ this.datum = source.datum;
+ this.datumCode=source.datumCode;
+ this.datumName=source.datumName;
+ this.nagrids=source.nagrids;
+ this.ellps=source.ellps;
+ this.a=source.a;
+ this.b=source.b;
+ this.a2=source.a2;
+ this.b2=source.b2;
+ this.e=source.e;
+ this.es=source.es;
+ this.ep2=source.ep2;
+ this.rf=source.rf;
+ this.long0=source.long0;
+ this.lat0=source.lat0;
+ this.lat1=source.lat1;
+ this.lat2=source.lat2;
+ this.lat_ts=source.lat_ts;
+ this.alpha=source.alpha;
+ this.longc=source.longc;
+ this.x0=source.x0;
+ this.y0=source.y0;
+ this.k0=source.k0;
+ this.k=source.k;
+ this.R_A=source.R_A;
+ this.zone=source.zone;
+ this.utmSouth=source.utmSouth;
+ this.to_meter=source.to_meter;
+ this.from_greenwich=source.from_greenwich;
+ this.datum_params=source.datum_params;
+ this.sphere=source.sphere;
+ this.ellipseName=source.ellipseName;
+
+ this.srsCode=source.srsCode;
+ this.srsAuth=source.srsAuth;
+ this.srsProjNumber=source.srsProjNumber;
+
+ }
+
+ }
+
+
+
+}
View
14 com/gradoservice/proj4as/proj/IProjection.as
@@ -0,0 +1,14 @@
+package com.gradoservice.proj4as.proj
+{
+ import com.gradoservice.proj4as.ProjPoint;
+
+ public interface IProjection
+ {
+ function init():void
+
+ function forward(p:ProjPoint):ProjPoint
+
+ function inverse(p:ProjPoint):ProjPoint
+
+ }
+}
View
145 com/gradoservice/proj4as/proj/ProjAea.as
@@ -0,0 +1,145 @@
+package com.gradoservice.proj4as.proj
+{
+ import com.gradoservice.proj4as.ProjConstants;
+ import com.gradoservice.proj4as.ProjPoint;
+ import com.gradoservice.proj4as.Datum;
+
+ public class ProjAea extends AbstractProjProjection
+ {
+ public function ProjAea(data:ProjParams)
+ {
+ super(data);
+ }
+
+ override public function init():void
+ {
+ if (Math.abs(this.lat1 + this.lat2) <ProjConstants.EPSLN) {
+ trace("aeaInitEqualLatitudes");
+ return;
+ }
+ this.temp = this.b / this.a;
+ this.es = 1.0 - Math.pow(this.temp,2);
+ this.e3 = Math.sqrt(this.es);
+
+ this.sin_po=Math.sin(this.lat1);
+ this.cos_po=Math.cos(this.lat1);
+ this.t1=this.sin_po
+ this.con = this.sin_po;
+ this.ms1 = ProjConstants.msfnz(this.e3,this.sin_po,this.cos_po);
+ this.qs1 = ProjConstants.qsfnz(this.e3,this.sin_po,this.cos_po);
+
+ this.sin_po=Math.sin(this.lat2);
+ this.cos_po=Math.cos(this.lat2);
+ this.t2=this.sin_po;
+ this.ms2 = ProjConstants.msfnz(this.e3,this.sin_po,this.cos_po);
+ this.qs2 = ProjConstants.qsfnz(this.e3,this.sin_po,this.cos_po);
+
+ this.sin_po=Math.sin(this.lat0);
+ this.cos_po=Math.cos(this.lat0);
+ this.t3=this.sin_po;
+ this.qs0 = ProjConstants.qsfnz(this.e3,this.sin_po,this.cos_po);
+
+ if (Math.abs(this.lat1 - this.lat2) > ProjConstants.EPSLN) {
+ this.ns0 = (this.ms1 * this.ms1 - this.ms2 *this.ms2)/ (this.qs2 - this.qs1);
+ } else {
+ this.ns0 = this.con;
+ }
+ this.c = this.ms1 * this.ms1 + this.ns0 * this.qs1;
+ this.rh = this.a * Math.sqrt(this.c - this.ns0 * this.qs0)/this.ns0;
+ }
+
+/* Albers Conical Equal Area forward equations--mapping lat,long to x,y
+ -------------------------------------------------------------------*/
+ override public function forward(p:ProjPoint):ProjPoint
+ {
+ var lon:Number=p.x;
+ var lat:Number=p.y;
+
+ this.sin_phi=Math.sin(lat);
+ this.cos_phi=Math.cos(lat);
+
+ var qs:Number = ProjConstants.qsfnz(this.e3,this.sin_phi,this.cos_phi);
+ var rh1:Number =this.a * Math.sqrt(this.c - this.ns0 * qs)/this.ns0;
+ var theta:Number = this.ns0 * ProjConstants.adjust_lon(lon - this.long0);
+ var x:Number = rh1 * Math.sin(theta) + this.x0;
+ var y:Number = this.rh - rh1 * Math.cos(theta) + this.y0;
+
+ p.x = x;
+ p.y = y;
+ return p;
+ }
+
+
+ override public function inverse(p:ProjPoint):ProjPoint
+ {
+ var rh1:Number;
+ var qs:Number;
+ var con:Number;
+ var theta:Number
+ var lon:Number;
+ var lat:Number;
+
+ p.x -= this.x0;
+ p.y = this.rh - p.y + this.y0;
+ if (this.ns0 >= 0) {
+ rh1 = Math.sqrt(p.x *p.x + p.y * p.y);
+ con = 1.0;
+ } else {
+ rh1 = -Math.sqrt(p.x * p.x + p.y *p.y);
+ con = -1.0;
+ }
+ theta = 0.0;
+ if (rh1 != 0.0) {
+ theta = Math.atan2(con * p.x, con * p.y);
+ }
+ con = rh1 * this.ns0 / this.a;
+ qs = (this.c - con * con) / this.ns0;
+ if (this.e3 >= 1e-10) {
+ con = 1 - .5 * (1.0 -this.es) * Math.log((1.0 - this.e3) / (1.0 + this.e3))/this.e3;
+ if (Math.abs(Math.abs(con) - Math.abs(qs)) > .0000000001 ) {
+ lat = this.phi1z(this.e3,qs);
+ } else {
+ if (qs >= 0) {
+ lat = .5 * Math.PI;
+ } else {
+ lat = -.5 * Math.PI;
+ }
+ }
+ } else {
+ lat = this.phi1z(e3,qs);
+ }
+
+ lon = ProjConstants.adjust_lon(theta/this.ns0 + this.long0);
+ p.x = lon;
+ p.y = lat;
+ return p;
+ }
+
+/* Function to compute phi1, the latitude for the inverse of the
+ Albers Conical Equal-Area projection.
+-------------------------------------------*/
+ private function phi1z (eccent:Number,qs:Number):Number
+ {
+ var con:Number;
+ var com:Number
+ var dphi:Number;
+ var phi:Number = ProjConstants.asinz(.5 * qs);
+ if (eccent < ProjConstants.EPSLN) return phi;
+
+ var eccnts:Number = eccent * eccent;
+ for (var i:int = 1; i <= 25; i++) {
+ sinphi = Math.sin(phi);
+ cosphi = Math.cos(phi);
+ con = eccent * sinphi;
+ com = 1.0 - con * con;
+ dphi = .5 * com * com / cosphi * (qs / (1.0 - eccnts) - sinphi / com + .5 / eccent * Math.log((1.0 - con) / (1.0 + con)));
+ phi = phi + dphi;
+ if (Math.abs(dphi) <= 1e-7) return phi;
+ }
+ trace("aea:phi1z:Convergence error");
+ return 0;
+ }
+
+
+ }
+}
View
93 com/gradoservice/proj4as/proj/ProjAeqd.as
@@ -0,0 +1,93 @@
+package com.gradoservice.proj4as.proj
+{
+ import com.gradoservice.proj4as.ProjPoint;
+ import com.gradoservice.proj4as.ProjConstants;
+ import com.gradoservice.proj4as.Datum;
+
+ public class ProjAeqd extends AbstractProjProjection
+ {
+ public function ProjAeqd(data:ProjParams)
+ {
+ super(data);
+ }
+
+ override public function init():void
+ {
+ this.sin_p12=Math.sin(this.lat0)
+ this.cos_p12=Math.cos(this.lat0)
+ }
+
+ override public function forward(p:ProjPoint):ProjPoint
+ {
+ var lon:Number=p.x;
+ var lat:Number=p.y;
+ var ksp:Number;
+
+ var sinphi:Number=Math.sin(p.y);
+ var cosphi:Number=Math.cos(p.y);
+ var dlon:Number = ProjConstants.adjust_lon(lon - this.long0);
+ var coslon:Number = Math.cos(dlon);
+ var g:Number = this.sin_p12 * sinphi + this.cos_p12 * cosphi * coslon;
+ if (Math.abs(Math.abs(g) - 1.0) < ProjConstants.EPSLN) {
+ ksp = 1.0;
+ if (g < 0.0) {
+ trace("aeqd:Fwd:PointError");
+ return null;
+ }
+ } else {
+ var z:Number = Math.acos(g);
+ ksp = z/Math.sin(z);
+ }
+ p.x = this.x0 + this.a * ksp * cosphi * Math.sin(dlon);
+ p.y = this.y0 + this.a * ksp * (this.cos_p12 * sinphi - this.sin_p12 * cosphi * coslon);
+ return p;
+ }
+
+ override public function inverse(p:ProjPoint):ProjPoint
+ {
+ p.x -= this.x0;
+ p.y -= this.y0;
+
+ var rh:Number = Math.sqrt(p.x * p.x + p.y *p.y);
+ if (rh > (2.0 * ProjConstants.HALF_PI * this.a))
+ {
+ trace("aeqdInvDataError");
+ return null;
+ }
+ var z:Number = rh / this.a;
+
+ var sinz:Number=Math.sin(z)
+ var cosz:Number=Math.cos(z)
+
+ var lon:Number = this.long0;
+ var lat:Number;
+ if (Math.abs(rh) <= ProjConstants.EPSLN) {
+ lat = this.lat0;
+ } else {
+ lat = ProjConstants.asinz(cosz * this.sin_p12 + (p.y * sinz * this.cos_p12) / rh);
+ var con:Number = Math.abs(this.lat0) - ProjConstants.HALF_PI;
+ if (Math.abs(con) <= ProjConstants.EPSLN) {
+ if (lat0 >= 0.0) {
+ lon = ProjConstants.adjust_lon(this.long0 + Math.atan2(p.x , -p.y));
+ } else {
+ lon = ProjConstants.adjust_lon(this.long0 - Math.atan2(-p.x , p.y));
+ }
+ } else {
+ con = cosz - this.sin_p12 * Math.sin(lat);
+ if ((Math.abs(con) < ProjConstants.EPSLN) && (Math.abs(p.x) < ProjConstants.EPSLN)) {
+ //no-op, just keep the lon value as is
+ } else {
+ var temp:Number = Math.atan2((p.x * sinz * this.cos_p12), (con * rh));
+ lon = ProjConstants.adjust_lon(this.long0 + Math.atan2((p.x * sinz * this.cos_p12), (con * rh)));
+ }
+ }
+ }
+
+ p.x = lon;
+ p.y = lat;
+ return p;
+ }
+
+
+ }
+}
View
55 com/gradoservice/proj4as/proj/ProjEqc.as
@@ -0,0 +1,55 @@
+package com.gradoservice.proj4as.proj
+{
+ import com.gradoservice.proj4as.ProjPoint;
+ import com.gradoservice.proj4as.ProjConstants;
+ import com.gradoservice.proj4as.Datum;
+
+ public class ProjEqc extends AbstractProjProjection
+ {
+ public function ProjEqc(data:ProjParams)
+ {
+ super(data);
+ }
+
+ override public function init():void
+ {
+ if(!this.x0) this.x0=0;
+ if(!this.y0) this.y0=0;
+ if(!this.lat0) this.lat0=0;
+ if(!this.long0) this.long0=0;
+ if(!this.lat_ts) this.lat_ts=0;
+ if (!this.title) this.title = "Equidistant Cylindrical (Plate Carre)";
+ this.rc= Math.cos(this.lat_ts);
+ }
+
+
+ // forward equations--mapping lat,long to x,y
+ // -----------------------------------------------------------------
+ override public function forward(p:ProjPoint):ProjPoint
+ {
+ var lon:Number= p.x;
+ var lat:Number= p.y;
+
+ var dlon:Number = ProjConstants.adjust_lon(lon - this.long0);
+ var dlat:Number = ProjConstants.adjust_lat(lat - this.lat0 );
+ p.x= this.x0 + (this.a*dlon*this.rc);
+ p.y= this.y0 + (this.a*dlat );
+ return p;
+ }
+
+ // inverse equations--mapping x,y to lat/long
+ // -----------------------------------------------------------------
+ override public function inverse(p:ProjPoint):ProjPoint
+ {
+ var x:Number= p.x;
+ var y:Number= p.y;
+
+ p.x= ProjConstants.adjust_lon(this.long0 + ((x - this.x0)/(this.a*this.rc)));
+ p.y= ProjConstants.adjust_lat(this.lat0 + ((y - this.y0)/(this.a )));
+ return p;
+ }
+
+
+
+ }
+}
View
156 com/gradoservice/proj4as/proj/ProjEqdc.as
@@ -0,0 +1,156 @@
+/*******************************************************************************
+NAME EQUIDISTANT CONIC
+
+PURPOSE: Transforms input longitude and latitude to Easting and Northing
+ for the Equidistant Conic projection. The longitude and
+ latitude must be in radians. The Easting and Northing values
+ will be returned in meters.
+
+PROGRAMMER DATE
+---------- ----
+T. Mittan Mar, 1993
+
+ALGORITHM REFERENCES
+
+1. Snyder, John P., "Map Projections--A Working Manual", U.S. Geological
+ Survey Professional Paper 1395 (Supersedes USGS Bulletin 1532), United
+ State Government Printing Office, Washington D.C., 1987.
+
+2. Snyder, John P. and Voxland, Philip M., "An Album of Map Projections",
+ U.S. Geological Survey Professional Paper 1453 , United State Government
+ Printing Office, Washington D.C., 1989.
+*******************************************************************************/
+
+package com.gradoservice.proj4as.proj
+{
+ import com.gradoservice.proj4as.ProjPoint;
+ import com.gradoservice.proj4as.ProjConstants;
+ import com.gradoservice.proj4as.Datum;
+
+ public class ProjEqdc extends AbstractProjProjection
+ {
+ public function ProjEqdc(data:ProjParams)
+ {
+ super(data);
+ }
+
+
+/* Variables common to all subroutines in this code file
+ -----------------------------------------------------*/
+
+/* Initialize the Equidistant Conic projection
+ ------------------------------------------*/
+ override public function init():void
+ {
+ /* Place parameters in static storage for common use
+ -------------------------------------------------*/
+ if(!this.mode) this.mode=0;//chosen default mode
+ this.temp = this.b / this.a;
+ this.es = 1.0 - Math.pow(this.temp,2);
+ this.e = Math.sqrt(this.es);
+ this.e0 = ProjConstants.e0fn(this.es);
+ this.e1 = ProjConstants.e1fn(this.es);
+ this.e2 = ProjConstants.e2fn(this.es);
+ this.e3 = ProjConstants.e3fn(this.es);
+
+ this.sinphi=Math.sin(this.lat1);
+ this.cosphi=Math.cos(this.lat1);
+
+ this.ms1 = ProjConstants.msfnz(this.e,this.sinphi,this.cosphi);
+ this.ml1 = ProjConstants.mlfn(this.e0, this.e1, this.e2,this.e3, this.lat1);
+
+ /* format B
+ ---------*/
+ if (this.mode != 0) {
+ if (Math.abs(this.lat1 + this.lat2) < ProjConstants.EPSLN) {
+ trace("eqdc:Init:EqualLatitudes");
+ //return(81);
+ }
+ this.sinphi=Math.sin(this.lat2);
+ this.cosphi=Math.cos(this.lat2);
+
+ this.ms2 = ProjConstants.msfnz(this.e,this.sinphi,this.cosphi);
+ this.ml2 = ProjConstants.mlfn(this.e0, this.e1, this.e2, this.e3, this.lat2);
+ if (Math.abs(this.lat1 - this.lat2) >= ProjConstants.EPSLN) {
+ this.ns = (this.ms1 - this.ms2) / (this.ml2 - this.ml1);
+ } else {
+ this.ns = this.sinphi;
+ }
+ } else {
+ this.ns = this.sinphi;
+ }
+ this.g = this.ml1 + this.ms1/this.ns;
+ this.ml0 = ProjConstants.mlfn(this.e0, this.e1,this. e2, this.e3, this.lat0);
+ this.rh = this.a * (this.g - this.ml0);
+ }
+
+
+/* Equidistant Conic forward equations--mapping lat,long to x,y
+ -----------------------------------------------------------*/
+ override public function forward(p:ProjPoint):ProjPoint
+ {
+ var lon:Number=p.x;
+ var lat:Number=p.y;
+
+ /* Forward equations
+ -----------------*/
+ var ml:Number = ProjConstants.mlfn(this.e0, this.e1, this.e2, this.e3, lat);
+ var rh1:Number = this.a * (this.g - ml);
+ var theta:Number = this.ns * ProjConstants.adjust_lon(lon - this.long0);
+
+ var x:Number = this.x0 + rh1 * Math.sin(theta);
+ var y:Number = this.y0 + this.rh - rh1 * Math.cos(theta);
+ p.x=x;
+ p.y=y;
+ return p;
+ }
+
+/* Inverse equations
+ -----------------*/
+ override public function inverse(p:ProjPoint):ProjPoint
+ {
+ p.x -= this.x0;
+ p.y = this.rh - p.y + this.y0;
+ var con:Number;
+ var rh1:Number;
+ if (this.ns >= 0) {
+ rh1 = Math.sqrt(p.x *p.x + p.y * p.y);
+ con = 1.0;
+ } else {
+ rh1 = -Math.sqrt(p.x *p. x +p. y * p.y);
+ con = -1.0;
+ }
+ var theta:Number = 0.0;
+ if (rh1 != 0.0) theta = Math.atan2(con *p.x, con *p.y);
+ var ml:Number = this.g - rh1 /this.a;
+ var lat:Number = this.phi3z(this.ml,this.e0,this.e1,this.e2,this.e3);
+ var lon:Number = ProjConstants.adjust_lon(this.long0 + theta / this.ns);
+
+ p.x=lon;
+ p.y=lat;
+ return p;
+ }
+
+/* Function to compute latitude, phi3, for the inverse of the Equidistant
+ Conic projection.
+-----------------------------------------------------------------*/
+ private function phi3z(ml:Number,e0:Number,e1:Number,e2:Number,e3:Number):Number
+ {
+ var phi:Number;
+ var dphi:Number;
+
+ phi = ml;
+ for (var i:int = 0; i < 15; i++) {
+ dphi = (ml + e1 * Math.sin(2.0 * phi) - e2 * Math.sin(4.0 * phi) + e3 * Math.sin(6.0 * phi))/ e0 - phi;
+ phi += dphi;
+ if (Math.abs(dphi) <= .0000000001) {
+ return phi;
+ }
+ }
+ trace("PHI3Z-CONV:Latitude failed to converge after 15 iterations");
+ return 0;
+ }
+
+
+ }
+}
View
90 com/gradoservice/proj4as/proj/ProjEqui.as
@@ -0,0 +1,90 @@
+/*******************************************************************************
+NAME EQUIRECTANGULAR
+
+PURPOSE: Transforms input longitude and latitude to Easting and
+ Northing for the Equirectangular projection. The
+ longitude and latitude must be in radians. The Easting
+ and Northing values will be returned in meters.
+
+PROGRAMMER DATE
+---------- ----
+T. Mittan Mar, 1993
+
+ALGORITHM REFERENCES
+
+1. Snyder, John P., "Map Projections--A Working Manual", U.S. Geological
+ Survey Professional Paper 1395 (Supersedes USGS Bulletin 1532), United
+ State Government Printing Office, Washington D.C., 1987.
+
+2. Snyder, John P. and Voxland, Philip M., "An Album of Map Projections",
+ U.S. Geological Survey Professional Paper 1453 , United State Government
+ Printing Office, Washington D.C., 1989.
+*******************************************************************************/
+package com.gradoservice.proj4as.proj
+{
+ import com.gradoservice.proj4as.Datum;
+ import com.gradoservice.proj4as.ProjConstants;
+ import com.gradoservice.proj4as.ProjPoint;
+
+ public class ProjEqui extends AbstractProjProjection
+ {
+ public function ProjEqui(data:ProjParams)
+ {
+ super(data);
+ }
+
+
+
+ override public function init():void
+ {
+ if(!this.x0) this.x0=0;
+ if(!this.y0) this.y0=0;
+ if(!this.lat0) this.lat0=0;
+ if(!this.long0) this.long0=0;
+ ///this.t2;
+ }
+
+
+
+/* Equirectangular forward equations--mapping lat,long to x,y
+ ---------------------------------------------------------*/
+ override public function forward(p:ProjPoint):ProjPoint
+ {
+
+ var lon:Number=p.x;
+ var lat:Number=p.y;
+
+ var dlon:Number = ProjConstants.adjust_lon(lon - this.long0);
+ var x:Number = this.x0 +this. a * dlon *Math.cos(this.lat0);
+ var y:Number = this.y0 + this.a * lat;
+
+ this.t1=x;
+ this.t2=Math.cos(this.lat0);
+ p.x=x;
+ p.y=y;
+ return p;
+ } //equiFwd()
+
+
+
+/* Equirectangular inverse equations--mapping x,y to lat/long
+ ---------------------------------------------------------*/
+ override public function inverse(p:ProjPoint):ProjPoint
+ {
+
+ p.x -= this.x0;
+ p.y -= this.y0;
+ var lat:Number = p.y /this. a;
+
+ if ( Math.abs(lat) > ProjConstants.HALF_PI) {
+ trace("equi:Inv:DataError");
+ }
+ var lon:Number = ProjConstants.adjust_lon(this.long0 + p.x / (this.a * Math.cos(this.lat0)));
+ p.x=lon;
+ p.y=lat;
+
+ return p;
+ }//equiInv()
+
+ }
+}
View
62 com/gradoservice/proj4as/proj/ProjGauss.as
@@ -0,0 +1,62 @@
+package com.gradoservice.proj4as.proj
+{
+ import com.gradoservice.proj4as.ProjPoint;
+ import com.gradoservice.proj4as.ProjConstants;
+ import com.gradoservice.proj4as.Datum;
+