Sunday, May 24, 2009
ArcEditor or ArcGIS Licence Example code
First, initialize environment variables and acquire an Engine license.
EngineInitializer.initializeEngine();
AoInitialize aoInit = new AoInitialize();
aoInit.initialize(esriLicenseProductCode.esriLicenseProductCodeEngine);If you are working with the ArcGIS controls (visual JavaBeans found in the com.esri.arcgis.beans.xxxx packages), then the initialization code looks like this:
EngineInitializer. initializeVisualBeans();
AoInitialize aoInit = new AoInitialize();
aoInit.initialize(esriLicenseProductCode.esriLicenseProductCodeEngine);
If your application requires the use of an extension product, such as Spatial Analyst or 3D Analyst, then you need to check these licenses as well. This code cannot precede the initial license checkout.
aoInit.initialize(esriLicenseExtensionCode.esriLicenseExtensionCodeSpatialAnalyst);
aoInit.initialize(esriLicenseExtensionCode.esriLicenseExtensionCode3DAnalyst);
Open a SDE Connection with Database
This example uses ArcObjects to connect directly to ArcSDE and get data sets rather than using the MapServer object to get the ArcSDE layers in a Map.
Create a WorkspaceFactory object within the Server's context.
IWorkspaceFactory pWorkspaceFactory = new IWorkspaceFactoryProxy(context.createObject("esriDataSourcesGDB.SdeWorkspaceFactory"));
Create an instance of a PropertySet for an Oracle ArcSDE connection. The PropertySet acts as an array of keyed values that ArcSDE will use to collect the connection values from:
PropertySet propSet = new PropertySet(context.createObject("esrisystem.PropertySet"));
propSet.setProperty("SERVER", "tel");
propSet.setProperty("INSTANCE", "5051");
propSet.setProperty("DATABASE", "");
propSet.setProperty("USER", "map");
propSet.setProperty("PASSWORD", "map");
propSet.setProperty("VERSION", "SDE.DEFAULT");
Open the ArcSDE workspace and get a handle to it through the WorkspaceFactory, passing in the PropertySet:
IWorkspace ws = pWorkspaceFactory.open(propSet,0);
You now have a connection to the database through a Workspace object (“ws”). In this example, the feature datasets are listed out:
IEnumDataset dsenum = ws.getDatasets(esriDatasetType.esriDTFeatureDataset);
IDataset ds = dsenum.next();
while(ds != null){
System.out.println(ds.getName());
ds = dsenum.next();
}
Friday, May 22, 2009
Are You expert in Arcobject, Answer this.

Define ArcObjects -
What are applications of ArcGIS Desktop – Ans: ArcMap, ArcCatalog and ArcToolbox
A class represents objects that can be created directly.
Normal A class cannot be used to create new objects, but it is a specification for sub classes A can’t directly create new objects, but objects of a class can be created as a property of another class or by functions from another class.
What is the basic difference between a command and a tool? – A MUST question
Name the object that is first created when ArcMap starts running
An instance of ArcCatalog has number of templates associated with it by default.
How many instances of an extension can exist per running application
The interface is implemented in order to create a configurable extension allowing users to toggle its enabled state.
Which of the following the default renderer object when a new feature class is loaded?
Which is the interface to which a renderer object can be assigned directly?
Name the interface that can be used to do editing in ArcObjects
Name the interface that can be used to create a new feature?
Define Domain. What are different types of domain
Which is the interface that is used to find a specific version provided its name as string
merges the current edit version with the target version
What is different between direct connection and through SDE connection?
Define versioning and list its main events
How will release com objects.
If you want to update ‘n’ number of features in featureclass which interface will you use (performance wise)
What is Callback in ArcGIS Server?
Explain security model employed in ArcGIS Server . Whats new in 9.3?
What is projection ?
What are different projection systems and what is difference between projected coordinated system and geographic coordinate system
What is a scale.?
What is geocoding?
What is reverse geocoding?
What is geo-referencing?
What is geo-processing?
What is ArcSDE. What is database which you used?.
If two persons updating the particular row of the table in database?. How does the system work?.
How do you load data into SDE?
How will create a SDE view?
What is an interface to implemented for callback ?
What is difference between queryfilter and querydef?, when to use ?
Difference between IFeatureLayer and Layer
What is generic class used to hold a set of properties for database connection?
Whether every controls in Web ADF has a property “CallBackresults”?
Give few command line ArcSDE commands?
Difference beteween personal geodatabase and enterprise geodatabase
What is ASP.NET AJax model used in ArcGIS Server 9.3 and 9.3
What is BLOB?
What is difference between Overriding and overloading
Difference between abstract class and interface
What is GPS ?
Ans: A command unlike a tool, once clicked doesn’t require any further user interaction with the map to complete its function.
2. A __________ class represents objects that can be created directly.
a. Class
b. CoClass
c. Abstract Class
d. None of the above
3. A __________ class cannot be used to create new objects, but it is a specification for sub classes.
a. Class
b. CoClass
c. Abstract Class
d. None of the above
Thursday, May 21, 2009
WebServices in GIS

