Selecting just the first row from a search cursorSearch cursor stops selecting after two iterationsUsing...

Forgetting the musical notes while performing in concert

What is required to make GPS signals available indoors?

Finitely generated matrix groups whose eigenvalues are all algebraic

Is it "common practice in Fourier transform spectroscopy to multiply the measured interferogram by an apodizing function"? If so, why?

Can a virus destroy the BIOS of a modern computer?

Avoiding the "not like other girls" trope?

Does the Idaho Potato Commission associate potato skins with healthy eating?

What are the G forces leaving Earth orbit?

Did 'Cinema Songs' exist during Hiranyakshipu's time?

Car headlights in a world without electricity

What's the meaning of "Sollensaussagen"?

Where would I need my direct neural interface to be implanted?

In Bayesian inference, why are some terms dropped from the posterior predictive?

What is the opposite of "eschatology"?

What Exploit Are These User Agents Trying to Use?

What do you call someone who asks many questions?

Why was the shrink from 8″ made only to 5.25″ and not smaller (4″ or less)

Do creatures with a speed 0ft., fly 30ft. (hover) ever touch the ground?

Why is the sentence "Das ist eine Nase" correct?

My ex-girlfriend uses my Apple ID to login to her iPad, do I have to give her my Apple ID password to reset it?

How do conventional missiles fly?

Machine learning testing data

How to travel to Japan while expressing milk?

Convert seconds to minutes



Selecting just the first row from a search cursor


Search cursor stops selecting after two iterationsUsing arcpy.da.InsertCursor to insert entire row that is fetched from search cursor?Insert cursor for first row in unique value set arcpyOutput the Search Cursor as a stringCursor update row operatorUsing Search/Update Cursor?Stratified random point sampling in PythonComparing value with value from the next rowDeleting row using ArcPy cursor?Switching from Nested Search Cursors to Dictionaries













0















Currently I am trying to select the top row of a feature class which is sorted using a Count field. I then would like to run the script a second time but the result will then be the second row of the table. I currently have the script below.



#import arcpy module
import arcpy
from arcpy import env

env.workspace = "D:\Trimble.gdb"

#allow overwrites
arcpy.env.overwriteOutput = True

#print list of feature classes
featList = arcpy.ListFeatureClasses()
print featList

#cheack if Messages and Township spatial join has been made
for feat in featList:
if arcpy.Exists("TWP_Messages"):
print "Township and Messages Without Roads joined already"
print ""
break
else:
#create spatial join between Messages and Townships
target_features = "D:\Trimble.gdb\TWP"
join_features = "D:\Trimble.gdb\Messages"
out_feature = "D:\Trimble.gdb\TWP_Messages"
arcpy.SpatialJoin_analysis(target_features, join_features, out_feature)

#sort Join_Count field by Descending
arcpy.Sort_management("TWP_Messages", "TWP_Messages_Sort", [["Count_", "DESCENDING"]])
print arcpy.GetMessage(2)
messageSort = "D:\Trimble.gdb\TWP_Messages_Sort"

#add field to messages sort feature to describe if item has been deleted already
arcpy.AddField_management(messageSort, "Downloaded", "TEXT")
#update all Downloaded fields to No
with arcpy.da.UpdateCursor(messageSort, "Downloaded") as cursor:
for row in cursor:
row[0] = "No"
cursor.updateRow(row)
del row
del cursor

messageSorted = "D:\Trimble.gdb\TWP_Messages_Sort"
i = 0
with arcpy.da.SearchCursor(messageSorted, ["DESCRIPTOR", "Count_"]) as cursor:
for row in cursor:
if row[1] != i:
print("Descriptor: {} Count: {}".format(row[0], row[1]))
i = row[1]
name = row[0]
with arcpy.da.UpdateCursor(messageSorted, ["Count_", "Downloaded"]) as curs:
for line in curs:
if line[0] == i:
line[1] = "Yes"
curs.updateRow(line)
break

print name


Currently it is rewriting the fields it updates (Downloaded) every time and does not remember where it left off. Obviously the break is causing a problem here too.



