KML Network Link

Network Links are great ways to reference KML or KMZ files archive on a local or remote location. You can use the element to specify the location of the KML file. Within that element, you can define the refresh options for updating the file, based on time and camera change. NetworkLinks can be used in combination with Regions to handle very large datasets efficiently. Following is a code snippet in C# : –

public void AddSensorNetworkLink(XmlDocument doc, XmlNode DocumentNode, string sensor, string URL)
XmlNode NetworkLinkNode = doc.CreateElement("NetworkLink");
XmlNode nameNode = doc.CreateElement("name");

XmlNode LinkNode = doc.CreateElement("Link");
XmlNode hrefNode = doc.CreateElement("href");

Posted in ArcObjects with Visual C# .NET | Leave a comment

Create polygon in a KML file

The following C# code will help you in creating a polygon for Google Earth based KML file. Have a look: –

public void AddPolygon(XmlDocument doc, XmlNode DocumentNode, int lat, int lon, int gridsize, string name, string id)
XmlNode PlacemarkNode = doc.CreateElement("Placemark");
XmlNode nameNode = doc.CreateElement("name");
XmlNode StyleNode = doc.CreateElement("styleUrl");
XmlNode PolyNode = doc.CreateElement("Polygon");
XmlNode tessNode = doc.CreateElement("tessellate");
XmlNode altNode = doc.CreateElement("altitudeMode");
XmlNode BoundNode = doc.CreateElement("outerBoundaryIs");
XmlNode LineNode = doc.CreateElement("LinearRing");
XmlNode coordinateNode = doc.CreateElement("coordinates");

string coord = lon.ToString() + "," + lat.ToString() + ",0," + Convert.ToString(lon + gridsize) + "," + lat.ToString() + ",0," + Convert.ToString(lon + gridsize) + "," + Convert.ToString(lat + gridsize) + ",0," + lon.ToString() + "," + Convert.ToString(lat + gridsize) + ",0," + lon.ToString() + "," + lat.ToString()+ ",0";


Posted in ArcObjects with Visual C# .NET | Leave a comment


Arc Hydro has been designed to represent data from hydrography and hydrology, thereby creating a basis for obtaining a deeper understanding of surface water systems. The Arc Hydro tools are a set of utilities developed on top of the Arc Hydro data model. They operate in the ArcGIS environment. Some of the functions require the Spatial and 3D Analyst extensions. More on this in a technical paper presented on the occasion of Map India 2004: –

Posted in Technical Papers | Leave a comment

On becoming ESRI MVP

Thanks to all professional friends and colleagues for this.

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

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_parent.Delete pCompositeLayer_child
End If
Next j
End If
Next i
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
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
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."
MsgBox "ERROR: " & Err.Number & vbCrLf & Err.Description
End If
Set WScr = Nothing
End Function

Posted in ArcObjects with Visual Basic | Leave a comment