On becoming ESRI MVP

Thanks to all professional friends and colleagues for this.
http://support.esri.com/index.cfm?fa=forums.gateway

Posted in General | Leave a comment

Calculate sum of the lengths of selected Polylines

The following code is useful to get a sum of selected Polyline features :-

Sub CalcLength()
Dim pMxD As IMxDocument
Set pMxD = ThisDocument

Dim pMap As IMap
Set pMap = pMxD.FocusMap

Dim pEnumFeat As IEnumFeature
Set pEnumFeat = pMap.FeatureSelection

Dim pFeat As IFeature, pCurve As ICurve, dLen As Double

dLen = 0#

Set pFeat = pEnumFeat.Next

Do Until pFeat Is Nothing

If TypeOf pFeat.Shape Is ICurve Then
Set pCurve = pFeat.Shape

dLen = dLen + pCurve.Length
End If

Set pFeat = pEnumFeat.Next
Loop

MsgBox “The length of the selected features is ” & Format(dLen, “0.00”)

End Sub

Posted in ArcObjects with Visual Basic | Leave a comment

Dissolve a group layer in ArcMap TOC

There are two ways to implement this: –

1. Use IUngroupLayerOperation to UNGROUP your layers so that the group is removed while layers remain. However, there is no sample code to implement IUngroupLayerOperation.

2. In the second approach, you can add child layers using IGroupLayer:: Add layers to parent grouplayer and then clear grouplayer_child to remove its layers and finally remove child grouplayer.

The following code can be used to dissolve a group layer in ArcMap TOC: –

Option Explicit
Private Sub UIButtonControl1_Click()
Dim i, j, k As Integer
Dim pMxdoc As IMxDocument
Set pMxdoc = ThisDocument
Dim pMap As IMap
Set pMap = pMxdoc.FocusMap
Dim pCompositeLayer_parent As ICompositeLayer
Dim pCompositeLayer_child As ICompositeLayer
Dim pGrplyr_parent As IGroupLayer
Set pGrplyr_parent = New GroupLayer
Dim pGrplyr_child As IGroupLayer
Set pGrplyr_child = New GroupLayer
For i = 0 To pMap.LayerCount – 1
If TypeOf pMap.Layer(i) Is IGroupLayer Then
Set pCompositeLayer_parent = pMap.Layer(i)
Set pGrplyr_parent = pMap.Layer(i)
For j = 0 To pCompositeLayer_parent.Count – 1
If TypeOf pCompositeLayer_parent.Layer(j) Is IGroupLayer Then
Set pCompositeLayer_child = pCompositeLayer_parent.Layer(j)
Set pGrplyr_child = pCompositeLayer_parent.Layer(j)
For k = 0 To pCompositeLayer_child.Count – 1
pGrplyr_parent.Add pCompositeLayer_child.Layer(k)
Next k
pGrplyr_child.Clear
pGrplyr_parent.Delete pCompositeLayer_child
End If
Next j
End If
Next i
pMxdoc.UpdateContents
End Sub

Posted in ArcObjects with Visual Basic | Leave a comment

How to extract installed ArcGIS version?

The following code can be utilized to get to know installed ArcGIS version: –

Public Function GetArcGISVersion() As String
On Error GoTo Err
Dim WScr As Object
Set WScr = CreateObject("WScript.Shell")
Dim sVer As String
sVer = WScr.RegRead("HKEY_LOCAL_MACHINE\SOFTWARE\ESRI\ArcGIS\RealVersion")
GetArcGISVersion = sVer
If Trim(sVer) = vbNullString Then
MsgBox "ERROR: ARCGIS-1" & vbCrLf & "Unable to retrieve ArcGIS information on this machine." & vbCrLf & "ArcGIS installation on this machine seems to be corrupt." & vbCrLf & "Please contact your system administrator."
End If
GoTo Cleanup
Err:
GetArcGISVersion = ""
If Err.Number = 53 Then
MsgBox "ERROR: ARCGIS-2" & vbCrLf & "ArcGIS is not installed on this machine." & vbCrLf & "Please install ArcGIS prior to run this application."
Else
MsgBox "ERROR: " & Err.Number & vbCrLf & Err.Description
End If
Cleanup:
Set WScr = Nothing
End Function

Posted in ArcObjects with Visual Basic | Leave a comment

Welcome on board

Welcome to Paritosh Gupta’s WebLog. This weblog will serve as a platform for ESRI ArcObjects developers world-wide. The key words include Visual Basic, C# .NET, ArcObjects, ArcGIS Desktop, ArcGIS Server, Flex API, ArcGIS Engine, PHP, JavaScript, ASP.NET

Posted in General | Leave a comment