I want to create and program an arc map add in commend in vb.net. to calculates a measure of gender structure ((Male_pop/FEAMLE_POP)*100 in a GenderStr field. I am getting an error I have included both my code and error message I am getting. I am wondering if anyone can help me what is the problem to solve this error?
First of all a screen shot of your code will not get you much help.... it is hard to see for some of us older folks..... formatted code will allow us to cut paste and see if we get similiar errors as yours....
In any event .... I put together some pseudo code taken from some of my applications that perform something like you want.... hopefully this will point you in the right path
Sub CalculateField() 'Set the pFeatureClass to be the feature class of the top layer in the active map -- if yours is different 'need to set the Layer index for your layer -- much help on finding the layer on the esri development site Dim pMxDoc as IMxDocument Dim pFeatLayer as IFeatureLayer Dim pFeatureClass as IFeatureClass Dim pFields as IFields Set pMxDoc = My.ArcMap.Document Set pFeatLayer = pMxDoc.FocusMap.Layer(0) Set pFeatureClass = pFeatLayer.FeatureClass 'Calculate the field values Dim pCursor As ICursor Dim pCalculator as ICalculator 'Prepare a cursor with all records from your layer Set pCursor = pFeatureClass.Update(Nothing, True) 'Define a calculator Set pCalculator = New Calculator '-------------- 'NOTE: Male_Pop, Female_Pop, and GenderStr MUST Exist within the Cursor so you may want to test for 'existence prior to the calculation with FindFields! Dim fields as IFields = pFeatureClass.Fields Dim fieldIndex as Integer if fields.FindField("Male_Pop") = -1 then msgbox("Male_Pop not found in layer") 'do something to fix this ... end if '... do the same for Female_Pop and for GenderStr '-------------- 'Be sure Female_Pop is not Zero or null With pCalculator Set .Cursor = pCursor Expression = "(([MALE_POP]/[FEMALE_POP]))*100" .Field = "GenderStr" End With 'Calculate the field values pCalculator.Calculate End sub<SPAN class="line-numbers-rows"><SPAN></SPAN><SPAN></SPAN><SPAN></SPAN><SPAN></SPAN><SPAN></SPAN><SPAN></SPAN><SPAN></SPAN><SPAN></SPAN><SPAN></SPAN><SPAN></SPAN><SPAN></SPAN><SPAN></SPAN><SPAN></SPAN><SPAN></SPAN><SPAN></SPAN><SPAN></SPAN><SPAN></SPAN><SPAN></SPAN><SPAN></SPAN><SPAN></SPAN><SPAN></SPAN><SPAN></SPAN><SPAN></SPAN><SPAN></SPAN><SPAN></SPAN><SPAN></SPAN><SPAN></SPAN><SPAN></SPAN><SPAN></SPAN><SPAN></SPAN><SPAN></SPAN><SPAN></SPAN><SPAN></SPAN><SPAN></SPAN><SPAN></SPAN><SPAN></SPAN><SPAN></SPAN><SPAN></SPAN><SPAN></SPAN><SPAN></SPAN></SPAN>
Abdul,
I agree with tkowal, screen shots of code is not a good way of asking a question as the error may be occurring outside what you are displaying and sometimes people mess up with screen resolution so its impossible to read! That said you don't state WHEN the error occurs. You clearly have a bunch of messagebox lines for debugging. This is a significant omission and you need to clarify at which point the error is occurring. Also you give no information about the version of ArcMap or the dataset that you are attempting a calculation on: is it a shape file, personal geodatabase or even an XY event layer? You need to be much more descriptive if you want us to help you. Suggest you edit your question with this information and get in the habit of supplying that if you need to ask another question.
Below Is my code for buffering one layer in ArcGIS ToC. Now I want to bring some changes to perform batch processing. Assume, The clip feature classis the first layer in ToC and that each layer below is to be clipped .
you may add each output clipped feature class as a layer in the ToC after each clip operation.
'define the dataset for clip Dim map As ESRI.ArcGIS.Carto.IMap Dim inputLayer As ESRI.ArcGIS.Carto.IFeatureLayer Dim overlayer As ESRI.ArcGIS.Carto.IFeatureLayer Dim inputFC As ESRI.ArcGIS.Geodatabase.IFeatureClass Dim overlayFC As ESRI.ArcGIS.Geodatabase.IFeatureClass map = mxDocument.FocusMap
'define the input feature class inputLayer = map.Layer(0) inputFC = inputLayer.FeatureClass 'defien the ovelray feature class overlayer = map.Layer(1) overlayFC = overlayer.FeatureClass
'define the output Dim newWSName As ESRI.ArcGIS.Geodatabase.IWorkspaceName Dim FCname As ESRI.ArcGIS.Geodatabase.IFeatureClassName Dim datasetName As ESRI.ArcGIS.Geodatabase.IDatasetName FCname = New ESRI.ArcGIS.Geodatabase.FeatureClassName datasetName = FCname newWSName = New ESRI.ArcGIS.Geodatabase.WorkspaceName newWSName.WorkspaceFactoryProgID = "esriCore.shapeFileWorkspaceFactory" newWSName.PathName = "C:\GEO531\Day10\Lab10_Data"
datasetName.WorkspaceName = newWSName datasetName.Name = "clip_result1"
'perform clip Dim bGP As ESRI.ArcGIS.Carto.IBasicGeoprocessor Dim tol As Double Dim outputFC As ESRI.ArcGIS.Geodatabase.FeatureClass
'define a basic geoprocesssing object bGP = New ESRI.ArcGIS.Carto.BasicGeoprocessor 'use the default tolerance tol = 0.0# 'run clip outputFC = bGP.Clip(inputFC, False, overlayFC, False, tol, FCname)
'create the output layer and add it the active map Dim name As ESRI.ArcGIS.esriSystem.IName Dim clipFC As ESRI.ArcGIS.Geodatabase.IFeatureClass Dim clipFL As ESRI.ArcGIS.Carto.IFeatureLayer name = FCname clipFC = name.Open clipFL = New ESRI.ArcGIS.Carto.FeatureLayer clipFL.FeatureClass = outputFC clipFL.Name = " clip_Result2" map.AddLayer(clipFL)
At the risk of being anoying this is a completely different question and has nothing to do with your original question. New questions must be asked on new posts. Anyone researching a similar problem as to your first question will simply find this post useless and contributes nothing to the user community. Did you solve the original problem? If so post an answer!
Suggest you delete this question and repost in a new thread.
Les membres connectés peuvent publier, suivre les mises à jour, et plus encore. Nouveau ici ? Inscrivez-vous gratuitement.
Find useful guides, FAQs, and documents to help you navigate and make the most of Esri Community.