Getting and editing list of strings from file geodatabaseTransforming file geodatabase feature classes from custom local coordinate system?Renaming shapefiles with prefix while running arcpy.FeatureClassToGeodatabase?Copying ArcSDE geodatabase to file geodatabase using ArcPy?Listing all feature datasets and classes from multiple geodatabase into CSV file?List File Geodatabase TopologyConverting multiple File geodatabase (.gdb) into multiple Personal geodatabase (.mdb)Create FeatureDataSet in geodatabase with Arcpy from a tableGetting full path of empty sde feature datasets (Children property from arcpy.Describe object won't work))Creating python dictionary that maps each domain to multiple coded values in File Geodatabase?Using arcpy.da.Walk to go through many file geodatabases

Why is it harder to turn a motor/generator with shorted terminals?

Chinese words with non-Chinese letters / characters?

Why do galaxies collide

Why are BJTs common in output stages of power amplifiers?

Were any toxic metals used in the International Space Station?

Find the unknown area, x

Wireless headphones interfere with Wi-Fi signal on laptop

Why does SSL Labs now consider CBC suites weak?

A case where Bishop for knight isn't a good trade

Why didn't the Avengers use this object earlier?

Do Grothendieck universes matter for an algebraic geometer?

Getting and editing list of strings from file geodatabase

Single word that parallels "Recent" when discussing the near future

Would life always name the light from their sun "white"

Was this seat-belt sign activation standard procedure?

Offered a new position but unknown about salary?

Show solution to recurrence is never a square

Filter a data-frame and add a new column according to the given condition

Why do the lights go out when someone enters the dining room on this ship?

Did galley captains put corks in the mouths of slave rowers to keep them quiet?

What information exactly does an instruction cache store?

How can two continuations cancel each other out?

Is it wrong to omit object pronouns in these sentences?

Tube from Heathrow to King's Cross



Getting and editing list of strings from file geodatabase


Transforming file geodatabase feature classes from custom local coordinate system?Renaming shapefiles with prefix while running arcpy.FeatureClassToGeodatabase?Copying ArcSDE geodatabase to file geodatabase using ArcPy?Listing all feature datasets and classes from multiple geodatabase into CSV file?List File Geodatabase TopologyConverting multiple File geodatabase (.gdb) into multiple Personal geodatabase (.mdb)Create FeatureDataSet in geodatabase with Arcpy from a tableGetting full path of empty sde feature datasets (Children property from arcpy.Describe object won't work))Creating python dictionary that maps each domain to multiple coded values in File Geodatabase?Using arcpy.da.Walk to go through many file geodatabases






.everyoneloves__top-leaderboard:empty,.everyoneloves__mid-leaderboard:empty,.everyoneloves__bot-mid-leaderboard:empty margin-bottom:0;








3















I have a file GDB that contains Annotation and Polygon feature classes. I would like to create a list of strings with the first part of the name of the polygon features. For example in the data below I would like to create a list that would appear like the following -



['Canal', 'CanalAreas']



Data Example



I have used ListFeatureClasses in order to get a list of all the polygon classes, but I'm a lot a loss of what the next step is, - a LEN() style function to move the last 6 characters?



lookfor = []
for dataset in arcpy.ListDatasets():
for fc in arcpy.ListFeatureClasses("*", "Polygon", dataset):
lookfor.append(fc)

for fc in arcpy.ListFeatureClasses("*", "Polygon"):
lookfor.append(fc)


I currently have this list hard coded in another script and would like to make it more dynamic so I don't have to worry about data changes etc. Any advice or help would be greatly appreciated.










share|improve this question

















  • 1





    Do you want the part before the first underscore? fcBase = fc.split('_')[0] then if fcBase not in lookfor: lookfor.append(fcBase) - probably best to cast fc = fc.lower() first though to avoid multiple items with slightly different case (CanalAreas is not the same as canalareas). Also consider using arcpy.da.Walk resources.arcgis.com/en/help/main/10.2/018w/… then you won't have to loop for all standalone then all feature classes in feature datasets.

    – Michael Stimson
    1 hour ago


















3















I have a file GDB that contains Annotation and Polygon feature classes. I would like to create a list of strings with the first part of the name of the polygon features. For example in the data below I would like to create a list that would appear like the following -



['Canal', 'CanalAreas']



Data Example



I have used ListFeatureClasses in order to get a list of all the polygon classes, but I'm a lot a loss of what the next step is, - a LEN() style function to move the last 6 characters?



lookfor = []
for dataset in arcpy.ListDatasets():
for fc in arcpy.ListFeatureClasses("*", "Polygon", dataset):
lookfor.append(fc)

for fc in arcpy.ListFeatureClasses("*", "Polygon"):
lookfor.append(fc)


I currently have this list hard coded in another script and would like to make it more dynamic so I don't have to worry about data changes etc. Any advice or help would be greatly appreciated.










share|improve this question

















  • 1





    Do you want the part before the first underscore? fcBase = fc.split('_')[0] then if fcBase not in lookfor: lookfor.append(fcBase) - probably best to cast fc = fc.lower() first though to avoid multiple items with slightly different case (CanalAreas is not the same as canalareas). Also consider using arcpy.da.Walk resources.arcgis.com/en/help/main/10.2/018w/… then you won't have to loop for all standalone then all feature classes in feature datasets.

    – Michael Stimson
    1 hour ago














3












3








3








I have a file GDB that contains Annotation and Polygon feature classes. I would like to create a list of strings with the first part of the name of the polygon features. For example in the data below I would like to create a list that would appear like the following -



['Canal', 'CanalAreas']



Data Example



I have used ListFeatureClasses in order to get a list of all the polygon classes, but I'm a lot a loss of what the next step is, - a LEN() style function to move the last 6 characters?



lookfor = []
for dataset in arcpy.ListDatasets():
for fc in arcpy.ListFeatureClasses("*", "Polygon", dataset):
lookfor.append(fc)

for fc in arcpy.ListFeatureClasses("*", "Polygon"):
lookfor.append(fc)


I currently have this list hard coded in another script and would like to make it more dynamic so I don't have to worry about data changes etc. Any advice or help would be greatly appreciated.










share|improve this question














I have a file GDB that contains Annotation and Polygon feature classes. I would like to create a list of strings with the first part of the name of the polygon features. For example in the data below I would like to create a list that would appear like the following -



['Canal', 'CanalAreas']



Data Example



I have used ListFeatureClasses in order to get a list of all the polygon classes, but I'm a lot a loss of what the next step is, - a LEN() style function to move the last 6 characters?



lookfor = []
for dataset in arcpy.ListDatasets():
for fc in arcpy.ListFeatureClasses("*", "Polygon", dataset):
lookfor.append(fc)

for fc in arcpy.ListFeatureClasses("*", "Polygon"):
lookfor.append(fc)


I currently have this list hard coded in another script and would like to make it more dynamic so I don't have to worry about data changes etc. Any advice or help would be greatly appreciated.







arcpy arcgis-10.1 file-geodatabase






share|improve this question













share|improve this question











share|improve this question




share|improve this question










asked 1 hour ago









occystrapoccystrap

353




353







  • 1





    Do you want the part before the first underscore? fcBase = fc.split('_')[0] then if fcBase not in lookfor: lookfor.append(fcBase) - probably best to cast fc = fc.lower() first though to avoid multiple items with slightly different case (CanalAreas is not the same as canalareas). Also consider using arcpy.da.Walk resources.arcgis.com/en/help/main/10.2/018w/… then you won't have to loop for all standalone then all feature classes in feature datasets.

    – Michael Stimson
    1 hour ago













  • 1





    Do you want the part before the first underscore? fcBase = fc.split('_')[0] then if fcBase not in lookfor: lookfor.append(fcBase) - probably best to cast fc = fc.lower() first though to avoid multiple items with slightly different case (CanalAreas is not the same as canalareas). Also consider using arcpy.da.Walk resources.arcgis.com/en/help/main/10.2/018w/… then you won't have to loop for all standalone then all feature classes in feature datasets.

    – Michael Stimson
    1 hour ago








1




1





Do you want the part before the first underscore? fcBase = fc.split('_')[0] then if fcBase not in lookfor: lookfor.append(fcBase) - probably best to cast fc = fc.lower() first though to avoid multiple items with slightly different case (CanalAreas is not the same as canalareas). Also consider using arcpy.da.Walk resources.arcgis.com/en/help/main/10.2/018w/… then you won't have to loop for all standalone then all feature classes in feature datasets.

– Michael Stimson
1 hour ago






Do you want the part before the first underscore? fcBase = fc.split('_')[0] then if fcBase not in lookfor: lookfor.append(fcBase) - probably best to cast fc = fc.lower() first though to avoid multiple items with slightly different case (CanalAreas is not the same as canalareas). Also consider using arcpy.da.Walk resources.arcgis.com/en/help/main/10.2/018w/… then you won't have to loop for all standalone then all feature classes in feature datasets.

– Michael Stimson
1 hour ago











1 Answer
1






active

oldest

votes


















2














If you always want the part before first underscore then split at this and fetch first item (index 0) in split list. Set will remove duplicates.



import arcpy
arcpy.env.workspace = r'C:Default.gdb'
polygons = list(set([fc.split('_')[0] for fc in arcpy.ListFeatureClasses(feature_type='POLYGON')]))


You can also use re module to split at first non-letter charachter:



import re
polygons = list(set([re.split('[^a-zA-Z]',fc)[0] for fc in arcpy.ListFeatureClasses(feature_type='POLYGON')]))





share|improve this answer




















  • 2





    Thanks Bera, this looks great. Upon using the code I noticed the first underscore was not always the right one, so I made a small adjustment like so - polygons = list(set([fc[:-6] for fc in arcpy.ListFeatureClasses(feature_type='POLYGON')]))

    – occystrap
    27 mins ago











Your Answer








StackExchange.ready(function()
var channelOptions =
tags: "".split(" "),
id: "79"
;
initTagRenderer("".split(" "), "".split(" "), channelOptions);

StackExchange.using("externalEditor", function()
// Have to fire editor after snippets, if snippets enabled
if (StackExchange.settings.snippets.snippetsEnabled)
StackExchange.using("snippets", function()
createEditor();
);

else
createEditor();

);

function createEditor()
StackExchange.prepareEditor(
heartbeatType: 'answer',
autoActivateHeartbeat: false,
convertImagesToLinks: false,
noModals: true,
showLowRepImageUploadWarning: true,
reputationToPostImages: null,
bindNavPrevention: true,
postfix: "",
imageUploader:
brandingHtml: "Powered by u003ca class="icon-imgur-white" href="https://imgur.com/"u003eu003c/au003e",
contentPolicyHtml: "User contributions licensed under u003ca href="https://creativecommons.org/licenses/by-sa/3.0/"u003ecc by-sa 3.0 with attribution requiredu003c/au003e u003ca href="https://stackoverflow.com/legal/content-policy"u003e(content policy)u003c/au003e",
allowUrls: true
,
onDemand: true,
discardSelector: ".discard-answer"
,immediatelyShowMarkdownHelp:true
);



);













draft saved

draft discarded


















StackExchange.ready(
function ()
StackExchange.openid.initPostLogin('.new-post-login', 'https%3a%2f%2fgis.stackexchange.com%2fquestions%2f322660%2fgetting-and-editing-list-of-strings-from-file-geodatabase%23new-answer', 'question_page');

);

Post as a guest















Required, but never shown

























1 Answer
1






active

oldest

votes








1 Answer
1






active

oldest

votes









active

oldest

votes






active

oldest

votes









2














If you always want the part before first underscore then split at this and fetch first item (index 0) in split list. Set will remove duplicates.



import arcpy
arcpy.env.workspace = r'C:Default.gdb'
polygons = list(set([fc.split('_')[0] for fc in arcpy.ListFeatureClasses(feature_type='POLYGON')]))


You can also use re module to split at first non-letter charachter:



import re
polygons = list(set([re.split('[^a-zA-Z]',fc)[0] for fc in arcpy.ListFeatureClasses(feature_type='POLYGON')]))





share|improve this answer




















  • 2





    Thanks Bera, this looks great. Upon using the code I noticed the first underscore was not always the right one, so I made a small adjustment like so - polygons = list(set([fc[:-6] for fc in arcpy.ListFeatureClasses(feature_type='POLYGON')]))

    – occystrap
    27 mins ago















2














If you always want the part before first underscore then split at this and fetch first item (index 0) in split list. Set will remove duplicates.



import arcpy
arcpy.env.workspace = r'C:Default.gdb'
polygons = list(set([fc.split('_')[0] for fc in arcpy.ListFeatureClasses(feature_type='POLYGON')]))


You can also use re module to split at first non-letter charachter:



import re
polygons = list(set([re.split('[^a-zA-Z]',fc)[0] for fc in arcpy.ListFeatureClasses(feature_type='POLYGON')]))





share|improve this answer




















  • 2





    Thanks Bera, this looks great. Upon using the code I noticed the first underscore was not always the right one, so I made a small adjustment like so - polygons = list(set([fc[:-6] for fc in arcpy.ListFeatureClasses(feature_type='POLYGON')]))

    – occystrap
    27 mins ago













2












2








2







If you always want the part before first underscore then split at this and fetch first item (index 0) in split list. Set will remove duplicates.



import arcpy
arcpy.env.workspace = r'C:Default.gdb'
polygons = list(set([fc.split('_')[0] for fc in arcpy.ListFeatureClasses(feature_type='POLYGON')]))


You can also use re module to split at first non-letter charachter:



import re
polygons = list(set([re.split('[^a-zA-Z]',fc)[0] for fc in arcpy.ListFeatureClasses(feature_type='POLYGON')]))





share|improve this answer















If you always want the part before first underscore then split at this and fetch first item (index 0) in split list. Set will remove duplicates.



import arcpy
arcpy.env.workspace = r'C:Default.gdb'
polygons = list(set([fc.split('_')[0] for fc in arcpy.ListFeatureClasses(feature_type='POLYGON')]))


You can also use re module to split at first non-letter charachter:



import re
polygons = list(set([re.split('[^a-zA-Z]',fc)[0] for fc in arcpy.ListFeatureClasses(feature_type='POLYGON')]))






share|improve this answer














share|improve this answer



share|improve this answer








edited 37 mins ago

























answered 42 mins ago









BERABERA

18.2k62145




18.2k62145







  • 2





    Thanks Bera, this looks great. Upon using the code I noticed the first underscore was not always the right one, so I made a small adjustment like so - polygons = list(set([fc[:-6] for fc in arcpy.ListFeatureClasses(feature_type='POLYGON')]))

    – occystrap
    27 mins ago












  • 2





    Thanks Bera, this looks great. Upon using the code I noticed the first underscore was not always the right one, so I made a small adjustment like so - polygons = list(set([fc[:-6] for fc in arcpy.ListFeatureClasses(feature_type='POLYGON')]))

    – occystrap
    27 mins ago







2




2





Thanks Bera, this looks great. Upon using the code I noticed the first underscore was not always the right one, so I made a small adjustment like so - polygons = list(set([fc[:-6] for fc in arcpy.ListFeatureClasses(feature_type='POLYGON')]))

– occystrap
27 mins ago





Thanks Bera, this looks great. Upon using the code I noticed the first underscore was not always the right one, so I made a small adjustment like so - polygons = list(set([fc[:-6] for fc in arcpy.ListFeatureClasses(feature_type='POLYGON')]))

– occystrap
27 mins ago

















draft saved

draft discarded
















































Thanks for contributing an answer to Geographic Information Systems Stack Exchange!


  • Please be sure to answer the question. Provide details and share your research!

But avoid


  • Asking for help, clarification, or responding to other answers.

  • Making statements based on opinion; back them up with references or personal experience.

To learn more, see our tips on writing great answers.




draft saved


draft discarded














StackExchange.ready(
function ()
StackExchange.openid.initPostLogin('.new-post-login', 'https%3a%2f%2fgis.stackexchange.com%2fquestions%2f322660%2fgetting-and-editing-list-of-strings-from-file-geodatabase%23new-answer', 'question_page');

);

Post as a guest















Required, but never shown





















































Required, but never shown














Required, but never shown












Required, but never shown







Required, but never shown

































Required, but never shown














Required, but never shown












Required, but never shown







Required, but never shown







Popular posts from this blog

Log på Navigationsmenu

Wonderful Copenhagen (sang) Eksterne henvisninger | NavigationsmenurSide på frankloesser.comWonderful Copenhagen

Detroit Tigers Spis treści Historia | Skład zespołu | Sukcesy | Członkowie Baseball Hall of Fame | Zastrzeżone numery | Przypisy | Menu nawigacyjneEncyclopedia of Detroit - Detroit TigersTigers Stadium, Detroit, MITigers Timeline 1900sDetroit Tigers Team History & EncyclopediaTigers Timeline 1910s1935 World Series1945 World Series1945 World Series1984 World SeriesComerica Park, Detroit, MI2006 World Series2012 World SeriesDetroit Tigers 40-Man RosterDetroit Tigers Coaching StaffTigers Hall of FamersTigers Retired Numberse