Skip to main content
added 4 characters in body
Source Link
Aaron
  • 51.8k
  • 29
  • 157
  • 322

You can use Select (Analysis) to perform this operation. This method has the added benefit of preserving your attributes. There are two main steps:

  1. Use a generator to list all of the unique city codes
  2. Loop through unique cities codes and add the code to the Select SQL expression

import arcpy, os

# Define the output workspace
outws = r'C:\temp\out'

# Set the input shapefile
shp = r'C:\temp\test.shp'

# Get a list of unique city codes using a generator
cities = set(row[0] for row in arcpy.da.SearchCursor(shp, "city"))

# Select unique cities and export to new shapefiles
for c in cities:
    out_fc = os.path.join(outws, c) # Define the output name
    where_clause = '"city" = \'%s\'' % c # Select based on city name
    arcpy.Select_analysis(shp, out_fc, where_clause) # Perform the Select

You can use Select (Analysis) to perform this operation. This method has the added benefit of preserving your attributes. There are two main steps:

  1. Use a generator to list all of the unique city codes
  2. Loop through unique cities codes and add the code to the Select SQL expression

import arcpy

# Define the output workspace
outws = r'C:\temp\out'

# Set the input shapefile
shp = r'C:\temp\test.shp'

# Get a list of unique city codes using a generator
cities = set(row[0] for row in arcpy.da.SearchCursor(shp, "city"))

# Select unique cities and export to new shapefiles
for c in cities:
    out_fc = os.path.join(outws, c) # Define the output name
    where_clause = '"city" = \'%s\'' % c # Select based on city name
    arcpy.Select_analysis(shp, out_fc, where_clause) # Perform the Select

You can use Select (Analysis) to perform this operation. This method has the added benefit of preserving your attributes. There are two main steps:

  1. Use a generator to list all of the unique city codes
  2. Loop through unique cities codes and add the code to the Select SQL expression

import arcpy, os

# Define the output workspace
outws = r'C:\temp\out'

# Set the input shapefile
shp = r'C:\temp\test.shp'

# Get a list of unique city codes using a generator
cities = set(row[0] for row in arcpy.da.SearchCursor(shp, "city"))

# Select unique cities and export to new shapefiles
for c in cities:
    out_fc = os.path.join(outws, c) # Define the output name
    where_clause = '"city" = \'%s\'' % c # Select based on city name
    arcpy.Select_analysis(shp, out_fc, where_clause) # Perform the Select
added 65 characters in body
Source Link
Aaron
  • 51.8k
  • 29
  • 157
  • 322

You can use Select (Analysis) to perform this operation. This method has the added benefit of preserving your attributes. There are two main steps:

  1. Use a generator to list all of the unique city codes
  2. Loop through unique cities codes and add the code to the Select SQL expression

import arcpy

# Define the output workspace
outws = r'C:\temp\out'

# Set the input shapefile
shp = r'C:\temp\test.shp'

# Get a list of unique city codes using a generator
cities = set(row[0] for row in arcpy.da.SearchCursor(shp, "city"))

# Select unique cities and export to new shapefiles
for c in cities:
    out_fc = os.path.join(outws, c) # Define the output name
    where_clause = '"city" = \'%s\'' % c # Select based on city name
    arcpy.Select_analysis(shp, out_fc, where_clause) # Perform the Select

You can use Select (Analysis) to perform this operation. There are two main steps:

  1. Use a generator to list all of the unique city codes
  2. Loop through unique cities codes and add the code to the Select SQL expression

import arcpy

# Define the output workspace
outws = r'C:\temp\out'

# Set the input shapefile
shp = r'C:\temp\test.shp'

# Get a list of unique city codes using a generator
cities = set(row[0] for row in arcpy.da.SearchCursor(shp, "city"))

# Select unique cities and export to new shapefiles
for c in cities:
    out_fc = os.path.join(outws, c) # Define the output name
    where_clause = '"city" = \'%s\'' % c # Select based on city name
    arcpy.Select_analysis(shp, out_fc, where_clause) # Perform the Select

You can use Select (Analysis) to perform this operation. This method has the added benefit of preserving your attributes. There are two main steps:

  1. Use a generator to list all of the unique city codes
  2. Loop through unique cities codes and add the code to the Select SQL expression

import arcpy

# Define the output workspace
outws = r'C:\temp\out'

# Set the input shapefile
shp = r'C:\temp\test.shp'

# Get a list of unique city codes using a generator
cities = set(row[0] for row in arcpy.da.SearchCursor(shp, "city"))

# Select unique cities and export to new shapefiles
for c in cities:
    out_fc = os.path.join(outws, c) # Define the output name
    where_clause = '"city" = \'%s\'' % c # Select based on city name
    arcpy.Select_analysis(shp, out_fc, where_clause) # Perform the Select
Source Link
Aaron
  • 51.8k
  • 29
  • 157
  • 322

You can use Select (Analysis) to perform this operation. There are two main steps:

  1. Use a generator to list all of the unique city codes
  2. Loop through unique cities codes and add the code to the Select SQL expression

import arcpy

# Define the output workspace
outws = r'C:\temp\out'

# Set the input shapefile
shp = r'C:\temp\test.shp'

# Get a list of unique city codes using a generator
cities = set(row[0] for row in arcpy.da.SearchCursor(shp, "city"))

# Select unique cities and export to new shapefiles
for c in cities:
    out_fc = os.path.join(outws, c) # Define the output name
    where_clause = '"city" = \'%s\'' % c # Select based on city name
    arcpy.Select_analysis(shp, out_fc, where_clause) # Perform the Select