1

I'm new to arcgis and arcpy, so some of my lingo and terminology may be off. I have a script that takes a feature layer as an ainput. From there I want to be able to count the number of selections in the feature layer. I also want to determine what type of layer it is, i.e. polygon, polyline, point, etc. Again, my terminology may be off. Can anyone help me with this??

1 Answer 1

4

To determine the feature type, you use describe to create a describe object of the feature layer and then use the shapeType property of the describe object. http://resources.arcgis.com/en/help/main/10.1/index.html#/FeatureClass_properties/018v00000011000000/ This is a modified example from that page:

import arcpy
# Create a Describe object from the feature class
#
desc = arcpy.Describe("C:/data/arch.dgn/Point")
# Print the shape type
#
print "Shape Type :   " + desc.shapeType

If you only have the feature layer, then you need to use the featureClass object of the feature layer. Another modified example, based on http://resources.arcgis.com/en/help/main/10.1/index.html#/Layer_properties/018v00000063000000/

import arcpy
# Create an in memory feature layer from a feature class.
#
arcpy.MakeFeatureLayer_management(
        "C:/data/chesapeake.gdb/bayshed",
        "mainlines_layer")
# Create a Describe object from the feature layer.
#
desc = arcpy.Describe("mainlines_layer")
# Print the shape type
#
print "Feature Class Shape type: " + desc.featureClass.shapeType

To get a count of selected records, you just use the Get Count (Data Management) tool. You have to use the result object though to get the value. http://help.arcgis.com/en/arcgisdesktop/10.0/help/index.html#//0017000000n7000000

count = int(arcpy.GetCount_management("Reference to layer").getOutput(0))

Get Count will return the number of selected features if there is a selection. If there is not a selection, it will return the count of all of the features in the layer.

1
  • Thanks a lot for your help. I added the suggested lines and it worked. Also gave me a better insight to arcpy and to feature layers. Thanks again! Mar 12, 2013 at 21:36

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

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