Definition Queries and exporting to shapefile

02-16-2017 07:48 AM
New Contributor III

Hi, I'm fairly new to python and was able to figure out how to do an export from our organization's SDE feature class to a shapefile through python. I'm trying to figure out how to do a an EQUAL TO definition from my SDE feature class and then have it export it to a shapefile with the definition query. For example, I have a feature class in SDE of sewer manholes and within that feature class I'm trying to pull out just the abandoned manholes and have be its own shapefile.

Any tips, suggestions, or sample codes would be helpful.

I've also attached a screen shot of the code I'm using to the feature class into a shapefile. I just need to add into that for the definition query portion of my task.


Tags (1)
0 Kudos
3 Replies
Frequent Contributor

I would suggest making a Feature Layer, which would allow you to use a query to subset your data down to what you want prior to converting it to a shapefile.  Then use that Feature Layer as your input for feature class to shapefile.

Conversely you can do a select by attribute and do something similar to this post.

Either way take a look at Josh Bixby's post in that link above about properly formatting SQL queries in Python, will help you get the syntax right.

New Contributor III

Making the feature class into a Feature Layer worked!

Thanks for your suggestion

0 Kudos
MVP Honored Contributor

You can use the Select geoprocessing tool to do this in a single step.