Sunday, May 24, 2009

ArcEditor or ArcGIS Licence Example code

An ArcGIS Engine-based application must initialize certain environment variables and check out a license before it can execute.
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 ?
------------------------------------------------------------------------------------------------
1. What is the basic difference between a command and a tool?
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


Proximity Web Service overview
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.



https://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.


See live example




IProximity Interface Example code

Private Sub GetNearestPoint()
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


This sample allows the user to view the mouse location in decimal degrees when the user clicks with the mouse.In this sample, you will be adding a new tool to the interface and writing the code for the tool.


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.

Add a Shape file Programatically


Dear all

find this steps to understand the arcobject code for Adding shape file programatically

This sample, which can easily be changed to support different data types, opens a shapefile on your local disk and adds the contents to the map as a feature layer. In this sample, you will be adding a control button 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 UIButtonControl as the UIControl Type.
Click Create.
Click and drag the new Project.UIButtonControl1 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 choose Click. 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 UIButtonControl1_Click() and End Sub). Dim pWorkspaceFactory As IWorkspaceFactory
Set pWorkspaceFactory = New ShapefileWorkspaceFactory
Dim pWorkSpace As IFeatureWorkspace
'Change C:\Source to the source location of the shapefile you wish to add
Set pWorkSpace = pWorkspaceFactory.OpenFromFile("C:\GISQuery\", 0)
Dim pClass As IFeatureClass
'Change USStates to the name of the shapefile you wish to add
Set pClass = pWorkSpace.OpenFeatureClass("GISQuery")
Dim pLayer As IFeatureLayer
Set pLayer = New FeatureLayer
Set pLayer.FeatureClass = pClass
pLayer.Name = pClass.AliasName
Dim pMxDoc As IMxDocument
Set pMxDoc = ThisDocument
pMxDoc.AddLayer pLayer
pMxDoc.ActiveView.PartialRefresh esriViewGeography, pLayer, Nothing
Go to line 5, Set pWorkSpace = pWorkspaceFactory.OpenFromFile("C:\Source", 0), and change C:\Source to the source location of the shapefile you want to add.
Go to line 8, Set pClass = pWorkSpace.OpenFeatureClass("GISQuery"), and change GISQuery to the name of the shapefile you want to add.
Close the Visual Basic Editor.
Click the new button in ArcMap to add the feature class to the map.



Monday, May 11, 2009

IdentityTool Sample code,



Dear All

ArcMap has an Identity tool which is used to view the information of an feature based on user clicks.
It also contains most of the interfaced used in arcobjects, some of them are
IFeatureLayer
IFeatureClass
ISpatialfilter
IMXdocument
IApplication



and many more, if you want to learn about this then study this tool, it will help you a lot to understand this.

Email me to get the code of this tool
Follow this link to download, and email me if you like this

Saturday, May 9, 2009

Select By Attribute Query Code in ArcMap


Hi all

As we have seen the Select By attribute query command in ArcMap many times and prefebly we have been used it many times. Do you know something interesting about this tool. This Development of this tool will teach you a lot about arcobject because most of the arcobjects are used here in the code.

So if you can write the code or understand the code of "Select By Attribute" then you would known as a good programmer of ArcObjects.

I have developed this command for all those new comers of Arcobjects who want to learn arcobject in a very short span of time.
Please email me your request so that i can transfer this code to you.
and i have a lot of other codes also which are very good to learn about this Arcobject.
contact at
or you can also leave a comment on this site with your id.
follow this link to download the sample code and email me if you like this
http://rapidshare.com/files/234459990/QueryByAttributeCommand.zip

Friday, May 8, 2009

GIS Basics


Let Me explain the GIS Basics here, so that you should also aware about the GIS Technology, These question comes in everyone life who is working on GIS Technology, sometime we don't know the answer, so Here You are.


A GIS can be distinguished by listing the types of questions it can (or should be able to) answer as opposed to being described: a) through formal definitions, and b) through its ability to carry out spatial operations, and linking data sets together with location as the common key. There are five generic questions that a sophisticated GIS can answer:
1 - Location What is at ...? The first of these questions seeks to find out what exists at a particular location described in various ways (e.g., place name, post or zip code, or geographic references).
2 - Situation/Condition Where does it exist? The second question is the converse of the first and requires spatial analysis to answer. Instead of identifying what exists at a given location, a location is found where certain conditions are satisfied (e.g., an unforested section of land of at least 2000 square meters in size, within 100 meters of a road, and with soils suitable for supporting buildings).
3 - Trends What has changed since...? The third question involves both of the first two, and seeks to find the differences within an area over time.
4 - Patterns What spatial patterns exist? The fourth question is more sophisticated; the question is asked to determine whether cancer is a major cause of death among residents near a nuclear power station or how many anomalies there are that don't fit a predetermined pattern and where they are located.
5 - Modeling What if...? The fifth question is posed to determine what happens, for example, if a new road is added to a network, or if a toxic substance seeps into the local groundwater supply. (Answering this type of question requires both geographic as well as other information, and possibly scientific laws.)

GIS Query


GISQuery is a interface between Problem and Solution, As GIS is a well known Technology of today's World. So there are thousands of guys who want the solution of their query, but they do not find any link on web related to problem.

This is a place where you can write your query to us and all the followers of this blog will get back to you with the solution.