⭐ 欢迎来到虫虫下载站! | 📦 资源下载 📁 资源专辑 ℹ️ 关于我们
⭐ 虫虫下载站

📄 aimscartography.js

📁 arcims简单实例图解 xiang huandianfen
💻 JS
📖 第 1 页 / 共 2 页
字号:
//aimsCartography.js

//Ellipsoid model constants (actual values here are for WGS84)
  var sm_a = 6378137.0;
  var sm_b = 6356752.314;
  var sm_EccSquared = 6.69437999013e-03;
  var UTMScaleFactor = 0.9996;
  
  var theUnitLabel;
  var theConversion;
  
//Array to hold UTM values
//------------------------  
  var xUTM = new Array();
  var yUTM = new Array();
  
  //Get the area of a polygon using Green's formula  
//-----------------------------------------------
  function getPolygonArea()
  {
   var poly_area = 0;
      
   var u_i = new Array();
   var v_i = new Array();   
  
 //If geographic coords then convert all to UTM meters
 //---------------------------------------------------   
   if (parent.MapFrame.MapUnits == "DEGREES")
   {
    
    for (var i=0;i<(clickPolyAreaX.length);i++)
    {
     var theUTMs = getUTMXY(clickPolyAreaX[i],clickPolyAreaY[i]);
     xUTM[i] = theUTMs[0];
     yUTM[i] = theUTMs[1];
    }

    
  //Change array variables over to xUTM and yUTM   
  //--------------------------------------------
    for (var i=0;i<(xUTM.length - 1);i++)
    {
     u_i[i] = xUTM[i + 1] - xUTM[i];
     v_i[i] = yUTM[i + 1] - yUTM[i];
    } 
 
    u_i[xUTM.length - 1] = xUTM[0] - xUTM[xUTM.length - 1];
    v_i[xUTM.length - 1] = yUTM[0] - yUTM[xUTM.length - 1]; 
        
    for (var i=0;i<u_i.length;i++)   
    {
     poly_area = poly_area + (xUTM[i] * v_i[i] - yUTM[i] * u_i[i]);
    }
       
   }  
   
   else
   
   {

    for (var i=0;i<(clickPolyAreaX.length - 1);i++)
    {
     u_i[i] = clickPolyAreaX[i + 1] - clickPolyAreaX[i];
     v_i[i] = clickPolyAreaY[i + 1] - clickPolyAreaY[i];
    } 
 
    u_i[clickPolyAreaX.length - 1] = clickPolyAreaX[0] - clickPolyAreaX[clickPolyAreaX.length - 1];
    v_i[clickPolyAreaX.length - 1] = clickPolyAreaY[0] - clickPolyAreaY[clickPolyAreaX.length - 1]; 
        
    for (var i=0;i<u_i.length;i++)   
    {
     poly_area = poly_area + (clickPolyAreaX[i] * v_i[i] - clickPolyAreaY[i] * u_i[i]);
    }
    
   } 
    
   poly_area = Math.abs(poly_area) * 0.5 
   
   return poly_area;
  } 
  
  
//Get the centroid of a polygon using Green's formula  
//---------------------------------------------------
  function getCentroidX(poly_area)
  {
   
   var c_x = 0;

 //If geographic coords then convert all to UTM meters
 //---------------------------------------------------   
   if (parent.MapFrame.MapUnits == "DEGREES")
   {
    
    for (var i=0;i<(xUTM.length - 1);i++)
    {
     c_x = c_x + (xUTM[i] + xUTM[i + 1]) * (xUTM[i] * yUTM[i + 1] - xUTM[i + 1] * yUTM[i]);
    } 

    c_x = c_x + (xUTM[xUTM.length - 1] + xUTM[0]) * (xUTM[xUTM.length - 1] * yUTM[0] - xUTM[0] * yUTM[xUTM.length - 1]);
    
   }
   
   else
   
   { 
   
    for (var i=0;i<(clickPolyAreaX.length - 1);i++)
    {
     c_x = c_x + (clickPolyAreaX[i] + clickPolyAreaX[i + 1]) * (clickPolyAreaX[i] * clickPolyAreaY[i + 1] - clickPolyAreaX[i + 1] * clickPolyAreaY[i]);
    } 

    c_x = c_x + (clickPolyAreaX[clickPolyAreaX.length - 1] + clickPolyAreaX[0]) * (clickPolyAreaX[clickPolyAreaX.length - 1] * clickPolyAreaY[0] - clickPolyAreaX[0] * clickPolyAreaY[clickPolyAreaX.length - 1]);
   
   }
  
   c_x = c_x / (6 * poly_area);
    
   return Math.abs(c_x);
  }
  
  
//Get the centroid of a polygon using Green's formula  
//---------------------------------------------------
  function getCentroidY(poly_area)
  {

   var c_y = 0;
   
 //If geographic coords then convert all to UTM meters
 //---------------------------------------------------   
   if (parent.MapFrame.MapUnits == "DEGREES")
   {
    
    for (var i=0;i<(xUTM.length - 1);i++)
    {
     c_y = c_y + (yUTM[i] + yUTM[i + 1]) * (xUTM[i] * yUTM[i + 1] - xUTM[i + 1] * yUTM[i]);
    } 
 
    c_y = c_y + (yUTM[xUTM.length - 1] + yUTM[0]) * (xUTM[xUTM.length - 1] * yUTM[0] - xUTM[0] * yUTM[xUTM.length - 1]);
        
   }
   
   else
   
   { 
    
    for (var i=0;i<(clickPolyAreaX.length - 1);i++)
    {
     c_y = c_y + (clickPolyAreaY[i] + clickPolyAreaY[i + 1]) * (clickPolyAreaX[i] * clickPolyAreaY[i + 1] - clickPolyAreaX[i + 1] * clickPolyAreaY[i]);
    } 
 
    c_y = c_y + (clickPolyAreaY[clickPolyAreaX.length - 1] + clickPolyAreaY[0]) * (clickPolyAreaX[clickPolyAreaX.length - 1] * clickPolyAreaY[0] - clickPolyAreaX[0] * clickPolyAreaY[clickPolyAreaX.length - 1]);
    
   }
    
   c_y = c_y / (6 * poly_area);
      
   return Math.abs(c_y);
  }

  
  function getUTMXY(lon,lat)
  {
   var xy = new Array(2);
   var zone = Math.floor ((lon + 180.0) / 6) + 1;

 //Compute the UTM zone
 //--------------------   
   zone = LatLonToUTMXY (DegToRad(lat),DegToRad (lon),zone,xy);   
   
   return xy;
  } 

  
