| Products: Engine: VB6 Platforms: WindowsMinimum ArcGIS Release: 9.0 |
' Converts decimal degrees to radians.' Divide radians by DDtoRAD to convert back to decimal degrees.Public ConstDDtoRAD = 3.14159265358979 / 180#PublicaAs Double, e2As Double' Change the library path if necessary. The geoddist function provides' access to the pe_geodesic_distance function in the Projection Engine' library, pe90.dll. The function inputs are:'' a = semimajor axis of a spheroid' e2 = eccentricity, e2 = f*(2-f) where f = flattening' lam1 = longitude of the first point in radians' phi1 = latitude of the first point in radians' lam2 = longitude of the second point in radians' phi2 = latitude of the second point in radians'' The function returns:'' distance = geodesic distance between the two points in meters' az12 = geodetic azimuth from point 1 to point 2 in radians' az21 = geodetic azimuth from point 2 to point 1 in radians'' The returned distance is a geodesic distance. A great circle distance' is on a sphere. The geodesic is on a spheroid/ellipsoid. If you wish' the great circle distance, make sure that the geographic coordinate' system uses a sphere. Ex: esriSRGeoCS_Authalicsphere (R = 6371000 m)Private Declare FunctiongeoddistLib"c:\arcgis\arcexe90\bin\pe90.dll" _Alias"pe_geodesic_distance" (ByValaAs Double,ByVale2As Double, _ByVallam1As Double,ByValphi1As Double, _ByVallam2As Double,ByValphi2As Double, _ distanceAs Double, azi12As Double, azi21As Double)As Long' Change the library path if necessary. The geodcoord function provides' access to the pe_geodesic_coordinate function in the Projection Engine' library, pe82.dll. The function inputs are:'' a = semimajor axis of a spheroid' e2 = eccentricity, e2 = f*(2-f) where f = flattening' lam1 = longitude of the first point in radians' phi1 = latitude of the first point in radians' distance = geodesic distance between the two points in meters' az12 = geodetic azimuth from point 1 to point 2 in radians'' The function returns:'' lam2 = longitude of the second point in radians' phi2 = latitude of the second point in radians'' The returned coordinate is based on a geodesic distance. A great circle' is on a sphere. The geodesic is on a spheroid/ellipsoid. If you wish' to use a great circle distance, make sure that the geographic coordinate' system uses a sphere. Ex: esriSRGeoCS_Authalicsphere (R = 6371000 m)Private Declare FunctiongeodcoordLib"c:\arcgis\arcexe90\bin\pe90.dll" _Alias"pe_geodesic_coordinate" (ByValaAs Double,ByVale2As Double, _ByVallam1As Double,ByValphi1As Double, _ByValdistanceAs Double,ByValazi12As Double, _ lam2As Double, phi2As Double)As Long Public Submain()' By default, these functions calculate the geodesic distance or coordinate.' A geodesic distance is calculated on a spheroid. A great circle distance' is calculated on a sphere. If you want the great circle distance, set' the a parameter to the radius of the sphere and set e2 to zero.geodesic_distance geodesic_coordinateEnd Sub Public Subgeodesic_distance(ByVallon1As Double,ByVallat1As Double, _ByVallon2As Double,ByVallat2As Double, _ distAs Double, a12As Double, a21As Double)' Initialization of variables needed by the geoddist function.Dimlam1As Double, phi1As Double Dimlam2As Double, phi2As Double DimdistanceAs Double Dimazi12As Double, azi21As Double' Defining the geographic coordinate system.' SetSpheroid retrieves the spheroid parameters. Change the' geographic coordinate system in the SetSpheroid subroutine.SetSpheroid a, e2' Definition of two input points and conversion to radians.lam1 = lon1 * DDtoRAD phi1 = lat1 * DDtoRAD lam2 = lon2 * DDtoRAD phi2 = lat2 * DDtoRAD' The function is called.geoddist a, e2, lam1, phi1, lam2, phi2, distance, azi12, azi21 dist = distance a12 = azi12 / DDtoRAD a21 = azi21 / DDtoRAD' Print or store the results. The azimuths are converted back to' decimal degrees.' Debug.Print distance' Debug.Print azi12 / DDtoRAD' Debug.Print azi21 / DDtoRADEnd Sub Public Subgeodesic_coordinate(ByVallon1cAs Double,ByVallat1cAs Double, _ByValdistcAs Double,ByValazi12cAs Double, _ lon2cAs Double, lat2cAs Double)' Initialization of variables needed by the geodcoord function.Dimlam1As Double, phi1As Double Dimlam2As Double, phi2As Double DimdistanceAs Double Dima12As Double' Defining the geographic coordinate system.' SetSpheroid retrieves the spheroid parameters. Change the' geographic coordinate system in the SetSpheroid subroutine.SetSpheroid a, e2' Convert the input point and azimuth to radians.lam1 = lon1c * DDtoRAD phi1 = lat1c * DDtoRAD a12 = azi12c * DDtoRAD' Assign the distancedistance = distc' The function is called.geodcoord a, e2, lam1, phi1, distance, a12, lon2c, lat2c' Print or store the results. The second point is converted back to' decimal degrees.lon2c = lon2c / DDtoRAD lat2c = lat2c / DDtoRADEnd Sub Public SubSetSpheroid(aAs Double, e2As Double)DimfAs Double DimpSpatialReferenceEnvAsSpatialReferenceEnvironmentSetpSpatialReferenceEnv =NewSpatialReferenceEnvironment' Defining the geographic coordinate system.' Change esriSRGeoCSType enumeration to the appropriate geographic' coordinate system.DimpGCSAsIGeographicCoordinateSystemDimpSpatialReferenceAsISpatialReferenceSetpGCS = pSpatialReferenceEnv.CreateGeographicCoordinateSystem(esriSRGeoCS_NAD1983)' This section retrieves the spheroid parameters from the geographic' coordinate system.DimpDatumAsIDatumDimpSpheroidAsISpheroidSetpDatum = pGCS.DatumSetpSpheroid = pDatum.Spheroid a = pSpheroid.SemiMajorAxis f = pSpheroid.Flattening e2 = f * (2# - f)End Sub