<?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: Generating Feature Class from Unique Value in Python Questions</title>
    <link>https://community.esri.com/t5/python-questions/generating-feature-class-from-unique-value/m-p/1144250#M63765</link>
    <description>&lt;P&gt;Why don't you use&lt;/P&gt;&lt;P&gt;&lt;A href="https://pro.arcgis.com/en/pro-app/latest/tool-reference/analysis/split-by-attributes.htm" target="_blank"&gt;Split By Attributes (Analysis)—ArcGIS Pro | Documentation&lt;/A&gt;&lt;/P&gt;&lt;P&gt;to produce the featureclasses based on your unique classes in the field&lt;/P&gt;</description>
    <pubDate>Tue, 15 Feb 2022 19:36:50 GMT</pubDate>
    <dc:creator>DanPatterson</dc:creator>
    <dc:date>2022-02-15T19:36:50Z</dc:date>
    <item>
      <title>Generating Feature Class from Unique Value</title>
      <link>https://community.esri.com/t5/python-questions/generating-feature-class-from-unique-value/m-p/1144156#M63759</link>
      <description>&lt;P&gt;Hi all, I'm needing your help once again with a code/script tool that I have been working on.&amp;nbsp;&lt;/P&gt;&lt;LI-CODE lang="python"&gt;import arcpy
import os

arcpy.env.overwriteOutput = True

arcpy.env.workspace =  r"C:\UpdateDevelopmentPython\ForDeveloping\ForDeveloping.gdb"
EnterWaterSysID = arcpy.GetParameterAsText(0).split(";")
Hydrant_FC = "Hydrants"
WaterSystems = "WaterSystems"
Streetmap = r"C:\UpdateDevelopmentPython\Streetmap Premium\FGDB\StreetMap_Data\NorthAmerica.gdb\Routing\Routing_ND"


qry = "{0} IN ({1})".format(arcpy.AddFieldDelimiters(datasource= Hydrant_FC, field = 'WaterSysID'), ', '.join(EnterWaterSysID))

arcpy.SelectLayerByAttribute_management(in_layer_or_view=Hydrant_FC, where_clause=qry)
arcpy.SelectLayerByLocation_management(Hydrant_FC,"Within",WaterSystems,None,"SUBSET_SELECTION","INVERT")

arcpy.env.workspace = r"C:\UpdateDevelopmentPython\ForDeveloping\ForDeveloping.gdb"
Service_Area = arcpy.na.MakeServiceAreaAnalysisLayer(network_data_source=Streetmap,
                                                       layer_name="Service Area", 
                                                       travel_mode="Driving Distance", 
                                                       travel_direction="FROM_FACILITIES", 
                                                       cutoffs=[0.189394], 
                                                       time_of_day="", 
                                                       time_zone="LOCAL_TIME_AT_LOCATIONS", 
                                                       output_type="LINES", 
                                                       polygon_detail="STANDARD", 
                                                       geometry_at_overlaps="SPLIT", 
                                                       geometry_at_cutoffs="RINGS", 
                                                       polygon_trim_distance="100 Meters", 
                                                       exclude_sources_from_polygon_generation=[], 
                                                       accumulate_attributes=["Miles"], 
                                                       ignore_invalid_locations="SKIP")[0]

Updated_Service_Area = arcpy.na.AddLocations(in_network_analysis_layer=Service_Area,
                                             sub_layer="Facilities", 
                                             in_table=Hydrant_FC, 
                                             field_mappings="", 
                                             search_tolerance="5000 Meters", 
                                             sort_field="", 
                                             search_criteria=[["Routing_Streets", "SHAPE"], 
                                                             ["Routing_Streets_Override", "NONE"], 
                                                             ["Routing_ND_Junctions", "NONE"]], 
                                             match_type="MATCH_TO_CLOSEST", 
                                             append="APPEND", 
                                             snap_to_position_along_network="NO_SNAP", 
                                             snap_offset="5 Meters", 
                                             exclude_restricted_elements="EXCLUDE", 
                                             search_query=[])[0]

