Fastest way to count the number of features in a feature class?Is there a way to show a layers feature count...

4 Spheres all touching each other??

If all harmonics are generated by plucking, how does a guitar string produce a pure frequency sound?

Do commercial flights continue with an engine out?

What is the purpose of easy combat scenarios that don't need resource expenditure?

Is my plan for fixing my water heater leak bad?

Why didn't Eru and/or the Valar intervene when Sauron corrupted Númenor?

How to push a box with physics engine by another object?

Activating a Alphanet Faucet Wallet Remotely (without tezos-client)

What was the population of late Pre-Islamic Arabia and the population of Arabic speakers before Islam?

How to add multiple differently colored borders around a node?

c++ How can I make an algorithm for finding variations of a set without repetition (i.e. n elements, choose k)?

How to properly claim credit for peer review?

Which branches of mathematics can be done just in terms of morphisms and composition?

Is the theory of the category of topological spaces computable?

Dilemma of explaining to interviewer that he is the reason for declining second interview

Linux File Manager: Restore previous open session (folders and tab)

Two functions in the same line

Crystal compensation for temp and voltage

Do any poskim exempt 13-20-year-olds from Mussaf?

Can a person refuse a presidential pardon?

How can I improve my fireworks photography?

Why do members of Congress in committee hearings ask witnesses the same question multiple times?

How to roast potatoes in the oven to make them crispy?

How do I add a variable to this curl command?



Fastest way to count the number of features in a feature class?


Is there a way to show a layers feature count in the TOC?Why does arcpy.ListFeatureClasses() take so incredibly long?Merge Spatially Coincident Features in the Same Feature ClassAny case when one must use older ArcPy cursors (not da module based)?Using arcpy.da.InsertCursor to insert entire row that is fetched from search cursor?Searching Geodatabase for Feature Class or Table by its name?How is the data access cursor performance so enhanced compared to previous versions?Comparing geometries using Search CursorsUsing SQL statement with ArcPy?Selecting features in an ArcGIS attribute table based on values of other features in the same table using SQLRead SDE Feature Attributes without ArcpyUse ArcPy/Python to print out the number of selected features based on different selection criteria













34















With the introduction of the Data Access module in arcpy (30x faster search cursors), I want to know if counting features matching sql criteria is faster than the traditional MakeTableView + GetCount methodology?










share|improve this question




















  • 12





    How stupid is it that the feature count isn't just a property of an arcpy.Describe object

    – Grant Humphries
    Sep 4 '13 at 20:24











  • This was pretty easy with ogrinfo with some OGR SQL. The dataset has something like 170000 records, and this wildcard search on an unindexed VARCHAR field came back in just a few seconds. ogrinfo "C:xGISVectorparcelsparcels_20140829_pmerc.ovf -sql "SELECT count(*) FROM parcels_20140829_pmerc WHERE tms like 'R39200-02-%'"

    – elrobis
    Sep 26 '14 at 13:54
















34















With the introduction of the Data Access module in arcpy (30x faster search cursors), I want to know if counting features matching sql criteria is faster than the traditional MakeTableView + GetCount methodology?










share|improve this question




















  • 12





    How stupid is it that the feature count isn't just a property of an arcpy.Describe object

    – Grant Humphries
    Sep 4 '13 at 20:24











  • This was pretty easy with ogrinfo with some OGR SQL. The dataset has something like 170000 records, and this wildcard search on an unindexed VARCHAR field came back in just a few seconds. ogrinfo "C:xGISVectorparcelsparcels_20140829_pmerc.ovf -sql "SELECT count(*) FROM parcels_20140829_pmerc WHERE tms like 'R39200-02-%'"

    – elrobis
    Sep 26 '14 at 13:54














34












34








34


13






With the introduction of the Data Access module in arcpy (30x faster search cursors), I want to know if counting features matching sql criteria is faster than the traditional MakeTableView + GetCount methodology?










share|improve this question
















With the introduction of the Data Access module in arcpy (30x faster search cursors), I want to know if counting features matching sql criteria is faster than the traditional MakeTableView + GetCount methodology?







arcgis-desktop arcpy arcgis-10.1 performance






share|improve this question















share|improve this question













share|improve this question




share|improve this question








edited Oct 16 '13 at 5:25









PolyGeo

53.6k1780240




53.6k1780240










asked Jul 23 '12 at 18:52









Michael MarkietaMichael Markieta

