Last active
August 29, 2015 14:17
-
-
Save cindygis/9c48afcd50351680172e to your computer and use it in GitHub Desktop.
Projects feature classes to Web Mercator (Auxiliary Sphere) if they are not in it already.
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
# | |
# @date 24/03/2015 | |
# @author Cindy Williams | |
# | |
# Projects feature classes to Web Mercator (Auxiliary Sphere) | |
# if they are not in it already. | |
# | |
# For use as a standalone script. | |
# | |
import arcpy | |
import os | |
arcpy.env.workspace = r"C:\Database Connections\work.sde" | |
# Create spatial reference using the WKID | |
sr_web = arcpy.SpatialReference(3857) | |
gdb = r"C:\Some\Arb\Folder\web.gdb" | |
fds_list = [] # List for existing feature datasets | |
# Loop over all feature datasets in workspace | |
for fds in arcpy.ListDatasets(feature_type="Feature"): | |
desc = arcpy.Describe(fds) | |
# Check if the spatial reference of the feature dataset | |
# is different to 3857 | |
if desc.spatialReference.name != sr_web.name: | |
fds_list.append(fds) | |
# Loop over feature datasets in list | |
for fd in fds_list: | |
# Create a copy of it with correct projection | |
arcpy.management.CreateFeatureDataset(gdb, | |
fd.rpartition(".")[2], | |
sr_web) | |
print("Created feature dataset: " + fd) | |
# Loop over feature classes within the feature dataset | |
# within the workspace | |
for ftr in arcpy.ListFeatureClasses(feature_dataset=fd): | |
# Project the feature classes to the respective | |
# feature dataset in the new gdb | |
arcpy.management.Project(ftr, | |
os.path.join(gdb, fd.rpartition(".")[2], ftr.rpartition(".")[2]), | |
sr_web) | |
print("\tProjected " + ftr) | |
print("Script complete.") |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment