how to set up automate from shapefile to sde connection? Can it be command or other recommend?

2769
9
Jump to solution
08-23-2017 08:35 AM
AlexP_
by
Occasional Contributor III

how to set up automate from shapefile to sde feature class connection? Can it be command or other recommend? Please advise.

Thank you.

0 Kudos
1 Solution

Accepted Solutions
JakeSkinner
Esri Esteemed Contributor

Hi Alexis,

You can use the feature class to feature class function via Python to automate converting a shapefile to an SDE feature class.

Feature Class to Feature Class—Help | ArcGIS Desktop 

View solution in original post

9 Replies
JakeSkinner
Esri Esteemed Contributor

Hi Alexis,

You can use the feature class to feature class function via Python to automate converting a shapefile to an SDE feature class.

Feature Class to Feature Class—Help | ArcGIS Desktop 

AlexP_
by
Occasional Contributor III

I set it up and it is working however how do i set it up every time I make change from shapefile to SDE feature class? I don't see change on SDE feature from shapefile.   Am I missing something?  For example, weekly Monday import shapefile from SDE feature class.

0 Kudos
SethLewis1
Occasional Contributor III

Alexis,

It sounds like Windows Task Scheduler offers the functionality that you're seeking.

AlexP_
by
Occasional Contributor III

Yes. This is what I am looking for. However, python script turned out an error when it tried to run. It is working fine inside ArcMap with Pyrhon window (arcpy)? I put overwrite the outputs of geoprocessing operations. It is succeeded. However, when I tried to run on Python script itself, it gave me an error. How can I fix it? See this message below. 

I used script in ArcMap with Python Window and it succeeded:

import arcpy
arcpy.env.workspace = "N:\_Alexis\GISData\Pubshp\CityHall.shp"
arcpy.FeatureClassToFeatureClass_conversion("CityHall",
"Database Connections\SDE.sde",
"CityHall2")

This is used in python script I used the same from ArcMap and gave me an error when I tried to run it. 

Traceback (most recent call last):
File "N:\_Alexis\GIS ArcPy\TEST_CityHall2.py", line 5, in <module>
"CityHall2")
File "C:\Program Files (x86)\ArcGIS\Desktop10.3\ArcPy\arcpy\conversion.py", line 1790, in FeatureClassToFeatureClass
raise e
ExecuteError: ERROR 000258: Output Database Connections\SDE.sde\CityHall2 already exists
Failed to execute (FeatureClassToFeatureClass).

0 Kudos
MicahBabinski
Occasional Contributor III

Hi Alexis,

Try this line of code right after you import arcpy:

arcpy.env.overwriteOutput = True

That should tell your geoprocessing environment to overwrite outputs if they exist already.

Micah

AlexP_
by
Occasional Contributor III

I recent run again and it gave me an error.

Traceback (most recent call last):
File "N:\_Alexis\GIS ArcPy\TEST_CityHall2.py", line 6, in <module>
"CityHall2")
File "C:\Program Files (x86)\ArcGIS\Desktop10.3\ArcPy\arcpy\conversion.py", line 1790, in FeatureClassToFeatureClass
raise e
ExecuteError: ERROR 000258: Output Database Connections\SDE.sde\CityHall2 already exists
Failed to execute (FeatureClassToFeatureClass).

I added it.

 

import arcpy
arcpy.env.overwriteOutput = True
arcpy.env.workspace = "N:\_Alexis\GISData\Pubshp\CityHall.shp"
arcpy.FeatureClassToFeatureClass_conversion("CityHall", 
"Database Connections\SDE.sde", 
"CityHall2")

0 Kudos
AlexP_
by
Occasional Contributor III

I figured it out the correct python script. It is working now.  

# Name: FeatureClassToFeatureClass_Example2.py
# Description: Use FeatureClassToFeatureClass with an expression to create a subset
# of the original feature class.

# Import system modules
import arcpy

arcpy.env.overwriteOutput = True

# Set environment settings
arcpy.env.workspace = "N:\_Alexis\GISData\Pubshp\CityHall.shp"

# Set local variables
inFeatures = "CityHall"
outLocation = "Database Connections\SDE.sde"
outFeatureClass = "CityHall2"

# Execute FeatureClassToFeatureClass
arcpy.FeatureClassToFeatureClass_conversion(inFeatures, outLocation,
outFeatureClass)

VinceAngelo
Esri Esteemed Contributor

It's important to keep in mind that enterprise geodatabases contain tables, not files, and that some of the usual practices which are casual about deletion and re-population in file-based storage mechanisms would be better off being redesigned to be less brutal on table elimination and creation in databases. For example, if the shapefile schema isn't changing with each release, using Truncate Table and Append would be less burdensome on the database, and would have the side effect of not needing an explicit delete or initializing the environment to permit target overwrite.

- V

AlexP_
by
Occasional Contributor III

I added it and there is no error message. I think it is working.  Thanks!

import arcpy
arcpy.env.overwriteOutput = True
arcpy.env.workspace = "N:\_Alexis\GISData\Pubshp\CityHall.shp"
arcpy.FeatureClassToFeatureClass_conversion("CityHall",
"Database Connections\SDE.sde",
"CityHall2")

This is what I got result:  It seems working. 

>>> ================================ RESTART ================================
>>>
>>>

Do you know what script is it? What do you recommend to set up python script that included whole feature class like drawing and tables?

0 Kudos