3

I have a feature class with 3 fields that I would like to reference later in an excel workbook. They are all represented in 3 different maps. I would like to show the the attribute counts for these 3 fields in Excel. The purpose of this is to ultimatelly create an automated process with Adobe Indesign for map book creation.

The ideal process would be:

  1. Select feature class attribute to be shown on map.
  2. Python automation to show the number of features displayed on map, written to text file or excel workbook.
  3. I don't want every column or row written, only the attribute displayed in layout or data view in ArcGIS.
  4. I would like to complete this from the Python window in ArcGIS for QA/QC purposes.

closed as too broad by PolyGeo, Fezter, BradHards, Devdatta Tengshe, Curlew Jan 8 '14 at 9:40

Please edit the question to limit it to a specific problem with enough detail to identify an adequate answer. Avoid asking multiple distinct questions at once. See the How to Ask page for help clarifying this question. If this question can be reworded to fit the rules in the help center, please edit the question.

  • Can you describe the desired output a little more, preferably with an example of both the input and the output? – blah238 Jan 7 '14 at 17:58
  • 1
    Are you just trying to get counts of unique values in a particular field from a featureclass? If so, I think you could just use the Summary Statistics or Frequency tools and write the results out to Excel using Table To Excel. – RyanDalton Jan 7 '14 at 18:07
  • The ultimate output should show the count of each attribute shown on a map, akin to the show feature count option within the legend. The summary statistics tool does not meet the needs of this process. As when it is executed it shows the total count, not count of each category. For instance, if there are 5 As 5 Bs 10 Cs 15 Ds, I would like to print the parsed attribute fields and the count to excel rows. – Geoffrey West Jan 7 '14 at 18:37
  • What version of ArcGIS for Desktop are you using? I ask because the export to Excel is easier at 10.2. – PolyGeo Jan 7 '14 at 19:10
  • 1
    @GeoffreyWest it's those kinds of "little" requirements that should be stated up front (and edited into the question instead of snuck into the comments). I believe xlwt will let you do this but most of the other options mentioned here so far will not. Though looking a little bit into InDesign scripting I do not see why Excel is needed at all, so perhaps you could explain why it is important to use it as opposed to some other format. – blah238 Jan 7 '14 at 22:12
2

You can use: arcpy.MakeFeatureLayer_management() and arcpy.SelectLayerByAttribute_management() to select the features you want. Then use: arcpy.GetCount_management tool to get a count of the selected objects. Using XLRD you can write to excel or just use:

outfile = open('OUT_TEXT_FILE.txt','w')
outfile.write("write the first line here" + "\n")
outfile.write("write the second line here" + "\n")
..
..
outfile.write("write the nth line here" + "\n")
outfile.close()

This will write to a new txt file - be careful - if the text file already exists - it will overwrite - to append use 'a' instead of the 'w' in the open command.

Not the answer you're looking for? Browse other questions tagged or ask your own question.