Select parcels (by county fips) from SDE layer into shapefile.

723
6
06-23-2014 12:23 PM
JimFritz
Occasional Contributor
I have an SDE layer of parcel data from which I want to export out (by state code and county fips code) each county separately into it's own shapefile.  I have a list of state and fips codes in a separate dbf.  I suppose there is a way to pass values from the dbf listing to perform the exports.  Could someone help with providing a Python script to work with?

Many thanks in advance!

Jim F.
Tags (2)
0 Kudos
6 Replies
KerryAlley
Occasional Contributor
Hi Jim,

Here's a little script that might help.  You would need to edit 4 lines (indicated with comments) to refer to your SDE data, though.  The script could be run from either the ArcMap Python window, or a Python IDE window. 

If you want to re-run the script, you'd have to delete the shapefiles manually because they can't be overwritten.

If the fips code does not specify the state, you'd need to specify the state using an additional field... which would require about 4 more lines of code.

import arcpy

#Next 4 lines must be edited to correspond to your data and directories.
fc = r"Database Connections\GDB_HMS.sde\GDB_HMS.HMSADMIN.rdsmall_arc"    #original dataset path
shortName = "rdsmall_arc"    #a simplified dataset name (without "." characters found in our SDE dataset names)
fipsField = "FIPS"     #name of the field that is used to subdivide dataset
outputFolder = r"V:\Projects\Shared\kalley\Documentation\rdsmall"    #folder path where shape files should go

fipsList = sorted(set([code[0] for code in arcpy.da.SearchCursor(fc, fipsField)])) #creates a sorted list of unique fips codes in dataset

for fipsCode in fipsList:
    outputName = "{0}_{1}".format(shortName, str(fipsCode)) #new filename will look like shortName_fipsCode.shp
    query = "{0} = {1}".format(fipsField, str(fipsCode)) #assumes fipsCode is an integer
    arcpy.FeatureClassToFeatureClass_conversion(fc, outputFolder, outputName, query)
    arcpy.AddMessage("Created {0}\n".format(outputName))

0 Kudos
JimFritz
Occasional Contributor
Hi Kerry,

Thanks for the quick response.  Not being a Python script writer, I'll need some more code, please.  First, the fips code field in both the sde and related table is a string field.  I now have a "state" field (string) in the look-up table so I'll need those extra 4 lines of code you mentioned.   For the connection to SDE, here is what the Instance field reads under Layer Properties, "sde:oracle$sde:oracle11g:LANDP.xcelenergy.com".  Looks different than yours.

Any assistance would be appreciated!

Jim
0 Kudos
JimFritz
Occasional Contributor
Hi Kerry,

Thanks for the quick response.  Not being a Python script writer, I'll need some more code, please.  First, the fips code field in both the sde and related table is a string field.  I now have a "state" field (string) in the look-up table so I'll need those extra 4 lines of code you mentioned.   For the connection to SDE, here is what the Instance field reads under Layer Properties, "sde:oracle$sde:oracle11g:LANDP.xcelenergy.com".  Looks different than yours.

Any assistance would be appreciated!

Jim


Kerry,

Here is some more info that may help.

Pathname to SDE layer:
S:\General-Offices-GO-Trans\SLR-Mapping\GIS_Analysis\GIS_Data\LAND_P.sde\PARCELS.PARCELS

Pathname to lookup table:
S:\General-Offices-GO-Trans\SLR-Mapping\GIS_Analysis\GIS_Data\County_Boundaries\Minnesota\mn\County_List_MN.dbf

Jim
0 Kudos
KerryAlley
Occasional Contributor
Hi Jim,

The paths do help.  It isn't clear to me, however, exactly what information is in your lookup table or how you want to use it.  For example, does the lookup table identify which fips codes belong to which state?  If so, how?  Is every fips code listed in one field, with another field providing the name of the state the code belongs to?  Will each shape file correspond to a single or multiple fips codes?  I would need to understand these kinds of relationships between relevant fields, and to know the names of the fields, in order to incorporate the lookup table into the script.

Kerry
0 Kudos
JimFritz
Occasional Contributor
Hi Jim,

The paths do help.  It isn't clear to me, however, exactly what information is in your lookup table or how you want to use it.  For example, does the lookup table identify which fips codes belong to which state?  If so, how?  Is every fips code listed in one field, with another field providing the name of the state the code belongs to?  Will each shape file correspond to a single or multiple fips codes?  I would need to understand these kinds of relationships between relevant fields, and to know the names of the fields, in order to incorporate the lookup table into the script.

Kerry


Kerry,
The information in the lookup table identifys all 87 unique fips codes for Minnesota but the feature class of parcel data includes other states so that's why there is a state field in the lookup table as well, all with MN as the attribute. So yes, every fips listed in one field and another field with state abbrev (MN), see attached table.  Each exported shapefile should correspond to a single fips code.  Also, the path to the SDE layer is as follows:  Database Connections\LAND_P.sde
The feature class is called:  PARCELS.PARCELS

Hope this all helps!

Jim
0 Kudos
JimFritz
Occasional Contributor
Kerry,
The information in the lookup table identifys all 87 unique fips codes for Minnesota but the feature class of parcel data includes other states so that's why there is a state field in the lookup table as well, all with MN as the attribute. So yes, every fips listed in one field and another field with state abbrev (MN), see attached table.  Each exported shapefile should correspond to a single fips code.  Also, the path to the SDE layer is as follows:  Database Connections\LAND_P.sde
The feature class is called:  PARCELS.PARCELS

Hope this all helps!

Jim


Oh, I forgot the attributes of the PARCELS.PARCELS table.  They are:

FIPS
and
STATE_CODE

thanks!

Jim
0 Kudos