I thought about making a table that updates each item that has previously been selected so then the search could check there and continue on to the next needed row. Unsure how to implement that too.



I appreciate any help you're able to give.









share



























    0















    Currently I am trying to select the top row of a feature class which is sorted using a Count field. I then would like to run the script a second time but the result will then be the second row of the table. I currently have the script below.



    #import arcpy module
    import arcpy
    from arcpy import env

    env.workspace = "D:\Trimble.gdb"

    #allow overwrites
    arcpy.env.overwriteOutput = True

    #print list of feature classes
    featList = arcpy.ListFeatureClasses()
    print featList

    #cheack if Messages and Township spatial join has been made
    for feat in featList:
    if arcpy.Exists("TWP_Messages"):
    print "Township and Messages Without Roads joined already"
    print ""
    break
    else:
    #create spatial join between Messages and Townships
    target_features = "D:\Trimble.gdb\TWP"
    join_features = "D:\Trimble.gdb\Messages"
    out_feature = "D:\Trimble.gdb\TWP_Messages"
    arcpy.SpatialJoin_analysis(target_features, join_features, out_feature)

    #sort Join_Count field by Descending
    arcpy.Sort_management("TWP_Messages", "TWP_Messages_Sort", [["Count_", "DESCENDING"]])
    print arcpy.GetMessage(2)
    messageSort = "D:\Trimble.gdb\TWP_Messages_Sort"

    #add field to messages sort feature to describe if item has been deleted already
    arcpy.AddField_management(messageSort, "Downloaded", "TEXT")
    #update all Downloaded fields to No
    with arcpy.da.UpdateCursor(messageSort, "Downloaded") as cursor:
    for row in cursor:
    row[0] = "No"
    cursor.updateRow(row)
    del row
    del cursor

    messageSorted = "D:\Trimble.gdb\TWP_Messages_Sort"
    i = 0
    with arcpy.da.SearchCursor(messageSorted, ["DESCRIPTOR", "Count_"]) as cursor:
    for row in cursor:
    if row[1] != i:
    print("Descriptor: {} Count: {}".format(row[0], row[1]))
    i = row[1]
    name = row[0]
    with arcpy.da.UpdateCursor(messageSorted, ["Count_", "Downloaded"]) as curs:
    for line in curs:
    if line[0] == i:
    line[1] = "Yes"
    curs.updateRow(line)
    break

    print name


    Currently it is rewriting the fields it updates (Downloaded) every time and does not remember where it left off. Obviously the break is causing a problem here too.



    I thought about making a table that updates each item that has previously been selected so then the search could check there and continue on to the next needed row. Unsure how to implement that too.



    I appreciate any help you're able to give.









    share

























      0












      0








      0








      Currently I am trying to select the top row of a feature class which is sorted using a Count field. I then would like to run the script a second time but the result will then be the second row of the table. I currently have the script below.



      #import arcpy module
      import arcpy
      from arcpy import env

      env.workspace = "D:\Trimble.gdb"

      #allow overwrites
      arcpy.env.overwriteOutput = True

      #print list of feature classes
      featList = arcpy.ListFeatureClasses()
      print featList

      #cheack if Messages and Township spatial join has been made
      for feat in featList:
      if arcpy.Exists("TWP_Messages"):
      print "Township and Messages Without Roads joined already"
      print ""
      break
      else:
      #create spatial join between Messages and Townships
      target_features = "D:\Trimble.gdb\TWP"
      join_features = "D:\Trimble.gdb\Messages"
      out_feature = "D:\Trimble.gdb\TWP_Messages"
      arcpy.SpatialJoin_analysis(target_features, join_features, out_feature)

      #sort Join_Count field by Descending
      arcpy.Sort_management("TWP_Messages", "TWP_Messages_Sort", [["Count_", "DESCENDING"]])
      print arcpy.GetMessage(2)
      messageSort = "D:\Trimble.gdb\TWP_Messages_Sort"

      #add field to messages sort feature to describe if item has been deleted already
      arcpy.AddField_management(messageSort, "Downloaded", "TEXT")
      #update all Downloaded fields to No
      with arcpy.da.UpdateCursor(messageSort, "Downloaded") as cursor:
      for row in cursor:
      row[0] = "No"
      cursor.updateRow(row)
      del row
      del cursor

      messageSorted = "D:\Trimble.gdb\TWP_Messages_Sort"
      i = 0
      with arcpy.da.SearchCursor(messageSorted, ["DESCRIPTOR", "Count_"]) as cursor:
      for row in cursor:
      if row[1] != i:
      print("Descriptor: {} Count: {}".format(row[0], row[1]))
      i = row[1]
      name = row[0]
      with arcpy.da.UpdateCursor(messageSorted, ["Count_", "Downloaded"]) as curs:
      for line in curs:
      if line[0] == i:
      line[1] = "Yes"
      curs.updateRow(line)
      break

      print name


      Currently it is rewriting the fields it updates (Downloaded) every time and does not remember where it left off. Obviously the break is causing a problem here too.



      I thought about making a table that updates each item that has previously been selected so then the search could check there and continue on to the next needed row. Unsure how to implement that too.



      I appreciate any help you're able to give.









      share














      Currently I am trying to select the top row of a feature class which is sorted using a Count field. I then would like to run the script a second time but the result will then be the second row of the table. I currently have the script below.



      #import arcpy module
      import arcpy
      from arcpy import env

      env.workspace = "D:\Trimble.gdb"

      #allow overwrites
      arcpy.env.overwriteOutput = True

      #print list of feature classes
      featList = arcpy.ListFeatureClasses()
      print featList

      #cheack if Messages and Township spatial join has been made
      for feat in featList:
      if arcpy.Exists("TWP_Messages"):
      print "Township and Messages Without Roads joined already"
      print ""
      break
      else:
      #create spatial join between Messages and Townships
      target_features = "D:\Trimble.gdb\TWP"
      join_features = "D:\Trimble.gdb\Messages"
      out_feature = "D:\Trimble.gdb\TWP_Messages"
      arcpy.SpatialJoin_analysis(target_features, join_features, out_feature)

      #sort Join_Count field by Descending
      arcpy.Sort_management("TWP_Messages", "TWP_Messages_Sort", [["Count_", "DESCENDING"]])
      print arcpy.GetMessage(2)
      messageSort = "D:\Trimble.gdb\TWP_Messages_Sort"

      #add field to messages sort feature to describe if item has been deleted already
      arcpy.AddField_management(messageSort, "Downloaded", "TEXT")
      #update all Downloaded fields to No
      with arcpy.da.UpdateCursor(messageSort, "Downloaded") as cursor:
      for row in cursor:
      row[0] = "No"
      cursor.updateRow(row)
      del row
      del cursor

      messageSorted = "D:\Trimble.gdb\TWP_Messages_Sort"
      i = 0
      with arcpy.da.SearchCursor(messageSorted, ["DESCRIPTOR", "Count_"]) as cursor:
      for row in cursor:
      if row[1] != i:
      print("Descriptor: {} Count: {}".format(row[0], row[1]))
      i = row[1]
      name = row[0]
      with arcpy.da.UpdateCursor(messageSorted, ["Count_", "Downloaded"]) as curs:
      for line in curs:
      if line[0] == i:
      line[1] = "Yes"
      curs.updateRow(line)
      break

      print name


      Currently it is rewriting the fields it updates (Downloaded) every time and does not remember where it left off. Obviously the break is causing a problem here too.



      I thought about making a table that updates each item that has previously been selected so then the search could check there and continue on to the next needed row. Unsure how to implement that too.



      I appreciate any help you're able to give.







      arcpy





      share












      share










      share



      share










      asked 6 mins ago









      BenjamBenjam

      155




      155






















          0






          active

          oldest

          votes












          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%2f317568%2fselecting-just-the-first-row-from-a-search-cursor%23new-answer', 'question_page');
          }
          );

          Post as a guest















          Required, but never shown

























          0






          active

          oldest

          votes








          0






          active

          oldest

          votes









          active

          oldest

          votes






          active

          oldest

          votes
















          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%2f317568%2fselecting-just-the-first-row-from-a-search-cursor%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 Классификация | Примечания | Ссылки |...

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

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