Commit 1ff077f6 authored by Calvin Metcalf's avatar Calvin Metcalf
Browse files

190 lines into Proj4.js

parent 324a33ee
Loading
Loading
Loading
Loading
+113 −116
Original line number Diff line number Diff line
@@ -65,6 +65,7 @@ proj4.defaultDatum = 'WGS84'; //default datum
    *     projected Cartesian (x,y), but should always have x,y properties.
    */
proj4.transform = function(source, dest, point) {
  var wgs84;
  if (!source.readyToUse) {
    this.reportError("proj4 initialization for:"+source.srsCode+" not yet complete");
      return point;
@@ -73,21 +74,20 @@ proj4.transform = function(source, dest, point) {
    this.reportError("proj4 initialization for:"+dest.srsCode+" not yet complete");
      return point;
  }
  function checkNotWGS(source,dest){
    return ((source.datum.datum_type === proj4.common.PJD_3PARAM || source.datum.datum_type === proj4.common.PJD_7PARAM) && dest.datumCode !== "WGS84");
  }
  
  // Workaround for datum shifts towgs84, if either source or destination projection is not wgs84
        if (source.datum && dest.datum && (
            ((source.datum.datum_type === proj4.common.PJD_3PARAM || source.datum.datum_type === proj4.common.PJD_7PARAM) && dest.datumCode !== "WGS84") ||
            ((dest.datum.datum_type === proj4.common.PJD_3PARAM || dest.datum.datum_type === proj4.common.PJD_7PARAM) && source.datumCode !== "WGS84"))) {
            var wgs84 = proj4.WGS84;
  if (source.datum && dest.datum && (checkNotWGS(source, dest) ||checkNotWGS(dest,source))) {
    wgs84 = proj4.WGS84;
    this.transform(source, wgs84, point);
    source = wgs84;
  }

  // DGR, 2010/11/12
  if (source.axis!=="enu") {
    this.adjust_axis(source,false,point);
  }

  // Transform source points to long/lat, if they aren't already.
  if (source.projName==="longlat") {
    point.x *= proj4.common.D2R;  // convert degrees to radians
@@ -99,7 +99,6 @@ proj4.transform = function(source, dest, point) {
    }
     source.inverse(point); // Convert Cartesian to longlat
  }

  // Adjust for the prime meridian if necessary
  if (source.from_greenwich) { 
    point.x += source.from_greenwich; 
@@ -139,7 +138,7 @@ proj4.transform = function(source, dest, point) {
      point to transform in geodetic coordinates (long, lat, height)
    */
proj4.datum_transform = function( source, dest, point ) {

  var wp,i,l;
  // Short cut if the datums are identical.
  if( source.compare_datums( dest ) ) {
    return point; // in this case, zero is sucess,
@@ -161,35 +160,33 @@ proj4.datum_transform = function( source, dest, point ) {

  var fallback= source.datum_type;
  // If this datum requires grid shifts, then apply it to geodetic coordinates.
      if( fallback === proj4.common.PJD_GRIDSHIFT )
      {
  if( fallback === proj4.common.PJD_GRIDSHIFT ) {
    if (this.apply_gridshift( source, 0, point )===0) {
      source.a = proj4.common.SRS_WGS84_SEMIMAJOR;
      source.es = proj4.common.SRS_WGS84_ESQUARED;
    } else {

      // try 3 or 7 params transformation or nothing ?
      if (!source.datum_params) {
        source.a = src_a;
        source.es = source.es;
        return point;
      }
              var wp= 1.0;
              for (var i= 0, l= source.datum_params.length; i<l; i++) {
      wp= 1;
      for (i= 0, l= source.datum_params.length; i<l; i++) {
        wp*= source.datum_params[i];
      }
              if (wp===0.0) {
      if (wp===0) {
        source.a = src_a;
        source.es = source.es;
        return point;
      }
              fallback= source.datum_params.length>3?
                proj4.common.PJD_7PARAM
              : proj4.common.PJD_3PARAM;
              // CHECK_RETURN;
      if(source.datum_params.length>3){
        fallback = proj4.common.PJD_7PARAM;
      } else {
        fallback = proj4.common.PJD_3PARAM;
      }
    }
  }

  if( dest.datum_type === proj4.common.PJD_GRIDSHIFT ){
          dest.a = proj4.common.SRS_WGS84_SEMIMAJOR;
          dest.es = proj4.common.SRS_WGS84_ESQUARED;