Jump to content

Programming in ArcGIS Desktop (VB.NET, VB & VBA)


yousef2233

Recommended Posts

I'm newbie in gis programming, I'm sorry if I have a lot of question about it..

first, in the code of :

[quote][color=#282828][font=helvetica, arial, sans-serif]Set pDoc = ThisDocument[/font][/color]
[color=#282828][font=helvetica, arial, sans-serif]If Not pDoc.SelectedLayer Is Nothing Then[/font][/color]
[color=#282828][font=helvetica, arial, sans-serif]Set pLayer = pDoc.SelectedLayer[/font][/color]
[color=#282828][font=helvetica, arial, sans-serif]   Else[/font][/color]
[color=#282828][font=helvetica, arial, sans-serif]MsgBox "No Layers Selected in TOC"[/font][/color][/quote]
[quote][/quote]

do you mean that if there isn't feature selected, it will show nothing??

how about it..call feature that has declared before to process it after..

in this case, i have called 2 file and show them in arcmap..the i wanna call them is other step..i don't know how to use TOC.

last, but not least..

How can I use arctool such analysis tool (extract, overlayand so on)?

thank you very much

Link to comment
Share on other sites

the TOC in ArcMAP includes some layers you have added already, my codes checks if any of them has been selected. just run my code and you will see what i mean.

'Defining some pointers you should be familiar with them

Dim pDoc As IMxDocument

Dim pLayer As IFeatureLayer

Dim pFeatClass As IFeatureClass

'Setting Pointers

Set pDoc = ThisDocument

'Working with TOC : this part checks if there is any selected layer (Not selected feature) is TOC

'and if so, player = pdoc.selectedlayer. pdoc pointing to the document you are working

' if you have problem understanding this section i seriously suggest reading Getting to know Arcobjects

If Not pDoc.SelectedLayer Is Nothing Then

Set pLayer = pDoc.SelectedLayer

Else

MsgBox "No Layers Selected in TOC"

Exit Sub

End If

'declaring a string variable for path of featureclass or layer

Dim LayerPath As String

Set pFeatClass = pLayer.FeatureClasss

'here is a part for assigning featureclass path to the variable

Dim pDataset As IDataset

Set pDataset = pFeatClass

Dim pWorkspace As IWorkspace

Set pWorkspace = pDataset.Workspace

Dim FCPath As String

FCPath = pWorkspace.PathName & "/" & pLayer.Name

'MsgBox (FCPath)

Link to comment
Share on other sites

the following codes have been written for working with arctoolbox so easy to use

Dim GP As Object

Set GP = CreateObject("esriGeoprocessing.GpDispatch.1")

'if you going to make a buffer around features of a layer, the code will be sth like this

FCpath is the path of the layer selected in the TOC and the "D:\GISAREA\Buffer.shp" the address of the output and obviously 50000 is the buffering distance

GP.Buffer_analysis FCPath, "D:\GISAREA\Buffer.shp", "50000"

good luck

Link to comment
Share on other sites

could I write something like this?

'take a map

Private Sub Petadasar_Click()

Dim p1MxDoc As IMxDocument

Set p1MxDoc = ThisDocument

Dim p1GxDialog As IGxDialog

Set p1GxDialog = New GxDialog

p1GxDialog.AllowMultiSelect = True

p1GxDialog.Title = "Select Feature Classes to Add To Map"

Dim p1GxFilter As IGxObjectFilter

Set p1GxFilter = New GxFilterFeatureClasses

Set p1GxDialog.ObjectFilter = p1GxFilter

Dim p1GxObjects As IEnumGxObject

p1GxDialog.DoModalOpen Thisdocument.Parent.hWnd, p1GxObjects

If (p1GxObjects Is Nothing) Then Exit Sub

p1GxObjects.Reset

Dim p1Layer As IFeatureLayer

Dim p1GxDataset As IGxDataset

Set p1GxDataset = p1GxObjects.Next

Do Until (p1GxDataset Is Nothing)

Set p1Layer = New FeatureLayer

Set p1Layer.FeatureClass = p1GxDataset.Dataset

p1Layer.Name = p1Layer.FeatureClass.AliasName

p1MxDoc.FocusMap.Addlayer p1Layer

Set p1GxDataset = p1GxObjects.Next

Loop

p1MxDoc.ActiveView.PartialRefresh esriViewGeography, Nothing, Nothing

End Sub

'determining a process

Public Sub ComboBox1_DropButtonclick()

With ComboBox1

.AddItem "Flood region"

.AddItem "Urban distance"

.AddItem "Roadway distance"

.AddItem "Topograph"

.AddItem "Slope"

.AddItem "Environmental load"

End With

End Sub

Private Sub CommandButton2_Click()

Dim pDoc As IMxDocument

Dim pLayer As IFeatureLayer

Dim pFeatClass As IFeatureClass

Dim GP As Object

Set pDoc = ThisDocument

Set pLayer = pDoc.SelectedLayer

Set GP = CreateObject("esriGeoprocessing.GpDispatch.1")

If ComboBox1 = "Flood region" Then

GP.Buffer_analysis FCPath, pLayer, "50000"

end if

end sub

  • Like 1
Link to comment
Share on other sites

1- the idea of GxDialogbox is a little weird, never seen sth like that before, all the programs ive seen they work with already added layers

2- FCpath, indicates the path of layer you are working with, and if you insist on using GxDialogbox it should have the path of layer you want to add

3- GP.Buffer_analysis FCPath, pLayer, "50000", FCPath is input layer path, pLayer is output layer Path, and 50000 is an argument in this case it's the buffering distance.

good luck

Link to comment
Share on other sites

Hi, need opinion all u guys

currently using VS 2008 with ArcGIS Engine Developer Kit 10, after compile and running the application on ArcGIS Engine 10 its work fine but after upgrading to ArcGIS Engine 10.1, the application cant run and error as below:

Description:

Stopped working

Problem signature:

Problem Event Name: CLR20r3

Problem Signature 01: apps.exe

Problem Signature 02: 1.0.0.0

Problem Signature 03: 5051b6e5

Problem Signature 04: Microsoft.VisualBasic

Problem Signature 05: 8.0.0.0

Problem Signature 06: 4ca2d138

Problem Signature 07: 6c

Problem Signature 08: 46

Problem Signature 09: System.IO.FileNotFoundException

OS Version: 6.1.7601.2.1.0.256.48

Locale ID: 17417

Could someone tell me what is happening here, thanks.

Edited by selamat
  • Like 1
Link to comment
Share on other sites

Hello all,

i want to overlay any files, so I need intersect_analysis..but I get error comment when I write

Dim GP As Object

Set GP = CreateObject("esriGeoprocessing.GpDispatch.1")

GP.Intersect_analysis "E:\3. STUDY\3. THESIS\2. DATA SPASIAL\utm\administratif\pemukiman.shp", "E:\3. STUDY\3. THESIS\2. DATA SPASIAL\utm\jalan\utama.shp", "D:\intest"

Could you guide me how to write intersect analsis, Please?

Thank you very much

Link to comment
Share on other sites

filename(1) = pWorkspace.PathName + "\" + pFeatureLayer.Name + ".shp"

MkDir ("D:\IPAL_Location_process" + CStr(Counter))

Dim GP As Object

Set GP = CreateObject("esriGeoprocessing.GpDispatch.1")

GP.Intersect_analysis filename(1) ; "D:\IPAL_Location_process\ur" + CStr(Counter) + ".shp", "D:\IPAL_Location_process\urban distance" + CStr(Counter) + ".shp"

but it doesn't work..

Link to comment
Share on other sites

I try to write

Private Sub CommandButton1_Click()

MkDir ("D:\IPAL_Location_processtest")

'spatial process

Dim urbanprocess As String

Dim GP As Object

Set GP = CreateObject("esriGeoprocessing.GpDispatch.1")

Select Case ComboBox1

'Case "Flood region"

'GP.Erase_analysis "E:\3. STUDY\3. THESIS\2. DATA SPASIAL\utm\administratif\batas pkl.shp", "E:\3. STUDY\3. THESIS\2. DATA SPASIAL\utm\banjir\80thn", "D:\IPAL_Location_process\Flood.shp"

Case "Urban distance"

GP.Buffer_analysis "E:\3. STUDY\3. THESIS\2. DATA SPASIAL\utm\administratif\pemukiman.shp", "D:\IPAL_Location_process\ur.shp", "150"

urbanprocess = "D:\IPAL_Location_process\ur.shp"

parameter1 = "urbanprocess;D:\B.shp"

parameter2 = "D:\IPAL_Location_process\urban.shp"

GP.Intersect_analysis parameter1, parameter2

End Select

End Sub

but it compile error in line 14

GP.Intersect_analysis parameter1, parameter2
Edited by Putri Yasmin
Link to comment
Share on other sites

@Selamat, are you sure about version of dotNet you are working with ?

Hi yousef2233

2008.jpg

image above show that i'm using visual studio 2008

is it true that ArcEngine Developer Kit 10.1 using VS2010 while ArcEngine Developer Kit 10 using VS2008

Edited by selamat
Link to comment
Share on other sites

@Putri Yasmin

Dim urbanprocess As String

Dim GP As Object

Set GP = CreateObject("esriGeoprocessing.GpDispatch.1")

parameter1 = "D:\GISAREA\test70.shp;D:\GISAREA\Temp8144.shp"

parameter2 = "D:\GISAREA\RESULT111.shp"

GP.Intersect_analysis parameter1, parameter2

Working fine here

you need a little concentration

i'll send you the rest

  • Like 1
Link to comment
Share on other sites

@Selamat

it seems that way

Before you can install the ArcGIS 10.1 ArcObjects .NET SDK, you must have Visual Studio 2010 installed on your machine. To build .NET applications with ArcGIS for Desktop or Engine, the Microsoft .NET Framework 3.5.1 must be installed on the machine. ArcGIS for Desktop and Engine installs the .NET 3.5.1 framework if it is not already on the machine.

http://resources.arcgis.com/en/help/arcobjects-net/conceptualHelp/index.html#//0001000002ns000000

  • Like 1
Link to comment
Share on other sites

dear all,

I have searched in any website about the function GP.CopyFeatures_management but I haven't found yet why my vba arcgis notices require = after GP.CopyFeatures_management(filename(1),"D:\wwtp\basemap.shp") but in any arcgis help, esriforum etc don't need it

in my arcgis 9.3, VBA compiles error after after GP.CopyFeatures_management(filename(1),"D:\wwtp\basemap.shp") and it needs = but when I write = true, it is error.

and once more, for replacing folder, I use :

Dim sFullPath As String

sFullPath = "D:\GISAREA"

Dim myFSO As Object

Set myFSO = CreateObject("Scripting.FileSystemObject")

FolderExists = myFSO.FolderExists(sFullPath)

if FolderExists = False then

MkDir(sFullPath)

end if

MkDir(sFullPath) was used for replacing exists directory, how about replacing file? I just found like this :

If GP.Exists("D:\directory_wwtp\Flood.shp") = False Then

GP.Erase_analysis "D:\WWTP_directory\basemap.shp", filename(2), "D:\directory_wwtp\Flood.shp"

Else

MkDir (Directory + "\" + ".shp")

End If

but it respons nothing.. :(

would you like to help me, please?

Edited by Putri Yasmin
Link to comment
Share on other sites

Join the conversation

You can post now and register later. If you have an account, sign in now to post with your account.

Guest
Reply to this topic...

×   Pasted as rich text.   Paste as plain text instead

  Only 75 emoji are allowed.

×   Your link has been automatically embedded.   Display as a link instead

×   Your previous content has been restored.   Clear editor

×   You cannot paste images directly. Upload or insert images from URL.

×
×
  • Create New...

Important Information

By using this site, you agree to our Terms of Use.

Disable-Adblock.png

 

If you enjoy our contents, support us by Disable ads Blocker or add GIS-area to your ads blocker whitelist