0

I'm struggling to use the describe function to find the spatial reference of a given shapefile and then apply it to another shapefile which has been copied to a projected folder.

I'm relatively new to using python so I apologize if my code attempt is dismal.

This is where I'm at:

import arcpy

data = arcpy.GetParameterAsText(0)
targetProjection = arcpy.GetParameterAsText(1)
projected = arcpy.GetParameterAsText(2)

# Create an error class
class NoExist(Exception):
    pass

try:

 # copy dataset to projected dataset folder
    arcpy.copyFeatures_management(data, projected)

 # describe the spatial reference of the dataset in the target projection folder
    desc = arcpy.Describe(targetProjection)

    # obtain the spatial reference
    spatialRef = desc.spatialReference

I think I've worked out how to find the target projection but am unsure of how I apply that to my other dataset.

1 Answer 1

2

Have a look at the Define Projection tool and its code usage. As @dslamb points out, this method is used to assign a projection if one has not already been assigned, or if you wish to reassign a different projection. Once you have the desired SpatialReference object, you could do something like the following:

arcpy.DefineProjection_management(projected, spatialRef)

Another option, if you want to project the data from one coordinate system to another, is to use the Project tool.

4
  • I'll check it out! Appreciate the help!
    – Dave.m
    Apr 5, 2016 at 10:08
  • Define projection reassigns a projection/coordinate to an existing Feature Class. This can cause numerous problems. Based on your description it sounds like you want to use the Project tool to project an existing Feature Class to a NEW projection/coordinate system based on another Feature Class. The project tool creates a copy of the existing Feature Class and gives the new file the projection. help.arcgis.com/EN/ArcGISDesktop/10.0/Help/index.html#//…
    – dslamb
    Apr 5, 2016 at 13:21
  • "This can cause numerous problems" is a very vague and blanket statement. It is either what he is wanting to do or not.
    – Barbarossa
    Apr 5, 2016 at 13:27
  • @Barbarossa To clarify my comment: If a user uses the Define tool on a feature class and assigns the 'wrong' projection (e.g. one that is not what the geometry is actually in) then the problems will be: on the fly projection will not work properly, geoprocessing scripts will not work, projecting the feature class using the Project tool will not actually project the geometry...etc. I just have seen a lot of people use the Define tool as if it were the Project tool without realizing its consequences, and I just wanted to make sure he got to the tool he needed (whichever one it might be).
    – dslamb
    Apr 6, 2016 at 18:06

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

Not the answer you're looking for? Browse other questions tagged or ask your own question.