You can use the Proximity Web Service to find all points of interest (POI) locations within a distance you define for a specified point or line (for example, find all POIs within five miles of x,y) or determine the nearest specified number of POI locations to a specified point or line (such as find nearest three POIs to x,y).
The Proximity Web Service offers the following capabilities:
Find nearest features.
Find features within a specified radius.
Return list and related information of found features.
Limit searches based on user-specified criteria.
http://arcweb.esri.com/services/v2/Proximity.wsdl
Note: HTTPS is available if you need added security to call ArcWeb Services. The Authentication Web Service and other ArcWeb Services must be accessed with the same IP address for the authentication token to be valid.
IProximity Interface Example code
Dim pPoint As IPoint
Dim pProximity As IProximityOperator
Dim pGeom As IGeometry
Dim pFeature As IFeature, pTestFeature As IFeature, pPointFeature As IFeature
Dim tempDist As Double, searchDist As Double, testDistance As Double, pointTestDistance As Double
Dim pFeatureClass As IFeatureClass
Dim pQueryFilter As IQueryFilter
Dim pFeatureCursor As IFeatureCursor
Dim iCount As Integer
Dim iDescription As Long, iOID As Long
Dim sClosest As String
On Error GoTo ErrorHandler
sClosest = "Nothing Found"
pointTestDistance = -1
testDistance = -1
searchDist = 500
iCount = 0
Set pFeatureClass = pFeatureWorkspace.OpenFeatureClass("ALL_CITIES")
Set pQueryFilter = New QueryFilter
'Get the search point
pQueryFilter.WhereClause = "WHERE OBJECTID = 23746"
Set pFeatureCursor = pFeatureClass.Search(pQueryFilter, False)
iDescription = pFeatureCursor.FindField("LOC_DESC")
iOID = pFeatureCursor.FindField("OBJECTID")
Set pTestFeature = pFeatureCursor.NextFeature
Debug.Print "?" & pTestFeature.Value(iOID) & " " & pTestFeature.Value(iDescription)
Set pPoint = pTestFeature.Shape
Set pProximity = pPoint
'Get the search data
pQueryFilter.WhereClause = "WHERE CNTRY = 'XX' and OBJECTID <> 23746"
Set pFeatureCursor = Nothing
Set pTestFeature = Nothing
Set pFeatureCursor = pFeatureClass.Search(pQueryFilter, False)
Set pTestFeature = pFeatureCursor.NextFeature
Debug.Print "START****" & Time
Do While (Not pTestFeature Is Nothing)
Set pGeom = pTestFeature.Shape
tempDist = pProximity.ReturnDistance(pGeom)
If (tempDist < searchDist) Then
If (pointTestDistance < 0) Then pointTestDistance = tempDist + 1
If (tempDist < pointTestDistance Or pointTestDistance = -1) Then
sClosest = pTestFeature.Value(iOID) & " " & pTestFeature.Value(iDescription) & " " & " [" & tempDist & "]"
Debug.Print sClosest
pointTestDistance = tempDist
Set pPointFeature = pTestFeature
End If
End If
iCount = iCount + 1
Set pTestFeature = pFeatureCursor.NextFeature
Loop
Debug.Print "END****" & Time
Debug.Print "Records parsed: " & iCount
Debug.Print "Closest Point: " & sClosest
Debug.Print "===================================================="
Exit Sub
ErrorHandler:
MsgBox "An unexpected error has occured in GetNearestPoint." & vbCr & vbCr & _
"Details : " & Err.Description, vbExclamation + vbOKOnly, "Error"
End Sub
Monday, May 18, 2009
Spatial Filter Example code

