<?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: Linear Events and Select By Location in Python Questions</title>
    <link>https://community.esri.com/t5/python-questions/linear-events-and-select-by-location/m-p/152459#M11748</link>
    <description>&lt;HTML&gt;&lt;HEAD&gt;&lt;/HEAD&gt;&lt;BODY&gt;&lt;SPAN&gt;bump :confused:&lt;/SPAN&gt;&lt;/BODY&gt;&lt;/HTML&gt;</description>
    <pubDate>Thu, 30 May 2013 19:42:04 GMT</pubDate>
    <dc:creator>WesleyMarcell</dc:creator>
    <dc:date>2013-05-30T19:42:04Z</dc:date>
    <item>
      <title>Linear Events and Select By Location</title>
      <link>https://community.esri.com/t5/python-questions/linear-events-and-select-by-location/m-p/152458#M11747</link>
      <description>&lt;HTML&gt;&lt;HEAD&gt;&lt;/HEAD&gt;&lt;BODY&gt;&lt;SPAN&gt;Greetings,&lt;/SPAN&gt;&lt;BR /&gt;&lt;SPAN&gt;I am working on a script to check some linear events at my current job.&amp;nbsp; I have been having some issues, and it is frustrating because the process I am attempting would work for regular features, and works when you manually run it through GIS, but it does not work programatically in python.&amp;nbsp; FYI I am using ArcGIS 10.0 for this process.&lt;/SPAN&gt;&lt;BR /&gt;&lt;BR /&gt;&lt;SPAN&gt;Basically I am attempting to check two fields "From_Milepost" and "To_Milepost" to ensure that the events are going from low to high (M values should work also).&amp;nbsp; My problem is that for our workflow, we are only checking events that fall withing a certian division of the data.&amp;nbsp; Our SDE data often includes several divisions, so I am attempting a SBL before checking the Milepost values.&lt;/SPAN&gt;&lt;BR /&gt;&lt;BR /&gt;&lt;SPAN&gt;Here is a list of the different things I have attempted:&lt;/SPAN&gt;&lt;BR /&gt;&lt;BR /&gt;&lt;SPAN&gt;1. Select By Location (Linear event that falls within division) &amp;gt; Check that Milepost order is correct&lt;/SPAN&gt;&lt;BR /&gt;&lt;SPAN&gt;&amp;nbsp;&amp;nbsp;&amp;nbsp; Result: Count on linear event is 140 (expected) when run through the check MP order section only four features are processed.&lt;/SPAN&gt;&lt;BR /&gt;&lt;BR /&gt;&lt;SPAN&gt;2. Select By Location &amp;gt; Create Feature Layer &amp;gt; Check MP order is correct&lt;/SPAN&gt;&lt;BR /&gt;&lt;SPAN&gt;&amp;nbsp;&amp;nbsp;&amp;nbsp; Result: Count on linear event is 140 (expected) when run through the check MP order section only four features are processed.&lt;/SPAN&gt;&lt;BR /&gt;&lt;BR /&gt;&lt;SPAN&gt;3. Select By Location &amp;gt; Create Table View &amp;gt; Check MP order is correct&lt;/SPAN&gt;&lt;BR /&gt;&lt;SPAN&gt;&amp;nbsp;&amp;nbsp;&amp;nbsp; Result: Count (6612) does not match, selection ignored when creating Table view &lt;/SPAN&gt;&lt;BR /&gt;&lt;SPAN&gt;&amp;nbsp;&amp;nbsp;&amp;nbsp; All events are processed through MP loop (6612 records)&lt;/SPAN&gt;&lt;BR /&gt;&lt;BR /&gt;&lt;SPAN&gt;4. Select By Location &amp;gt; Create Feature Layer &amp;gt; Create Table View &amp;gt; Check MP order loop&lt;/SPAN&gt;&lt;BR /&gt;&lt;SPAN&gt;&amp;nbsp;&amp;nbsp;&amp;nbsp; Results: Count of Feature layer 140, count of Table view 6612, all 6612 records looped through&lt;/SPAN&gt;&lt;BR /&gt;&lt;BR /&gt;&lt;SPAN&gt;And finally this workflow works, but not as I would like it to (OID's not retained, my data does not have unique identifiers)&lt;/SPAN&gt;&lt;BR /&gt;&lt;SPAN&gt;5. Select by location &amp;gt; Copy Features management &amp;gt; Loop through MP check section&lt;/SPAN&gt;&lt;BR /&gt;&lt;SPAN&gt;&amp;nbsp;&amp;nbsp;&amp;nbsp; Results: Count matches, only 140 features looped through.&amp;nbsp; OIDs renumbered 1-140&lt;/SPAN&gt;&lt;BR /&gt;&lt;BR /&gt;&lt;SPAN&gt;I have attached code below with the above numbered and commented out.&amp;nbsp; If anyone can help it would be appreciated.&amp;nbsp; What I am hoping is to get the 140 selected events to go through the loop.&amp;nbsp; I would like to retain the OID's if at all possible.&amp;nbsp; If there is a way to do this without creating Table views/feature layers that is great.&amp;nbsp; If there is a way to retain the original OID's when you run the CopyFeatures_management that would also be great.&amp;nbsp; My last idea is to create a FGDB and only write the errors to a feature class.&amp;nbsp; This would allow the user to zoom to the area and find the feature.&amp;nbsp; Retaining OID's however would be the best solution.&amp;nbsp; Any feedback is greatly appreciated.&amp;nbsp; I do not have much experience using Event Layers, and have even less experience attempting to program python using events.&lt;/SPAN&gt;&lt;BR /&gt;&lt;BR /&gt;&lt;SPAN&gt;Here is some delicious code goodness!!!&lt;/SPAN&gt;&lt;BR /&gt;&lt;PRE class="plain" name="code"&gt;import arcpy from arcpy import mapping from arcpy import env&amp;nbsp; arcpy.env.overwriteOutput = True SUBDIVISION = "NCS_SUB_CODE_EVT Events" OPCODE = "NCS_OP_CODE_EVT Events"&amp;nbsp; ##Check MP Order NCS_OP_CODE_EVT arcpy.AddMessage("***Checking MP order - NCS_OP_CODE_EVT***") arcpy.SelectLayerByLocation_management(OPCODE, "INTERSECT", SUBDIVISION, "", "NEW_SELECTION")&amp;nbsp; ######1. This will run a loop on the data.&amp;nbsp; Count matches, but only four results are looped through#### ##arcpy.AddMessage("OPCODE = " + str(arcpy.GetCount_management(OPCODE))) ##rows = arcpy.SearchCursor(OPCODE)&amp;nbsp; ######2. This creates Feature Layer and then loops through.&amp;nbsp; Counts match, only four records looped#### ##arcpy.MakeFeatureLayer_management(OPCODE, "OPCODE_F") ##arcpy.AddMessage("OPCODE_FeatureLyr Count = " + str(arcpy.GetCount_management("OPCODE_F"))) ##rows = arcpy.SearchCursor("OPCODE_F")&amp;nbsp; ####3. This creates a Table View and then loops.&amp;nbsp; Counts match only four records looped#### ##arcpy.MakeTableView_management(OPCODE, "OPCODE_T") ##arcpy.AddMessage("OPCODE_TblView Count = " + str(arcpy.GetCount_management("OPCODE_T"))) ##rows = arcpy.SearchCursor("OPCODE_T")&amp;nbsp; ####4. This will combine above.&amp;nbsp; Create Feature Layer then send to Table view, then loop#### ##arcpy.MakeFeatureLayer_management(OPCODE, "OPCODE_F") ##arcpy.MakeTableView_management("OPCODE_F", "OPCODE_T") ##arcpy.AddMessage("OPCODE_FeatureLyr Count = " + str(arcpy.GetCount_management("OPCODE_F"))) ##arcpy.AddMessage("OPCODE_TblView Count = " + str(arcpy.GetCount_management("OPCODE_T"))) ##rows = arcpy.SearchCursor("OPCODE_T")&amp;nbsp; ####5. Copy features out.&amp;nbsp; Does not retain OID's arcpy.CopyFeatures_management(OPCODE, "OPCODE_SEL") arcpy.AddMessage(arcpy.GetCount_management("OPCODE_SEL")) rows = arcpy.SearchCursor("OPCODE_SEL")&amp;nbsp; for row in rows: &amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp; MP = (row.To_Milepost - row.From_Milepost) &amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp; arcpy.AddMessage("OID = " + str(row.OBJECTID) + " MP = " + str(MP)) &amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp; if MP &amp;lt; 0: &amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp; arcpy.AddMessage("ObjectID: " + str(row.OBJECTID)+ " has decreasing Mileposts")&lt;/PRE&gt;&lt;/BODY&gt;&lt;/HTML&gt;</description>
      <pubDate>Wed, 29 May 2013 13:59:25 GMT</pubDate>
      <guid>https://community.esri.com/t5/python-questions/linear-events-and-select-by-location/m-p/152458#M11747</guid>
      <dc:creator>WesleyMarcell</dc:creator>
      <dc:date>2013-05-29T13:59:25Z</dc:date>
    </item>
    <item>
      <title>Re: Linear Events and Select By Location</title>
      <link>https://community.esri.com/t5/python-questions/linear-events-and-select-by-location/m-p/152459#M11748</link>
      <description>&lt;HTML&gt;&lt;HEAD&gt;&lt;/HEAD&gt;&lt;BODY&gt;&lt;SPAN&gt;bump :confused:&lt;/SPAN&gt;&lt;/BODY&gt;&lt;/HTML&gt;</description>
      <pubDate>Thu, 30 May 2013 19:42:04 GMT</pubDate>
      <guid>https://community.esri.com/t5/python-questions/linear-events-and-select-by-location/m-p/152459#M11748</guid>
      <dc:creator>WesleyMarcell</dc:creator>
      <dc:date>2013-05-30T19:42:04Z</dc:date>
    </item>
    <item>
      <title>Re: Linear Events and Select By Location</title>
      <link>https://community.esri.com/t5/python-questions/linear-events-and-select-by-location/m-p/152460#M11749</link>
      <description>&lt;HTML&gt;&lt;HEAD&gt;&lt;/HEAD&gt;&lt;BODY&gt;&lt;SPAN&gt;OID values are not under a user's control and cannot be retained within an OID field of any exported feature class or table (it will always renumber).&amp;nbsp; Geoprocessing operations that output OID values for backward links (such as Intersect, Spatial Join, and many others) create a Long field with a name like TARGET_FID, JOIN_FID or FID_OPCODE (FID plus source name).&amp;nbsp; Once these fields are converted to a Long field they are no longer ensured to be unique in the output table.&amp;nbsp; These tools usually combine two inputs.&amp;nbsp; Copy Features does not retain OIDs in a field like this as you have seen.&lt;/SPAN&gt;&lt;BR /&gt;&lt;BR /&gt;&lt;SPAN&gt;So you could create a polygon of your area and do a Spatial join with your features making the lines the TARGET_FID (primary source).&amp;nbsp; They would retain their original shape even if they were not contained completely by the area boundary.&amp;nbsp; Spatial Join should also work with all feature class type combinations (polygon on polygon, line or point, line on polygon, line or point, and point on polygon, line or point).&amp;nbsp; In effect Spatial Join is the process of Select by Location and output to a new feature class in one operation with backward OID support to your original source data.&lt;/SPAN&gt;&lt;/BODY&gt;&lt;/HTML&gt;</description>
      <pubDate>Thu, 30 May 2013 23:04:10 GMT</pubDate>
      <guid>https://community.esri.com/t5/python-questions/linear-events-and-select-by-location/m-p/152460#M11749</guid>
      <dc:creator>RichardFairhurst</dc:creator>
      <dc:date>2013-05-30T23:04:10Z</dc:date>
    </item>
    <item>
      <title>Re: Linear Events and Select By Location</title>
      <link>https://community.esri.com/t5/python-questions/linear-events-and-select-by-location/m-p/152461#M11750</link>
      <description>&lt;HTML&gt;&lt;HEAD&gt;&lt;/HEAD&gt;&lt;BODY&gt;&lt;SPAN&gt;Thanks for the reply! I think that a spatial join will do the trick.&amp;nbsp; I actually came up with the same solution this morning, and have tested and gotten it to work as I would like.&amp;nbsp;&amp;nbsp; Thanks a bunch for the feedback.&amp;nbsp; i will try to put the code up when I have finished to help anyone else with this problem!!!&lt;/SPAN&gt;&lt;/BODY&gt;&lt;/HTML&gt;</description>
      <pubDate>Fri, 31 May 2013 18:40:23 GMT</pubDate>
      <guid>https://community.esri.com/t5/python-questions/linear-events-and-select-by-location/m-p/152461#M11750</guid>
      <dc:creator>WesleyMarcell</dc:creator>
      <dc:date>2013-05-31T18:40:23Z</dc:date>
    </item>
  </channel>
</rss>

