Hi all,
I'm trying to create a process in modelbuilder that will allow me to load .shp into an existing sde database.
I'm sure I need to append the new .shp to the existing database, but I'm just not sure exactly how to go about it in modelbuilder. I also need to create a loop or make a condition where the .shp are in the correct projection. As they are sometimes received in the wrong or with no projection at all.
Thanks!
Hi Matt,
To convert from shapefile to SDE feature class I'd use the Feature Class To Feature Class tool.
The projection step introduces another layer of complexity. I'm not 100% sure how to check the spatial reference of a shapefile in ModelBuilder. This is one thing arcpy is great at. If you haven't tried Python/arcpy, I'd encourage you to give it a shot. Assuming your desired spatial reference is NAD 1983 UTM Zone 10N, your script might look something like this:
# import required modules
import arcpy, os
# create variables pointing to the desired spatial reference, a folder containing your input shapefiles and your output SDE workspace
spRef = arcpy.SpatialReference(26910)
shapefile_folder = r"C:\WorkArea\ShapefilesFromContractor"
sde_workspace = r"C:\WorkArea\DatabaseConnections\MySDEWorkspace.sde"
# list all of the shapefiles in the shapefile folder
arcpy.env.workspace = shapefile_folder
shpList = arcpy.ListFeatureClasses()
# loop through the shapefiles
for shp in shpList:
# test to see if the projection is undefined
if arcpy.Describe(shp).spatialReference.GSCName == "":
# define the projection
arcpy.DefineProjection_management(shp, arcpy.SpatialReference(4269))
# project to the desired spatial reference
arcpy.Project_management(shp, os.path.join(sde_workspace, arcpy.Describe(shp).baseName), spRef)
# if it not undefined...
else:
# test to see if it is in the wrong projected coordinate system
if arcpy.Describe(shp).spatialReference.PCSCode != 26910:
# project the shapefile into the correct spatial reference, outputting to sde
arcpy.Project_management(shp, os.path.join(sde_workspace, arcpy.Describe(shp).baseName), spRef)
# otherwise, just move it to sde
else:
arcpy.FeatureClassToFeatureClass_conversion(shp, sde_workspace, arcpy.Describe(shp).baseName)
Of course, if the shapefiles come in with the spatial reference undefined, you may need to guess, sleuth out, or ask what geographic coordinate system was used to collect the data and possibly use a transformation. For instance, GPS data would likely have a geographic coordinate system of WGS 1984.
Here's the help for the geoprocessing tools that will get you there:
Feature Class To Feature Class
Good luck! Hope this helps.
Micah