<?xml version="1.0" encoding="UTF-8"?>
<rss xmlns:content="http://purl.org/rss/1.0/modules/content/" xmlns:dc="http://purl.org/dc/elements/1.1/" xmlns:rdf="http://www.w3.org/1999/02/22-rdf-syntax-ns#" xmlns:taxo="http://purl.org/rss/1.0/modules/taxonomy/" version="2.0">
  <channel>
    <title>topic Re: odd troubles with cursors in ArcGIS API for Python Questions</title>
    <link>https://community.esri.com/t5/arcgis-api-for-python-questions/odd-troubles-with-cursors/m-p/873691#M4810</link>
    <description>&lt;HTML&gt;&lt;HEAD&gt;&lt;/HEAD&gt;&lt;BODY&gt;&lt;P&gt;Your problem is that layer.getSelectionSet() returns Python sets:&lt;/P&gt;&lt;BLOCKQUOTE class="jive_macro_quote jive-quote jive_text_macro"&gt;&lt;H2 style="font-weight: 300; font-style: normal; margin: -5px 0px 1.55rem; font-size: 1.9994rem; line-height: 2.325rem; padding-top: 5px; color: #4c4c4c; font-family: 'Avenir Next W01', 'Avenir Next W00', 'Avenir Next', Avenir, 'Helvetica Neue', sans-serif; font-variant-ligatures: normal; font-variant-caps: normal; letter-spacing: normal; orphans: 2; text-align: start; text-indent: 0px; text-transform: none; white-space: normal; widows: 2; word-spacing: 0px; -webkit-text-stroke-width: 0px; text-decoration-style: initial; text-decoration-color: initial;"&gt;Method Overview&lt;/H2&gt;&lt;TABLE style="margin-bottom: 1.55rem; width: 759.333px; background-color: #ffffff; border-collapse: collapse; border-spacing: 0px; border: 1px solid #cccccc; text-align: left; overflow: auto; font-size: 0.875rem; line-height: 1.55rem; color: #4c4c4c; font-family: 'Avenir Next W01', 'Avenir Next W00', 'Avenir Next', Avenir, 'Helvetica Neue', sans-serif; font-style: normal; font-variant-ligatures: normal; font-variant-caps: normal; font-weight: 400; letter-spacing: normal; orphans: 2; text-indent: 0px; text-transform: none; white-space: normal; widows: 2; word-spacing: 0px; -webkit-text-stroke-width: 0px; text-decoration-style: initial; text-decoration-color: initial;"&gt;&lt;THEAD style="background-color: #efefef; border-bottom: 1px solid #cccccc; font-weight: 400; font-style: normal; font-size: 1rem; line-height: 1.55rem;"&gt;&lt;TR style="border-bottom: none; text-align: left;"&gt;&lt;TD class="" style="font-weight: 300; border-left: 1px solid #cccccc; border-right: 1px solid #cccccc; padding: 0.51667rem;"&gt;Method&lt;/TD&gt;&lt;TD class="" style="font-weight: 300; border-left: 1px solid #cccccc; border-right: 1px solid #cccccc; padding: 0.51667rem;"&gt;Explanation&lt;/TD&gt;&lt;/TR&gt;&lt;/THEAD&gt;&lt;TBODY style="overflow: auto; width: 759.333px;"&gt;&lt;TR style="border-bottom: 1px solid #cccccc; text-align: left;"&gt;&lt;TD style="font-weight: 300; border-left: 1px solid #cccccc; border-right: 1px solid #cccccc; padding: 0.51667rem;"&gt;getSelectionSet ()&lt;/TD&gt;&lt;TD style="font-weight: 300; border-left: 1px solid #cccccc; border-right: 1px solid #cccccc; padding: 0.51667rem;"&gt;&lt;P style="margin-top: 0px; margin-bottom: 0px;"&gt;Returns a layer's selection as a Python set of object IDs.&lt;/P&gt;&lt;/TD&gt;&lt;/TR&gt;&lt;/TBODY&gt;&lt;/TABLE&gt;&lt;/BLOCKQUOTE&gt;&lt;P&gt;&lt;/P&gt;&lt;P&gt;Since Python represents a set using curly brackets, your SQL expression is &lt;SPAN style="font-family: courier new, courier, monospace;"&gt;ObjectID = {4724}&lt;/SPAN&gt; instead of &lt;SPAN style="font-family: courier new, courier, monospace;"&gt;ObjectID = 4724&lt;/SPAN&gt;&amp;nbsp; .&lt;/P&gt;&lt;/BODY&gt;&lt;/HTML&gt;</description>
    <pubDate>Mon, 19 Aug 2019 16:01:17 GMT</pubDate>
    <dc:creator>JoshuaBixby</dc:creator>
    <dc:date>2019-08-19T16:01:17Z</dc:date>
    <item>
      <title>odd troubles with cursors</title>
      <link>https://community.esri.com/t5/arcgis-api-for-python-questions/odd-troubles-with-cursors/m-p/873690#M4809</link>
      <description>&lt;HTML&gt;&lt;HEAD&gt;&lt;/HEAD&gt;&lt;BODY&gt;&lt;P&gt;Hi folks, I'm not new to Python scripting for ArcGIS, but I'm a bit rusty to manipulating Python in GIS specifically, and new to ArcGIS Pro.&amp;nbsp; That said, what I'm trying to do is fairly simple and I've worked with cursors in GIS before, so I am stumped at what's wrong.&amp;nbsp; &lt;/P&gt;&lt;P&gt;&lt;/P&gt;&lt;P&gt;I have two datasets that I need to, by hand, relate to one another (they are two representations of the same geographic points, but one set is far more spatially accurate than the other, and I need to connect by hand what accurate point in one attribute table belongs to what inaccurate point in the other attribute table, and create a field that links them together as 'the same thing' since no such field currently exists between the two data tables).&amp;nbsp;&amp;nbsp; Since this is considered a common problem in the municipality I work with (two data sets that need to be linked by hand to each other), I am trying to write a script to aid in this process.&amp;nbsp; The idea is to, when two points are selected (as being the 'same') in the map, I run a script to pull values out of the accurate table and add them to the other datasets' attribute table.&amp;nbsp;&amp;nbsp; I found an example on the web a few years' old (predating the arcpy.mp) and thought I'd updated it properly, but I'm still having trouble.&amp;nbsp; I know my points are selected as expected, but this below script isn't working; I get an SQL error that doesn't make sense to me as an error. &amp;nbsp; Here is the code (my tab formatting gets butchered when copying from the Python window in Arc; not sure why, but I don't think it's relevant to my error):&lt;/P&gt;&lt;P&gt;&lt;/P&gt;&lt;P&gt;import arcpy&lt;/P&gt;&lt;P&gt;&lt;/P&gt;&lt;P&gt;aprx = arcpy.mp.ArcGISProject("CURRENT")&lt;BR /&gt;m = aprx.listMaps("Map1")[0]&lt;BR /&gt;featlyr = m.listLayers("WaterSystemValve")[0]&lt;BR /&gt;tblview = m.listLayers("Sheet1_XYTableToPoint")[0]&lt;/P&gt;&lt;P&gt;# field names in Table that you want to copy to water meter layer&lt;BR /&gt;tblFields = ['MCID'] &lt;BR /&gt;# field names in water meter layer that you want populated by table.&lt;BR /&gt;lyrFields = ['ValveNumber']&lt;/P&gt;&lt;P&gt;# Get a list of selected records in the table&lt;BR /&gt;tblsel = tblview.getSelectionSet() &lt;BR /&gt;# Get a list of the selected features in the water meter layer&lt;BR /&gt;lyrsel = featlyr.getSelectionSet()&lt;/P&gt;&lt;P&gt;if len(tblsel) == 1 and len(lyrsel) == 1: # If there is a single record/feature selected, then proceed&lt;BR /&gt; &lt;BR /&gt; # Query for Search Cursor to find the selected record&lt;BR /&gt; tblExpression = 'ObjectID = {}'.format(tblsel)&lt;BR /&gt; print(tblExpression, file=sys.stderr)&lt;BR /&gt; # Query for Update Cursor to find the selected feature&lt;BR /&gt; lyrExpression = 'ObjectID = {}'.format(lyrsel)&lt;/P&gt;&lt;P&gt;&lt;BR /&gt; with arcpy.da.SearchCursor(tblview, tblFields, tblExpression) as sCursor:&lt;BR /&gt; &amp;nbsp;&amp;nbsp;&amp;nbsp;for sRow in sCursor:&lt;BR /&gt; &amp;nbsp;&amp;nbsp;&amp;nbsp;with arcpy.da.UpdateCursor(featlyr, lyrFields, lyrExpression) as uCursor:&lt;BR /&gt; &amp;nbsp;&amp;nbsp;&amp;nbsp;for uRow in uCursor:&lt;BR /&gt; #Update the water meter feature to the value in the table record&lt;BR /&gt; uRow = sRow&lt;BR /&gt; &lt;BR /&gt; # Save the changes&lt;BR /&gt; # uRow.updateRow(uRow) &lt;BR /&gt;else:&lt;BR /&gt; # Bail if there are not the right number of records/features selected &lt;BR /&gt; # (e.g. there isn't a single record in the table and feature in the layer)&lt;BR /&gt; arcpy.AddError("Not the right number of features/records selected, bailing!")&lt;/P&gt;&lt;P&gt;&lt;/P&gt;&lt;P&gt;-----------------------------------------&lt;/P&gt;&lt;P&gt;and the error:&lt;/P&gt;&lt;P&gt;Failed script Script...&lt;BR /&gt; ObjectID = {4724}&lt;BR /&gt;Traceback (most recent call last):&lt;BR /&gt; File "C:\Users\Cynthia\Documents\myGISproj\RIR_watervalves\testme.py", line 29, in &amp;lt;module&amp;gt;&lt;BR /&gt; for sRow in sCursor:&lt;BR /&gt;&lt;STRONG&gt;RuntimeError: An invalid SQL statement was used. [SELECT MCID, OBJECTID FROM Sheet1_XYTableToPoint WHERE ObjectID = {4724}]&lt;/STRONG&gt;&lt;BR /&gt; Failed to execute (Script).&lt;/P&gt;&lt;P&gt;&lt;/P&gt;&lt;P&gt;I verified that object ID is correct, it should be 4724 and I can't for the life of me see what is invalid about the SQL statement (the fields are properly named).&amp;nbsp; Any ideas?&lt;/P&gt;&lt;P&gt;&lt;/P&gt;&lt;P&gt;Thanks,&lt;/P&gt;&lt;P&gt;&lt;/P&gt;&lt;P&gt;Cyndy&lt;/P&gt;&lt;/BODY&gt;&lt;/HTML&gt;</description>
      <pubDate>Mon, 19 Aug 2019 15:18:02 GMT</pubDate>
      <guid>https://community.esri.com/t5/arcgis-api-for-python-questions/odd-troubles-with-cursors/m-p/873690#M4809</guid>
      <dc:creator>CyndyBresloff</dc:creator>
      <dc:date>2019-08-19T15:18:02Z</dc:date>
    </item>
    <item>
      <title>Re: odd troubles with cursors</title>
      <link>https://community.esri.com/t5/arcgis-api-for-python-questions/odd-troubles-with-cursors/m-p/873691#M4810</link>
      <description>&lt;HTML&gt;&lt;HEAD&gt;&lt;/HEAD&gt;&lt;BODY&gt;&lt;P&gt;Your problem is that layer.getSelectionSet() returns Python sets:&lt;/P&gt;&lt;BLOCKQUOTE class="jive_macro_quote jive-quote jive_text_macro"&gt;&lt;H2 style="font-weight: 300; font-style: normal; margin: -5px 0px 1.55rem; font-size: 1.9994rem; line-height: 2.325rem; padding-top: 5px; color: #4c4c4c; font-family: 'Avenir Next W01', 'Avenir Next W00', 'Avenir Next', Avenir, 'Helvetica Neue', sans-serif; font-variant-ligatures: normal; font-variant-caps: normal; letter-spacing: normal; orphans: 2; text-align: start; text-indent: 0px; text-transform: none; white-space: normal; widows: 2; word-spacing: 0px; -webkit-text-stroke-width: 0px; text-decoration-style: initial; text-decoration-color: initial;"&gt;Method Overview&lt;/H2&gt;&lt;TABLE style="margin-bottom: 1.55rem; width: 759.333px; background-color: #ffffff; border-collapse: collapse; border-spacing: 0px; border: 1px solid #cccccc; text-align: left; overflow: auto; font-size: 0.875rem; line-height: 1.55rem; color: #4c4c4c; font-family: 'Avenir Next W01', 'Avenir Next W00', 'Avenir Next', Avenir, 'Helvetica Neue', sans-serif; font-style: normal; font-variant-ligatures: normal; font-variant-caps: normal; font-weight: 400; letter-spacing: normal; orphans: 2; text-indent: 0px; text-transform: none; white-space: normal; widows: 2; word-spacing: 0px; -webkit-text-stroke-width: 0px; text-decoration-style: initial; text-decoration-color: initial;"&gt;&lt;THEAD style="background-color: #efefef; border-bottom: 1px solid #cccccc; font-weight: 400; font-style: normal; font-size: 1rem; line-height: 1.55rem;"&gt;&lt;TR style="border-bottom: none; text-align: left;"&gt;&lt;TD class="" style="font-weight: 300; border-left: 1px solid #cccccc; border-right: 1px solid #cccccc; padding: 0.51667rem;"&gt;Method&lt;/TD&gt;&lt;TD class="" style="font-weight: 300; border-left: 1px solid #cccccc; border-right: 1px solid #cccccc; padding: 0.51667rem;"&gt;Explanation&lt;/TD&gt;&lt;/TR&gt;&lt;/THEAD&gt;&lt;TBODY style="overflow: auto; width: 759.333px;"&gt;&lt;TR style="border-bottom: 1px solid #cccccc; text-align: left;"&gt;&lt;TD style="font-weight: 300; border-left: 1px solid #cccccc; border-right: 1px solid #cccccc; padding: 0.51667rem;"&gt;getSelectionSet ()&lt;/TD&gt;&lt;TD style="font-weight: 300; border-left: 1px solid #cccccc; border-right: 1px solid #cccccc; padding: 0.51667rem;"&gt;&lt;P style="margin-top: 0px; margin-bottom: 0px;"&gt;Returns a layer's selection as a Python set of object IDs.&lt;/P&gt;&lt;/TD&gt;&lt;/TR&gt;&lt;/TBODY&gt;&lt;/TABLE&gt;&lt;/BLOCKQUOTE&gt;&lt;P&gt;&lt;/P&gt;&lt;P&gt;Since Python represents a set using curly brackets, your SQL expression is &lt;SPAN style="font-family: courier new, courier, monospace;"&gt;ObjectID = {4724}&lt;/SPAN&gt; instead of &lt;SPAN style="font-family: courier new, courier, monospace;"&gt;ObjectID = 4724&lt;/SPAN&gt;&amp;nbsp; .&lt;/P&gt;&lt;/BODY&gt;&lt;/HTML&gt;</description>
      <pubDate>Mon, 19 Aug 2019 16:01:17 GMT</pubDate>
      <guid>https://community.esri.com/t5/arcgis-api-for-python-questions/odd-troubles-with-cursors/m-p/873691#M4810</guid>
      <dc:creator>JoshuaBixby</dc:creator>
      <dc:date>2019-08-19T16:01:17Z</dc:date>
    </item>
    <item>
      <title>Re: odd troubles with cursors</title>
      <link>https://community.esri.com/t5/arcgis-api-for-python-questions/odd-troubles-with-cursors/m-p/873692#M4811</link>
      <description>&lt;HTML&gt;&lt;HEAD&gt;&lt;/HEAD&gt;&lt;BODY&gt;&lt;P&gt;Thank you!! &lt;/P&gt;&lt;/BODY&gt;&lt;/HTML&gt;</description>
      <pubDate>Mon, 19 Aug 2019 16:52:42 GMT</pubDate>
      <guid>https://community.esri.com/t5/arcgis-api-for-python-questions/odd-troubles-with-cursors/m-p/873692#M4811</guid>
      <dc:creator>CyndyBresloff</dc:creator>
      <dc:date>2019-08-19T16:52:42Z</dc:date>
    </item>
    <item>
      <title>Re: odd troubles with cursors</title>
      <link>https://community.esri.com/t5/arcgis-api-for-python-questions/odd-troubles-with-cursors/m-p/873693#M4812</link>
      <description>&lt;HTML&gt;&lt;HEAD&gt;&lt;/HEAD&gt;&lt;BODY&gt;&lt;P&gt;If someone's response answers your question, please mark it correct to close out the question, or you can reply with follow-up questions.&lt;/P&gt;&lt;/BODY&gt;&lt;/HTML&gt;</description>
      <pubDate>Mon, 19 Aug 2019 17:09:52 GMT</pubDate>
      <guid>https://community.esri.com/t5/arcgis-api-for-python-questions/odd-troubles-with-cursors/m-p/873693#M4812</guid>
      <dc:creator>JoshuaBixby</dc:creator>
      <dc:date>2019-08-19T17:09:52Z</dc:date>
    </item>
  </channel>
</rss>