Solve_Succeeded = arcpy.na.Solve(in_network_analysis_layer=Updated_Service_Area, 
                                 ignore_invalids="SKIP", 
                                 terminate_on_solve_error="TERMINATE", 
                                 simplification_tolerance="", 
                                 overrides="")

Lines = arcpy.Select_analysis("Lines","Lines_Selected")

arcpy.SelectLayerByAttribute_management(Hydrant_FC, "CLEAR_SELECTION")

Lines_Extracted = r"C:\UpdateDevelopmentPython\ForDeveloping\ForDeveloping.gdb\Lines_Selected"
p = arcpy.mp.ArcGISProject("CURRENT")
m = p.listMaps("Map")[0]
m.addDataFromPath(Lines_Extracted)

NewHydrantLines = arcpy.MakeFeatureLayer_management(Lines_Extracted,"HydrantLines")
outgdb = r"C:\UpdateDevelopmentPython\ForDeveloping\ForDeveloping.gdb\Lines_Selected_Joined"

arcpy.analysis.SpatialJoin("Lines_Selected", 
                           "Hydrants", 
                           outgdb, 
                           "JOIN_ONE_TO_ONE", 
                           "KEEP_COMMON", 
                           'WaterSysID "WaterSysID" true true false 4 Long 0 0,First,#,Hydrants,WaterSysID,-1,-1', 
                           "WITHIN_A_DISTANCE", 
                           "1000 Feet", '')

Streets_Joined = r"C:\UpdateDevelopmentPython\ForDeveloping\ForDeveloping.gdb\Lines_Selected_Joined"
fieldName = "WaterSysID"
delimfield = arcpy.AddFieldDelimiters(Streets_Joined,fieldName)
sql = delimfield = EnterWaterSysID
with arcpy.da.SearchCursor(Streets_Joined,fieldName) as cursor:
    for row in cursor:
        arcpy.SelectLayerByAttribute_management(row,"NEW_SELECTION",sql)&lt;/LI-CODE&gt;&lt;P&gt;After I perform the spatial join which is line 69 of my code I get an feature class called Lines_Selected_Joined with an attribute table that looks like the following.&lt;/P&gt;&lt;P&gt;&lt;span class="lia-inline-image-display-wrapper lia-image-align-inline" image-alt="table.PNG" style="width: 999px;"&gt;&lt;img src="https://community.esri.com/t5/image/serverpage/image-id/33956i52B471A2194639D4/image-size/large?v=v2&amp;amp;px=999" role="button" title="table.PNG" alt="table.PNG" /&gt;&lt;/span&gt;&lt;/P&gt;&lt;P&gt;This works great but now what I'm trying to do is generate individual feature classes based on the unique values found in the WaterSysID column.&amp;nbsp;&lt;/P&gt;&lt;P&gt;The WaterSysID values that I want to extract from this one feature class should be the same ones that I enter in the tool using the GetParameterAsText function, found on line 7 of my code.&amp;nbsp; In this case it would be for WaterSysIDs 4 and 159.&amp;nbsp;&lt;/P&gt;&lt;P&gt;&lt;span class="lia-inline-image-display-wrapper lia-image-align-center" image-alt="Tool.PNG" style="width: 400px;"&gt;&lt;img src="https://community.esri.com/t5/image/serverpage/image-id/33960iB0295661E7498636/image-size/medium?v=v2&amp;amp;px=400" role="button" title="Tool.PNG" alt="Tool.PNG" /&gt;&lt;/span&gt;Any suggestions on how to go about this?&amp;nbsp; Thanks all in advance for the help, I do appreciate it as I'm pretty green when it comes to Python.&lt;/P&gt;&lt;P&gt; &lt;/P&gt;</description>
      <pubDate>Tue, 15 Feb 2022 16:52:21 GMT</pubDate>
      <guid>https://community.esri.com/t5/python-questions/generating-feature-class-from-unique-value/m-p/1144156#M63759</guid>
      <dc:creator>ColeNelson</dc:creator>
      <dc:date>2022-02-15T16:52:21Z</dc:date>
    </item>
    <item>
      <title>Re: Generating Feature Class from Unique Value</title>
      <link>https://community.esri.com/t5/python-questions/generating-feature-class-from-unique-value/m-p/1144250#M63765</link>
      <description>&lt;P&gt;Why don't you use&lt;/P&gt;&lt;P&gt;&lt;A href="https://pro.arcgis.com/en/pro-app/latest/tool-reference/analysis/split-by-attributes.htm" target="_blank"&gt;Split By Attributes (Analysis)—ArcGIS Pro | Documentation&lt;/A&gt;&lt;/P&gt;&lt;P&gt;to produce the featureclasses based on your unique classes in the field&lt;/P&gt;</description>
      <pubDate>Tue, 15 Feb 2022 19:36:50 GMT</pubDate>
      <guid>https://community.esri.com/t5/python-questions/generating-feature-class-from-unique-value/m-p/1144250#M63765</guid>
      <dc:creator>DanPatterson</dc:creator>
      <dc:date>2022-02-15T19:36:50Z</dc:date>
    </item>
    <item>
      <title>Re: Generating Feature Class from Unique Value</title>
      <link>https://community.esri.com/t5/python-questions/generating-feature-class-from-unique-value/m-p/1144259#M63768</link>
      <description>&lt;P&gt;Hi Don!&amp;nbsp; That worked great, thank you so much for the help!!!&lt;/P&gt;&lt;P&gt;The only question I have left is how do I rename the new feature classes?&amp;nbsp;&amp;nbsp;&lt;/P&gt;&lt;P&gt;&lt;span class="lia-inline-image-display-wrapper lia-image-align-center" image-alt="gdb.PNG" style="width: 368px;"&gt;&lt;img src="https://community.esri.com/t5/image/serverpage/image-id/33989iF6E5CE16EE828702/image-size/large?v=v2&amp;amp;px=999" role="button" title="gdb.PNG" alt="gdb.PNG" /&gt;&lt;/span&gt;&lt;/P&gt;&lt;P&gt;For example, instead of the feature class being called T4, I'd like to call it 4WS_Streets, or something along those lines.&amp;nbsp; This was the code I used for the SplitByAttributes.&lt;/P&gt;&lt;LI-CODE lang="python"&gt;finalLines = r"C:\UpdateDevelopmentPython\ForDeveloping\NewHydrants.gdb"