3,63542958




3,63542958








  • 12





    How stupid is it that the feature count isn't just a property of an arcpy.Describe object

    – Grant Humphries
    Sep 4 '13 at 20:24











  • This was pretty easy with ogrinfo with some OGR SQL. The dataset has something like 170000 records, and this wildcard search on an unindexed VARCHAR field came back in just a few seconds. ogrinfo "C:xGISVectorparcelsparcels_20140829_pmerc.ovf -sql "SELECT count(*) FROM parcels_20140829_pmerc WHERE tms like 'R39200-02-%'"

    – elrobis
    Sep 26 '14 at 13:54














  • 12





    How stupid is it that the feature count isn't just a property of an arcpy.Describe object

    – Grant Humphries
    Sep 4 '13 at 20:24











  • This was pretty easy with ogrinfo with some OGR SQL. The dataset has something like 170000 records, and this wildcard search on an unindexed VARCHAR field came back in just a few seconds. ogrinfo "C:xGISVectorparcelsparcels_20140829_pmerc.ovf -sql "SELECT count(*) FROM parcels_20140829_pmerc WHERE tms like 'R39200-02-%'"

    – elrobis
    Sep 26 '14 at 13:54








12




12





How stupid is it that the feature count isn't just a property of an arcpy.Describe object

– Grant Humphries
Sep 4 '13 at 20:24





How stupid is it that the feature count isn't just a property of an arcpy.Describe object

– Grant Humphries
Sep 4 '13 at 20:24













This was pretty easy with ogrinfo with some OGR SQL. The dataset has something like 170000 records, and this wildcard search on an unindexed VARCHAR field came back in just a few seconds. ogrinfo "C:xGISVectorparcelsparcels_20140829_pmerc.ovf -sql "SELECT count(*) FROM parcels_20140829_pmerc WHERE tms like 'R39200-02-%'"

– elrobis
Sep 26 '14 at 13:54





This was pretty easy with ogrinfo with some OGR SQL. The dataset has something like 170000 records, and this wildcard search on an unindexed VARCHAR field came back in just a few seconds. ogrinfo "C:xGISVectorparcelsparcels_20140829_pmerc.ovf -sql "SELECT count(*) FROM parcels_20140829_pmerc WHERE tms like 'R39200-02-%'"

– elrobis
Sep 26 '14 at 13:54










2 Answers
2






active

oldest

votes


















46














I am using an example with 1 million randomly generated points inside of a filegeodatabase. Attached here.



Here is some code to get us started:



import time
import arcpy

arcpy.env.workspace = "C:CountTest.gdb"

time.sleep(5) # Let the cpu/ram calm before proceeding!

"""Method 1"""
StartTime = time.clock()
with arcpy.da.SearchCursor("RandomPoints", ["OBJECTID"]) as cursor:
rows = {row[0] for row in cursor}

count = 0
for row in rows:
count += 1

EndTime = time.clock()
print "Finished in %s seconds" % (EndTime - StartTime)
print "%s features" % count

time.sleep(5) # Let the cpu/ram calm before proceeding!

"""Method 2"""
StartTime2 = time.clock()
arcpy.MakeTableView_management("RandomPoints", "myTableView")
count = int(arcpy.GetCount_management("myTableView").getOutput(0))

EndTime2 = time.clock()
print "Finished in %s seconds" % (EndTime2 - StartTime2)
print "%s features" % count


And some initial results:



>>> 
Finished in 6.75540050237 seconds
1000000 features
Finished in 0.801474780332 seconds
1000000 features
>>> =============================== RESTART ===============================
>>>
Finished in 6.56968596918 seconds
1000000 features
Finished in 0.812731769756 seconds
1000000 features
>>> =============================== RESTART ===============================
>>>
Finished in 6.58207512487 seconds
1000000 features
Finished in 0.841122157314 seconds
1000000 features


Imagine larger, more complex datasets. The SearchCursor will indefinitely crawl.



I am not at all dissatisfied with the results, however, the DataAccess module is being used extensively in our GIS development circle. I am looking to rebuild some of our function definitions with this module as it is more flexible than a MakeTableView + GetCount methodology.






share|improve this answer
























  • Nice roundup. For completeness sake I'd like to add what IMO should be fastest, but is in fact the slowest method (10x slower). arcpy.Statistics_analysis("RandomPoints", r"in_memorycount", [["OBJECTID", "COUNT"]]) cursor = arcpy.da.SearchCursor(r"in_memorycount", ["COUNT_OBJECTID"]) row = cursor.next() del cursor count = row[0]

    – Berend
    Jun 11 '15 at 14:57



