//Converts a latitude/longitude pair to x and y coordinates in the UTM projection.

//Inputs:
//lat - Latitude of the point, in radians.
//lon - Longitude of the point, in radians.
//zone - UTM zone to be used for calculating values for x and y.
//       If zone is less than 1 or greater than 60, the routine
//       will determine the appropriate zone from the value of lon.

//Outputs:xy - A 2-element array where the UTM x and y values will be stored.

//Returns:The UTM zone used for calculating the values of x and y.

  function LatLonToUTMXY (lat,lon,zone,xy)
  {
   MapLatLonToXY (lat, lon, UTMCentralMeridian (zone), xy);

 //Adjust easting and northing for UTM system
 //------------------------------------------
   xy[0] = xy[0] * UTMScaleFactor + 500000.0;
   xy[1] = xy[1] * UTMScaleFactor;
   
   if (xy[1] < 0.0)
   {
    xy[1] = xy[1] + 10000000.0;
   } 

   return zone;
  }
    
            
//Converts a latitude/longitude pair to x and y coordinates in the
//Transverse Mercator projection.  Note that Transverse Mercator is not
//the same as UTM; a scale factor is required to convert between them.

//Inputs:
//phi - Latitude of the point, in radians.
//lambda - Longitude of the point, in radians.
//lambda0 - Longitude of the central meridian to be used, in radians.

//Outputs:
//xy - A 2-element array containing the x and y coordinates of the computed point.

//Returns:
//The function does not return a value.

  function MapLatLonToXY (phi, lambda, lambda0, xy)
  {
    
   var N, nu2, ep2, t, t2, l;
   var l3coef, l4coef, l5coef, l6coef, l7coef, l8coef;
   var tmp;

 //Precalculate ep2
   ep2 = (Math.pow (sm_a, 2.0) - Math.pow (sm_b, 2.0)) / Math.pow (sm_b, 2.0);
    
 //Precalculate nu2
   nu2 = ep2 * Math.pow (Math.cos (phi), 2.0);
    
 //Precalculate N
   N = Math.pow (sm_a, 2.0) / (sm_b * Math.sqrt (1 + nu2));
    
 //Precalculate t
   t = Math.tan (phi);
   t2 = t * t;
   tmp = (t2 * t2 * t2) - Math.pow (t, 6.0);

 //Precalculate l
   l = lambda - lambda0;
    
 //Precalculate coefficients for l**n in the equations below
 //so a normal human being can read the expressions for easting and northing
  
   l3coef = 1.0 - t2 + nu2;
    
   l4coef = 5.0 - t2 + 9 * nu2 + 4.0 * (nu2 * nu2);
    
   l5coef = 5.0 - 18.0 * t2 + (t2 * t2) + 14.0 * nu2 - 58.0 * t2 * nu2;
    
   l6coef = 61.0 - 58.0 * t2 + (t2 * t2) + 270.0 * nu2 - 330.0 * t2 * nu2;
    
   l7coef = 61.0 - 479.0 * t2 + 179.0 * (t2 * t2) - (t2 * t2 * t2);
    
   l8coef = 1385.0 - 3111.0 * t2 + 543.0 * (t2 * t2) - (t2 * t2 * t2);
    
 //Calculate easting(x)
   xy[0] = N * Math.cos (phi) * l
           + (N / 6.0 * Math.pow (Math.cos (phi), 3.0) * l3coef * Math.pow (l, 3.0))
           + (N / 120.0 * Math.pow (Math.cos (phi), 5.0) * l5coef * Math.pow (l, 5.0))
           + (N / 5040.0 * Math.pow (Math.cos (phi), 7.0) * l7coef * Math.pow (l, 7.0));
    
 //Calculate northing(y)
   xy[1] = ArcLengthOfMeridian (phi)
           + (t / 2.0 * N * Math.pow (Math.cos (phi), 2.0) * Math.pow (l, 2.0))
           + (t / 24.0 * N * Math.pow (Math.cos (phi), 4.0) * l4coef * Math.pow (l, 4.0))
           + (t / 720.0 * N * Math.pow (Math.cos (phi), 6.0) * l6coef * Math.pow (l, 6.0))
           + (t / 40320.0 * N * Math.pow (Math.cos (phi), 8.0) * l8coef * Math.pow (l, 8.0));
    
   return;
  }

          
//Converts degrees to radians.
  function DegToRad (deg)
  {
   return (deg / 180.0 * Math.PI)
  }

//Converts radians to degrees.
  function RadToDeg (rad)
  {
   return (rad / Math.PI * 180.0)

⌨️ 快捷键说明

复制代码 Ctrl + C
搜索代码 Ctrl + F
全屏模式 F11
切换主题 Ctrl + Shift + D
显示快捷键 ?
增大字号 Ctrl + =
减小字号 Ctrl + -