Take the 2-minute tour ×
Geographic Information Systems Stack Exchange is a question and answer site for cartographers, geographers and GIS professionals. It's 100% free, no registration required.

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??

share|improve this question
add comment

1 Answer

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.

share|improve this answer
    
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! –  user1898629 Mar 12 '13 at 21:36
    
Remember to accept the answer as correct if it is :) Glad it worked! –  blord-castillo Mar 13 '13 at 13:15
add comment

Your Answer

 
discard

By posting your answer, you agree to the privacy policy and terms of service.

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