0














I have tested solution from answer above and on my real world data the difference is negligible. Opposite to results in other answer, my times for arcpy.MakeTableView_management and arcpy.da.SearchCursor within ArcMap are same same.



I have tested variations with and without query, please see the code for query version, and final measured results below:



@staticmethod
def query_features(feature_class, query):

# Method 1
time.sleep(5) # Let the cpu/ram calm before proceeding!
start_time = time.clock()
count = len(list(i for i in arcpy.da.SearchCursor(feature_class, ["OBJECTID"], query)))
end_time = time.clock()
arcpy.AddMessage("Method 1 finished in {} seconds".format((end_time - start_time)))
arcpy.AddMessage("{} features".format(count))

# Method 2
time.sleep(5) # Let the cpu/ram calm before proceeding!
start_time = time.clock()
arcpy.MakeTableView_management(feature_class, "myTableView", query)
count = int(arcpy.GetCount_management("myTableView").getOutput(0))

end_time = time.clock()
arcpy.AddMessage("Method 2 in {} seconds".format((end_time - start_time)))
arcpy.AddMessage("{} features".format(count))


The results below:



    No query:
Method 1 finished in 5.3616442 seconds
804140 features
Method 2 in 4.2843138 seconds
804140 features

Many results query:
Method 1 finished in 12.7124766 seconds
518852 features
Method 2 in 12.1396602 seconds
518852 features

Few results query:
Method 1 finished in 11.1421476 seconds
8 features
Method 2 in 11.2232503 seconds
8 features




