|
Quick example for requesting elevations from a Utah SGID web service using VBA in ArcMap. The web service is called WSUTSGID_RasterValues and returns an elevation value when provided a point location and the elevation data set (SGID.SGIDRAS.DEM_10METER) as input parameters. Not blazing speed but it works in a pinch. This could be used to generate an elevation profile dataset for graphing elevation profile data for routes and trails (like the data graphed below), although there are certainly faster ways to do it. I recommend using the www.ian-ko.com's Easy Calculate field calculator scripts to first generalize (shape_Generalize.cal) and then densify (shape_Densify.cal, I used 100 meters) your line work first so that you have the minimum set of vertices evenly spaced for the line for which you want to get elevation values. Import the output into Excel and graph. Click image for full size view.
Public Sub getElevationValues() 'AGRC-BG 5/2/07, updated 5/28/08
'BEFORE USING THIS SCRIPT IN ARCMAP, YOU MUST: '1) Download & Install Microsoft Office XP Web Services Toolkit 2.0 from ' http://www.microsoft.com/downloads/details.aspx?FamilyId=4922060F-002A-4F5B-AF74-978F2CD6C798&displaylang=en ' '2) From within the VBA Interface's Tools>>References menu ' Enable the reference: Microsoft Soap Type Library 3.0 ' '3) Register with mapserv.utah.gov to get a username (set variable below to your ' username) to test the GetRasterValue web service, ' or, change the code to reference another webservice and its operations. Dim outputDir as String outputDir = "c:/temp" Dim mapServUserName As String mapServUserName = "yourMapServUserName Here" 'get from mapserv.utah.gov Dim WSDLAddress As String WSDLAddress = "http://mapserv.utah.gov/WSUTSGID_RasterValues/Default.asmx?wsdl" Dim i As Integer Dim x As Integer Dim objSClient As MSSOAPLib30.SoapClient30 ' Remove the 30 if using an earlier version of SOAP ' Point the SOAP API to the web service that we want to call... Set objSClient = New SoapClient30 Call objSClient.MSSoapInit(par_WSDLFile:=WSDLAddress)
Dim pMxDoc As IMxDocument Dim pRouteFL As IFeatureLayer Dim pRouteFC As IFeatureClass Dim pRouteFeatureCursor As IFeatureCursor Dim pRouteFeature As IFeature Dim pPointCollection As IPointCollection Dim p As Long Dim pVertexPoint As IPoint Set pMxDoc = ThisDocument Set pRouteFL = pMxDoc.FocusMap.Layer(0) Set pRouteFC = pRouteFL.FeatureClass Set pRouteFeatureCursor = pRouteFC.Search(Nothing, True) Set pRouteFeature = pRouteFeatureCursor.NextFeature Dim response As String Dim responseConv As Double Do Until pRouteFeature Is Nothing Open outputDir & "/elevoutfile" & pRouteFeature.OID & ".txt" For Output As #1 Set pPointCollection = pRouteFeature.Shape
For p = 0 To pPointCollection.PointCount - 1 Set pVertexPoint = pPointCollection.Point(p) ' Call a specific web service operation ' The example web service operation is called RasterValues and ' takes 3 arguments: [username], [raster layer], [utmx], [utmy] response = objSClient.GetRasterValue(mapServUserName, "SGID.SGIDRAS.DEM_10METER", pVertexPoint.x, pVertexPoint.Y) response = Replace(response, "|meters", "") responseConv = CLng(CDbl(response) * 3.2808) Debug.Print p & "," & responseConv & "," & CLng(pVertexPoint.x) & "," & CLng(pVertexPoint.Y) Print #1, p & "," & responseConv & "," & CLng(pVertexPoint.x) & "," & CLng(pVertexPoint.Y) Next p Set pRouteFeature = pRouteFeatureCursor.NextFeature Close #1 Loop Set objSClient = Nothing
End Sub |