How to write a script that will define missing spatial ref in a fc to match the rest of the fc in a .gdb

254
2
10-06-2021 08:15 AM
PatrickMorgan39339
New Contributor

I am taking my first Python and and it's all online and I am struggle to say the list. I have watched videos and read blogs and I haven't been able to get the slightest idea of how to do this. I have a .gbd that has 4 feature class (shapefiles) in it. My first task was to write a script that read all the spatial reference and I got that

import arcpy
arcpy.env.workspace = "C:/Users/morganp/Documents/NOTES/msu/LM 7/GrPrg_lab7data"
feature_classes = arcpy.ListFeatureClasses()
for fc in feature_classes:
    spatial_ref = arcpy.Describe(fc).spatialReference
    if spatial_ref.name == "Unknown":
        print("{} has an unknown spatial reference".format(fc))
    else:
        print("{} : {}".format(fc, spatial_ref.name))

 

My second task is to write a script that will set the one that has the unknown spatial reference to match the others

I am using IDLE Python 2.7 and ArcMap 10.7

Many thanks for all help

0 Kudos
2 Replies
DonMorrison1
Occasional Contributor III

Perhaps the DefineProjection API will do the trick.

PatrickMorgan39339
New Contributor

Thanks I actually found that page about 5 minutes after posting the question. Still working it out!!

0 Kudos