Select to view content in your preferred language

How to copy fc datasets and define projection

1134
1
Jump to solution
01-26-2019 01:20 PM
KimCollins
New Contributor

Hello,

    I am new to the world of python. I have a geodatabase with feature datasets and multiple types of feature classes within those datasets. I'm trying to write a script that will search through the specified geodatabase and copy items into new datasets within a new geodatabase. I also need to define a projection for the data as it goes into the new gdb. 

I've been doing it manually in ArcCatalog by creating a new dataset in the target gdb and defining a projection, then importing the feature classes into it. However this has been pretty time consuming. 

This is what I have so far for my script, I think I may be completely lost and I'm not sure if .da.Walk is what I should be using

gdbFrom = arcpy.GetParameterAsText(0)
gdbTo = arcpy.GetParameterAsText(1)
Projection = arcpy.GetParameterAsText(2)

for datasets in arcpy.da.Walk(gdbFrom):
     for fc in datasets:

0 Kudos
1 Solution

Accepted Solutions
LanceCole
MVP Regular Contributor

I typically use the following for crawling through unknown database feature datasets and feature classes:

arcpy.env.workspace = gdbFrom

for ds in arcpy.ListDatasets(feature_type='feature')

   do what you need with each feature dataset
   for fc in arcpy.ListFeatureClasses(feature_dataset=ds):

      do what you need here for each feature class in a dataset

To define a spacial reference for a dataset:

cs = arcpy.SpatialReference(4326)   # for GCS_WGS_1984 as an example

arcpy.DefineProjection_management(dataset, cs)

If you are not modifying the data just applying a coodinate system and/or transformation to the dataset you could use Project—Help | ArcGIS for Desktop on each feature dataset setting your gbdFrom and gbdTo, in and out coordinate system and transformation if needed.  Do not forget about applying a transformation if need or your data may end up in the wrong part of the world.

cs = arcpy.SpatialReference(4326)   # for GCS_WGS_1984 as an example

arcpy.Project_management(gdbFrom/in_dataset, gbdTo/out_dataset, cs)

 

ListDatasets—Help | ArcGIS Desktop

ListFeatureClasses—ArcPy Functions | ArcGIS Desktop 

SpatialReference—Help | ArcGIS Desktop 

Define Projection—Help | ArcGIS Desktop 

Project—Help | ArcGIS for Desktop

View solution in original post

1 Reply
LanceCole
MVP Regular Contributor

I typically use the following for crawling through unknown database feature datasets and feature classes:

arcpy.env.workspace = gdbFrom

for ds in arcpy.ListDatasets(feature_type='feature')

   do what you need with each feature dataset
   for fc in arcpy.ListFeatureClasses(feature_dataset=ds):

      do what you need here for each feature class in a dataset

To define a spacial reference for a dataset:

cs = arcpy.SpatialReference(4326)   # for GCS_WGS_1984 as an example

arcpy.DefineProjection_management(dataset, cs)

If you are not modifying the data just applying a coodinate system and/or transformation to the dataset you could use Project—Help | ArcGIS for Desktop on each feature dataset setting your gbdFrom and gbdTo, in and out coordinate system and transformation if needed.  Do not forget about applying a transformation if need or your data may end up in the wrong part of the world.

cs = arcpy.SpatialReference(4326)   # for GCS_WGS_1984 as an example

arcpy.Project_management(gdbFrom/in_dataset, gbdTo/out_dataset, cs)

 

ListDatasets—Help | ArcGIS Desktop

ListFeatureClasses—ArcPy Functions | ArcGIS Desktop 

SpatialReference—Help | ArcGIS Desktop 

Define Projection—Help | ArcGIS Desktop 

Project—Help | ArcGIS for Desktop