share























    Your Answer








    StackExchange.ready(function() {
    var channelOptions = {
    tags: "".split(" "),
    id: "79"
    };
    initTagRenderer("".split(" "), "".split(" "), channelOptions);

    StackExchange.using("externalEditor", function() {
    // Have to fire editor after snippets, if snippets enabled
    if (StackExchange.settings.snippets.snippetsEnabled) {
    StackExchange.using("snippets", function() {
    createEditor();
    });
    }
    else {
    createEditor();
    }
    });

    function createEditor() {
    StackExchange.prepareEditor({
    heartbeatType: 'answer',
    autoActivateHeartbeat: false,
    convertImagesToLinks: false,
    noModals: true,
    showLowRepImageUploadWarning: true,
    reputationToPostImages: null,
    bindNavPrevention: true,
    postfix: "",
    imageUploader: {
    brandingHtml: "Powered by u003ca class="icon-imgur-white" href="https://imgur.com/"u003eu003c/au003e",
    contentPolicyHtml: "User contributions licensed under u003ca href="https://creativecommons.org/licenses/by-sa/3.0/"u003ecc by-sa 3.0 with attribution requiredu003c/au003e u003ca href="https://stackoverflow.com/legal/content-policy"u003e(content policy)u003c/au003e",
    allowUrls: true
    },
    onDemand: true,
    discardSelector: ".discard-answer"
    ,immediatelyShowMarkdownHelp:true
    });


    }
    });














    draft saved

    draft discarded


















    StackExchange.ready(
    function () {
    StackExchange.openid.initPostLogin('.new-post-login', 'https%3a%2f%2fgis.stackexchange.com%2fquestions%2f30140%2ffastest-way-to-count-the-number-of-features-in-a-feature-class%23new-answer', 'question_page');
    }
    );

    Post as a guest















    Required, but never shown

























    2 Answers
    2






    active

    oldest

    votes








    2 Answers
    2






    active

    oldest

    votes









    active

    oldest

    votes






    active

    oldest

    votes









    46














    I am using an example with 1 million randomly generated points inside of a filegeodatabase. Attached here.



    Here is some code to get us started:



    import time
    import arcpy

    arcpy.env.workspace = "C:CountTest.gdb"

    time.sleep(5) # Let the cpu/ram calm before proceeding!

    """Method 1"""
    StartTime = time.clock()
    with arcpy.da.SearchCursor("RandomPoints", ["OBJECTID"]) as cursor:
    rows = {row[0] for row in cursor}

    count = 0
    for row in rows:
    count += 1

    EndTime = time.clock()
    print "Finished in %s seconds" % (EndTime - StartTime)
    print "%s features" % count

    time.sleep(5) # Let the cpu/ram calm before proceeding!

    """Method 2"""
    StartTime2 = time.clock()
    arcpy.MakeTableView_management("RandomPoints", "myTableView")
    count = int(arcpy.GetCount_management("myTableView").getOutput(0))

    EndTime2 = time.clock()
    print "Finished in %s seconds" % (EndTime2 - StartTime2)
    print "%s features" % count


    And some initial results:



    >>> 
    Finished in 6.75540050237 seconds
    1000000 features
    Finished in 0.801474780332 seconds
    1000000 features
    >>> =============================== RESTART ===============================
    >>>
    Finished in 6.56968596918 seconds
    1000000 features
    Finished in 0.812731769756 seconds
    1000000 features
    >>> =============================== RESTART ===============================
    >>>
    Finished in 6.58207512487 seconds
    1000000 features
    Finished in 0.841122157314 seconds
    1000000 features


    Imagine larger, more complex datasets. The SearchCursor will indefinitely crawl.



    I am not at all dissatisfied with the results, however, the DataAccess module is being used extensively in our GIS development circle. I am looking to rebuild some of our function definitions with this module as it is more flexible than a MakeTableView + GetCount methodology.






    share|improve this answer
























    • Nice roundup. For completeness sake I'd like to add what IMO should be fastest, but is in fact the slowest method (10x slower). arcpy.Statistics_analysis("RandomPoints", r"in_memorycount", [["OBJECTID", "COUNT"]]) cursor = arcpy.da.SearchCursor(r"in_memorycount", ["COUNT_OBJECTID"]) row = cursor.next() del cursor count = row[0]

      – Berend
      Jun 11 '15 at 14:57
















    46














    I am using an example with 1 million randomly generated points inside of a filegeodatabase. Attached here.



    Here is some code to get us started:



    import time
    import arcpy

    arcpy.env.workspace = "C:CountTest.gdb"

    time.sleep(5) # Let the cpu/ram calm before proceeding!

    """Method 1"""
    StartTime = time.clock()
    with arcpy.da.SearchCursor("RandomPoints", ["OBJECTID"]) as cursor:
    rows = {row[0] for row in cursor}

    count = 0
    for row in rows:
    count += 1

    EndTime = time.clock()
    print "Finished in %s seconds" % (EndTime - StartTime)
    print "%s features" % count

    time.sleep(5) # Let the cpu/ram calm before proceeding!

    """Method 2"""
    StartTime2 = time.clock()
    arcpy.MakeTableView_management("RandomPoints", "myTableView")
    count = int(arcpy.GetCount_management("myTableView").getOutput(0))

    EndTime2 = time.clock()
    print "Finished in %s seconds" % (EndTime2 - StartTime2)
    print "%s features" % count


    And some initial results:



    >>> 
    Finished in 6.75540050237 seconds
    1000000 features
    Finished in 0.801474780332 seconds
    1000000 features
    >>> =============================== RESTART ===============================
    >>>
    Finished in 6.56968596918 seconds
    1000000 features
    Finished in 0.812731769756 seconds
    1000000 features
    >>> =============================== RESTART ===============================
    >>>
    Finished in 6.58207512487 seconds
    1000000 features
    Finished in 0.841122157314 seconds
    1000000 features


    Imagine larger, more complex datasets. The SearchCursor will indefinitely crawl.



    I am not at all dissatisfied with the results, however, the DataAccess module is being used extensively in our GIS development circle. I am looking to rebuild some of our function definitions with this module as it is more flexible than a MakeTableView + GetCount methodology.






    share|improve this answer
























    • Nice roundup. For completeness sake I'd like to add what IMO should be fastest, but is in fact the slowest method (10x slower). arcpy.Statistics_analysis("RandomPoints", r"in_memorycount", [["OBJECTID", "COUNT"]]) cursor = arcpy.da.SearchCursor(r"in_memorycount", ["COUNT_OBJECTID"]) row = cursor.next() del cursor count = row[0]

      – Berend
      Jun 11 '15 at 14:57














    46












    46








    46







    I am using an example with 1 million randomly generated points inside of a filegeodatabase. Attached here.



    Here is some code to get us started:



    import time
    import arcpy

    arcpy.env.workspace = "C:CountTest.gdb"

    time.sleep(5) # Let the cpu/ram calm before proceeding!

    """Method 1"""
    StartTime = time.clock()
    with arcpy.da.SearchCursor("RandomPoints", ["OBJECTID"]) as cursor:
    rows = {row[0] for row in cursor}

    count = 0
    for row in rows:
    count += 1

    EndTime = time.clock()
    print "Finished in %s seconds" % (EndTime - StartTime)
    print "%s features" % count

    time.sleep(5) # Let the cpu/ram calm before proceeding!

    """Method 2"""
    StartTime2 = time.clock()
    arcpy.MakeTableView_management("RandomPoints", "myTableView")
    count = int(arcpy.GetCount_management("myTableView").getOutput(0))

    EndTime2 = time.clock()
    print "Finished in %s seconds" % (EndTime2 - StartTime2)
    print "%s features" % count


    And some initial results:



    >>> 
    Finished in 6.75540050237 seconds
    1000000 features
    Finished in 0.801474780332 seconds
    1000000 features
    >>> =============================== RESTART ===============================
    >>>
    Finished in 6.56968596918 seconds
    1000000 features
    Finished in 0.812731769756 seconds
    1000000 features
    >>> =============================== RESTART ===============================
    >>>
    Finished in 6.58207512487 seconds
    1000000 features
    Finished in 0.841122157314 seconds
    1000000 features


    Imagine larger, more complex datasets. The SearchCursor will indefinitely crawl.



    I am not at all dissatisfied with the results, however, the DataAccess module is being used extensively in our GIS development circle. I am looking to rebuild some of our function definitions with this module as it is more flexible than a MakeTableView + GetCount methodology.






    share|improve this answer













    I am using an example with 1 million randomly generated points inside of a filegeodatabase. Attached here.



    Here is some code to get us started:



    import time
    import arcpy

    arcpy.env.workspace = "C:CountTest.gdb"

    time.sleep(5) # Let the cpu/ram calm before proceeding!

    """Method 1"""
    StartTime = time.clock()
    with arcpy.da.SearchCursor("RandomPoints", ["OBJECTID"]) as cursor:
    rows = {row[0] for row in cursor}

    count = 0
    for row in rows:
    count += 1

    EndTime = time.clock()
    print "Finished in %s seconds" % (EndTime - StartTime)
    print "%s features" % count

    time.sleep(5) # Let the cpu/ram calm before proceeding!

    """Method 2"""
    StartTime2 = time.clock()
    arcpy.MakeTableView_management("RandomPoints", "myTableView")
    count = int(arcpy.GetCount_management("myTableView").getOutput(0))

    EndTime2 = time.clock()
    print "Finished in %s seconds" % (EndTime2 - StartTime2)
    print "%s features" % count


    And some initial results:



    >>> 
    Finished in 6.75540050237 seconds
    1000000 features
    Finished in 0.801474780332 seconds
    1000000 features
    >>> =============================== RESTART ===============================
    >>>
    Finished in 6.56968596918 seconds
    1000000 features
    Finished in 0.812731769756 seconds
    1000000 features
    >>> =============================== RESTART ===============================
    >>>
    Finished in 6.58207512487 seconds
    1000000 features
    Finished in 0.841122157314 seconds
    1000000 features


    Imagine larger, more complex datasets. The SearchCursor will indefinitely crawl.



    I am not at all dissatisfied with the results, however, the DataAccess module is being used extensively in our GIS development circle. I am looking to rebuild some of our function definitions with this module as it is more flexible than a MakeTableView + GetCount methodology.







    share|improve this answer












    share|improve this answer



    share|improve this answer










    answered Jul 23 '12 at 18:52









    Michael MarkietaMichael Markieta

    3,63542958




    3,63542958













    • Nice roundup. For completeness sake I'd like to add what IMO should be fastest, but is in fact the slowest method (10x slower). arcpy.Statistics_analysis("RandomPoints", r"in_memorycount", [["OBJECTID", "COUNT"]]) cursor = arcpy.da.SearchCursor(r"in_memorycount", ["COUNT_OBJECTID"]) row = cursor.next() del cursor count = row[0]

      – Berend
      Jun 11 '15 at 14:57



















    • Nice roundup. For completeness sake I'd like to add what IMO should be fastest, but is in fact the slowest method (10x slower). arcpy.Statistics_analysis("RandomPoints", r"in_memorycount", [["OBJECTID", "COUNT"]]) cursor = arcpy.da.SearchCursor(r"in_memorycount", ["COUNT_OBJECTID"]) row = cursor.next() del cursor count = row[0]

      – Berend
      Jun 11 '15 at 14:57

















    Nice roundup. For completeness sake I'd like to add what IMO should be fastest, but is in fact the slowest method (10x slower). arcpy.Statistics_analysis("RandomPoints", r"in_memorycount", [["OBJECTID", "COUNT"]]) cursor = arcpy.da.SearchCursor(r"in_memorycount", ["COUNT_OBJECTID"]) row = cursor.next() del cursor count = row[0]

    – Berend
    Jun 11 '15 at 14:57





    Nice roundup. For completeness sake I'd like to add what IMO should be fastest, but is in fact the slowest method (10x slower). arcpy.Statistics_analysis("RandomPoints", r"in_memorycount", [["OBJECTID", "COUNT"]]) cursor = arcpy.da.SearchCursor(r"in_memorycount", ["COUNT_OBJECTID"]) row = cursor.next() del cursor count = row[0]

    – Berend
    Jun 11 '15 at 14:57













    0














    I have tested solution from answer above and on my real world data the difference is negligible. Opposite to results in other answer, my times for arcpy.MakeTableView_management and arcpy.da.SearchCursor within ArcMap are same same.



    I have tested variations with and without query, please see the code for query version, and final measured results below:



    @staticmethod
    def query_features(feature_class, query):

    # Method 1
    time.sleep(5) # Let the cpu/ram calm before proceeding!
    start_time = time.clock()
    count = len(list(i for i in arcpy.da.SearchCursor(feature_class, ["OBJECTID"], query)))
    end_time = time.clock()
    arcpy.AddMessage("Method 1 finished in {} seconds".format((end_time - start_time)))
    arcpy.AddMessage("{} features".format(count))

    # Method 2
    time.sleep(5) # Let the cpu/ram calm before proceeding!
    start_time = time.clock()
    arcpy.MakeTableView_management(feature_class, "myTableView", query)
    count = int(arcpy.GetCount_management("myTableView").getOutput(0))

    end_time = time.clock()
    arcpy.AddMessage("Method 2 in {} seconds".format((end_time - start_time)))
    arcpy.AddMessage("{} features".format(count))


    The results below:



        No query:
    Method 1 finished in 5.3616442 seconds
    804140 features
    Method 2 in 4.2843138 seconds
    804140 features

    Many results query:
    Method 1 finished in 12.7124766 seconds
    518852 features
    Method 2 in 12.1396602 seconds
    518852 features

    Few results query:
    Method 1 finished in 11.1421476 seconds
    8 features
    Method 2 in 11.2232503 seconds
    8 features




    share




























      0














      I have tested solution from answer above and on my real world data the difference is negligible. Opposite to results in other answer, my times for arcpy.MakeTableView_management and arcpy.da.SearchCursor within ArcMap are same same.



      I have tested variations with and without query, please see the code for query version, and final measured results below:



      @staticmethod
      def query_features(feature_class, query):

      # Method 1
      time.sleep(5) # Let the cpu/ram calm before proceeding!
      start_time = time.clock()
      count = len(list(i for i in arcpy.da.SearchCursor(feature_class, ["OBJECTID"], query)))
      end_time = time.clock()
      arcpy.AddMessage("Method 1 finished in {} seconds".format((end_time - start_time)))
      arcpy.AddMessage("{} features".format(count))

      # Method 2
      time.sleep(5) # Let the cpu/ram calm before proceeding!
      start_time = time.clock()
      arcpy.MakeTableView_management(feature_class, "myTableView", query)
      count = int(arcpy.GetCount_management("myTableView").getOutput(0))

      end_time = time.clock()
      arcpy.AddMessage("Method 2 in {} seconds".format((end_time - start_time)))
      arcpy.AddMessage("{} features".format(count))


      The results below:



          No query:
      Method 1 finished in 5.3616442 seconds
      804140 features
      Method 2 in 4.2843138 seconds
      804140 features

      Many results query:
      Method 1 finished in 12.7124766 seconds
      518852 features
      Method 2 in 12.1396602 seconds
      518852 features

      Few results query:
      Method 1 finished in 11.1421476 seconds
      8 features
      Method 2 in 11.2232503 seconds
      8 features




      share


























        0












        0








        0







        I have tested solution from answer above and on my real world data the difference is negligible. Opposite to results in other answer, my times for arcpy.MakeTableView_management and arcpy.da.SearchCursor within ArcMap are same same.



        I have tested variations with and without query, please see the code for query version, and final measured results below:



        @staticmethod
        def query_features(feature_class, query):

        # Method 1
        time.sleep(5) # Let the cpu/ram calm before proceeding!
        start_time = time.clock()
        count = len(list(i for i in arcpy.da.SearchCursor(feature_class, ["OBJECTID"], query)))
        end_time = time.clock()
        arcpy.AddMessage("Method 1 finished in {} seconds".format((end_time - start_time)))
        arcpy.AddMessage("{} features".format(count))

        # Method 2
        time.sleep(5) # Let the cpu/ram calm before proceeding!
        start_time = time.clock()
        arcpy.MakeTableView_management(feature_class, "myTableView", query)
        count = int(arcpy.GetCount_management("myTableView").getOutput(0))

        end_time = time.clock()
        arcpy.AddMessage("Method 2 in {} seconds".format((end_time - start_time)))
        arcpy.AddMessage("{} features".format(count))


        The results below:



            No query:
        Method 1 finished in 5.3616442 seconds
        804140 features
        Method 2 in 4.2843138 seconds
        804140 features

        Many results query:
        Method 1 finished in 12.7124766 seconds
        518852 features
        Method 2 in 12.1396602 seconds
        518852 features

        Few results query:
        Method 1 finished in 11.1421476 seconds
        8 features
        Method 2 in 11.2232503 seconds
        8 features




        share













        I have tested solution from answer above and on my real world data the difference is negligible. Opposite to results in other answer, my times for arcpy.MakeTableView_management and arcpy.da.SearchCursor within ArcMap are same same.



        I have tested variations with and without query, please see the code for query version, and final measured results below:



        @staticmethod
        def query_features(feature_class, query):

        # Method 1
        time.sleep(5) # Let the cpu/ram calm before proceeding!
        start_time = time.clock()
        count = len(list(i for i in arcpy.da.SearchCursor(feature_class, ["OBJECTID"], query)))
        end_time = time.clock()
        arcpy.AddMessage("Method 1 finished in {} seconds".format((end_time - start_time)))
        arcpy.AddMessage("{} features".format(count))

        # Method 2
        time.sleep(5) # Let the cpu/ram calm before proceeding!
        start_time = time.clock()
        arcpy.MakeTableView_management(feature_class, "myTableView", query)
        count = int(arcpy.GetCount_management("myTableView").getOutput(0))

        end_time = time.clock()
        arcpy.AddMessage("Method 2 in {} seconds".format((end_time - start_time)))
        arcpy.AddMessage("{} features".format(count))


        The results below:



            No query:
        Method 1 finished in 5.3616442 seconds
        804140 features
        Method 2 in 4.2843138 seconds
        804140 features

        Many results query:
        Method 1 finished in 12.7124766 seconds
        518852 features
        Method 2 in 12.1396602 seconds
        518852 features

        Few results query:
        Method 1 finished in 11.1421476 seconds
        8 features
        Method 2 in 11.2232503 seconds
        8 features





        share











        share


        share










        answered 5 mins ago









        MiroMiro

        5,18443461




        5,18443461






























            draft saved

            draft discarded




















































            Thanks for contributing an answer to Geographic Information Systems Stack Exchange!


            • Please be sure to answer the question. Provide details and share your research!

            But avoid



            • Asking for help, clarification, or responding to other answers.

            • Making statements based on opinion; back them up with references or personal experience.


            To learn more, see our tips on writing great answers.




            draft saved


            draft discarded














            StackExchange.ready(
            function () {
            StackExchange.openid.initPostLogin('.new-post-login', 'https%3a%2f%2fgis.stackexchange.com%2fquestions%2f30140%2ffastest-way-to-count-the-number-of-features-in-a-feature-class%23new-answer', 'question_page');
            }
            );

            Post as a guest















            Required, but never shown





















































            Required, but never shown














            Required, but never shown












            Required, but never shown







            Required, but never shown

































            Required, but never shown














            Required, but never shown












            Required, but never shown







            Required, but never shown







            Popular posts from this blog

            (145452) 2005 RN43 Классификация | Примечания | Ссылки |...

            Щит и меч (фильм) Содержание Названия серий | Сюжет |...

            Энтрерриос (город) Содержание История | Географическое...