Select to view content in your preferred language

How to Load FeatureClass in ArcMap with Python

742
3
08-18-2012 09:35 AM
Angel_ReynaldoCardenas_Huerta
Deactivated User
Hello.

I am making an application for ArcGIS 10 in which auto-load features and can process, the form the QtDesinger do with the coding I'm doing it with eclipse, and I want to run everything within the ArcMap ...
I have some doubts

1. - As I make a shortcut from ArcMap to this application, something like a toolbox of a button
2. - how to load featureclass from form with python?
3. - Any tutorials on these topics somewhat advanced geoprocessing, I extract the coordinates of some features, add features (polygons), see if one of them overlaps with other ...

I had all this in VBA but it turns out that in future versions crrera not, because the ESRI will not support VBA, then do it again after python ...

thank you very much in advance for your answers and help ..

excuse the bad language, but I speak Spanish
Angel Cardenas H.
Tags (2)
0 Kudos
3 Replies
ChristopherThompson
Frequent Contributor
You want to look into the arcpy.mapping capabilities for some of this.  Generally I think what you are going to find is that you need to work with an existing map as arcpy can't open a new MXD, and then you have to add a layer from an existing layer file (.lyr) that is on disk.  Sort of a pain if you have lots of feature classes but no .lyr layers.  You could do something in the following manner though:

  • use arcpy.mapping 'open' a map document (that would be mapdoc = arcpy.mappping.MapDocument('path to your mxd')
  • use arcpy.SaveToLayerFile function to create your layers - you may have to figure out how to do this programmatically

  • use arcpy.mapping.AddLayer function to add the .lyr layers to your map.

Its a bit of a runaround but it should work for you.  Of course the devil is in the details with this sort of thing, and a lot depends on how yoru data are filed and then what you want to actually do with those layers in a geoprocessing context.
an intro to Arcpy including the mapping module is here:
http://resources.arcgis.com/en/help/main/10.1/index.html#//000v00000001000000#GUID-4EC90E5F-F497-4FC...

One thing I'm curious of - since you already have this procedure coded in VBA, would it be possible to port that over to VB.net? Seems you would have fewer issues refactoring the code that way than completely redoing it in Python.
0 Kudos
KenCarrier
Deactivated User
I agree with Christopher, porting your VBA to VB.NET might be easier to do considering your familiarity and comfort with VB. The other option is to create a python add-in at 10.1.

1. In the initialize event of a combobox you could read the layer files into the combobox from a place on disk.
2. In the selection event, you could write the code to add the layer to the map. Then if necessary do anything else you need.
0 Kudos
Angel_ReynaldoCardenas_Huerta
Deactivated User
thank you very much for your answers and Ken Christopher, achieve load the feature class to ArcMap, but I had a problem, and it will not let me upload it again because I created entities, which can not be repeated, the code I use is

arcpy.makefeaturelayer_management ("path or featureclass", "alias")

there is another way to do this without my block to add again the same featureclass?

the other inconsistency I had is that I arcgis10 hangs, and the program runs only a short time within ArcMap

a query, how I would spend my VBA code to. NET and then load it as dll or tlb?

thanks in advance

Angel Cardenas
0 Kudos