fields = ["WaterSysID"]
arcpy.SplitByAttributes_analysis(Lines_Selected,finalLines,fields)&lt;/LI-CODE&gt;</description>
      <pubDate>Tue, 15 Feb 2022 19:57:06 GMT</pubDate>
      <guid>https://community.esri.com/t5/python-questions/generating-feature-class-from-unique-value/m-p/1144259#M63768</guid>
      <dc:creator>ColeNelson</dc:creator>
      <dc:date>2022-02-15T19:57:06Z</dc:date>
    </item>
    <item>
      <title>Re: Generating Feature Class from Unique Value</title>
      <link>https://community.esri.com/t5/python-questions/generating-feature-class-from-unique-value/m-p/1144320#M63770</link>
      <description>&lt;P&gt;&lt;A href="https://pro.arcgis.com/en/pro-app/latest/tool-reference/data-management/rename.htm" target="_blank"&gt;Rename (Data Management)—ArcGIS Pro | Documentation&lt;/A&gt;&lt;/P&gt;&lt;P&gt;or modify/emulate the code in the actual script located in....&lt;/P&gt;&lt;P&gt;C:\...Your_install_folder ...\Resources\ArcToolBox\Scripts\splitbyattribute.py&lt;/P&gt;</description>
      <pubDate>Tue, 15 Feb 2022 21:30:15 GMT</pubDate>
      <guid>https://community.esri.com/t5/python-questions/generating-feature-class-from-unique-value/m-p/1144320#M63770</guid>
      <dc:creator>DanPatterson</dc:creator>
      <dc:date>2022-02-15T21:30:15Z</dc:date>
    </item>
  </channel>
</rss>