Count features within an area
DescriptionThis sample uses a spatial query filter to count the number of features within an area. First, click the tool button (you create) on the toolbar, then click and drag a rectangle around the features you want to have counted. The program retrieves the cursor's locations based on a filter, then loops through a counting procedure of all the features. The number of points, lines, and areas are totaled and reported to the user on a message box. In this sample, you will be adding a control tool and writing the code for it.
Start ArcMap.
Open an existing map document (.mxd) or add layers to the empty (Untitled) map document.
Click Tools and click Customize.
Click the Commands tab.
Click the drop-down arrow on the Save in combo box and click the map document in which the new command will be saved.
Scroll through the Categories list and click [UIControls].
Click New UIControl.
Click to select the UIToolControl as the UIControl Type.
Click Create.
Click and drag the new Project.UIToolControl1 in the Commands list and drop it on any toolbar.
Click Close.
Right-click the newly placed control and click View Source. This opens the Visual Basic Editor.
In the ThisDocument (Code) window, click the Procedure Box drop-down arrow (the one on the right of the window) and click MouseDown. This adds the wrapper code for the procedure you are creating.
Copy and paste the following code between the two wrapper code lines (between
---------------------------------------------------------------------------------------------
Private Sub UIToolControl1_MouseDown(ByVal button As Long, ByVal shift As Long, ByVal x As Long, ByVal y As Long) and End Sub): Dim pMxDoc As IMxDocument
Set pMxDoc = ThisDocument
Dim pEnv As IEnvelope
Dim pRubber As IRubberBand
Set pRubber = New RubberEnvelope
Dim pActiveView As IActiveView
Set pActiveView = pMxDoc.FocusMap
Set pEnv = pRubber.TrackNew(pActiveView.ScreenDisplay, Nothing)
Dim pSpatialFilter As ISpatialFilter
Set pSpatialFilter = New SpatialFilter
Set pSpatialFilter.Geometry = pEnv
pSpatialFilter.SpatialRel = esriSpatialRelIntersects
Dim lPoints As Long, lPolylines As Long, lPolygons As Long
Dim pLayer As IFeatureLayer
Dim pFeatureCursor As IFeatureCursor
Dim pFeature As IFeature
Dim i As Long
For i = 0 To pMxDoc.FocusMap.LayerCount - 1
If (TypeOf pMxDoc.FocusMap.Layer(i) Is IGeoFeatureLayer) Then
Set pLayer = pMxDoc.FocusMap.Layer(i)
pSpatialFilter.GeometryField = pLayer.FeatureClass.ShapeFieldName
Set pFeatureCursor = pLayer.Search(pSpatialFilter, True)
Set pFeature = pFeatureCursor.NextFeature
Do Until (pFeature Is Nothing)
Select Case pFeature.Shape.GeometryType
Case esriGeometryPoint
lPoints = lPoints + 1
Case esriGeometryPolyline
lPolylines = lPolylines + 1
Case esriGeometryPolygon
lPolygons = lPolygons + 1
End Select
Set pFeature = pFeatureCursor.NextFeature
Loop
End If
Next i
MsgBox "Features Found:" & vbCrLf & lPoints & " Points " & vbCrLf & _
lPolylines & " Polylines " & vbCrLf & lPolygons & " Polygons "
---------------------------------------------------------------------------------------------
Close the Visual Basic Editor.
Click the Tool button in ArcMap, then click and drag to select an area in which to count the features.
Display a mouse location in decimal degrees

Start ArcMap.
Open an existing map document (.mxd) or add layers to the empty (Untitled) map document. The data added to the map must be projected.
Click Tools and click Customize.
Click the Commands tab.
Click the drop-down arrow on the Save in combo box and click the map document in which the new command will be saved.
Scroll through the Categories list and click [UIControls].
Click New UIControl.
Click to select the UIToolControl as the UIControl Type.
Click Create and Edit.
Copy and paste the following code after all other code in the ThisDocument (Code) window.Private Sub UIToolControl1_MouseDown(ByVal button As Long, ByVal shift As Long, ByVal x As Long, ByVal y As Long)
Dim pMxDoc As IMxDocument
Dim pPoint As IPoint
Dim pClone As IClone
Dim pGeometry As IGeometry
Dim pSpatialRefFactory As ISpatialReferenceFactory
Dim pSpatialRef As ISpatialReference
Dim pGeographicCoordSys As IGeographicCoordinateSystem
'Get the point where the user clicked
Set pMxDoc = Application.Document
If pMxDoc.CurrentLocation.IsEmpty Then Exit Sub
'Clone the point because we don't want to alter
'the actual document's current location point
Set pClone = pMxDoc.CurrentLocation
Set pPoint = pClone.Clone
Set pGeometry = pPoint 'QI
'Create a new geographic coordinate system to use in the conversion
Set pSpatialRefFactory = New SpatialReferenceEnvironment
Set pGeographicCoordSys = pSpatialRefFactory.CreateGeographicCoordinateSystem(esriSRGeoCS_NAD1983)
Set pSpatialRef = pGeographicCoordSys 'QI
pSpatialRef.SetFalseOriginAndUnits -180, -90, 1000000
pGeometry.Project pSpatialRef
MsgBox pPoint.x & ", " & pPoint.y, , "Decimal Degrees"
End Sub
Close or minimize the VBA window.
In ArcMap, click Tools and click Customize.
Click the Commands Tab.
Click the drop-down arrow on the Save in combo box and click the map document in which the new control was saved.
Scroll through the Categories list and click [UIControls].
Click the Project.UIToolControl1 in the Commands list. Click and drag this button and drop it onto any toolbar.
Click Close.
Click the tool and click anywhere on the map.