Backing Up Files Using Model Builder

1868
13
06-15-2012 08:22 AM
by Anonymous User
Not applicable
Original User: MCline19

I am trying to create a model, using model builder, that will back up multiple files under certain conditions.  The files being backed up are .sde files and I need them to be backed up as .shp files.  I am using the "Feature Class To Shapefile (multiple)" conversion tool to accomplish this. 

The conditions I need to meet include:
1. Keeps current file names
2. Overwrites existing files
3. Only backup files which have been modified since the previous backup

Currently, using the "Feature Class to Shapefile (multiple)" conversion tool, I have been able to meet my first two conditions; however I have not been able to figure out how to satisfy my third condition or if their is a tool capable of doing this.

I would appreciate any advise on how to solve this issue. 
THANKS!
Marie
0 Kudos
13 Replies
by Anonymous User
Not applicable
Original User: NobbirAhmed

You don't get what you want for 2 and 3 with Feature Class to Shapefile (multiple).

2. The tool does not override if a file already exists. It appends an underscore and a number to the name. So, if rivers.shp exists then the tool, when you try copy again, will name the data rivers_1.shp

3. The tool does not compare states.

For the 3rd condition you can use Feature Compare tool. For doing that your workflow will be:

- Make copies (using Copy Features in batch mode) of all original data to a base SDE location. These will be your base data to compare with. Ideally, base data should be in SDE workspace.

- As Feature Class To Shapefile will not override your existing data, I would suggest using Copy Features in batch mode.

- When updating (if you don't use SDE base data):
first compare SDE current data with the base SDE data (using, for example, Feature Compare). If a dataset is changed the tool will return False in which case copy that data as a shapefile to the folder. Also, update the base data with the changed SDE data.
ShitijMehta
Esri Regular Contributor
Try the feature Compare tool in your model.
I am assuming you are using the Feature Class Iterator in your model to iterate and copy your feature classes.
Use the Feature Compare tool and for the test feature class parameter (open the tool dialog. It  is the second parameter) give the path to your workspace that already contains the feature classes from previous backup : some thing like this C://Backup/%Name%. This %Name% is the variable name of the output of the Iterator. As long as the feature classes you are copying and the feature classes that already exists share the same name this will work.  For the first time you can just copy the feature class without worrying about copying only the feature classes that have been modified.

One of the outputs of  the feature compare tool is Compare status which becomes false if the feature classes you are comparing are different. You will have to set an if-then-else condition here to say if it is false run the feature class to shapefile tool, else do nothing.
There is a series of blogs on if-then-else blogs that will help you.

If you are stuck at "if" �?? Part 1
If you are stuck at "if" �?? Part 2 �?? Example of using Script tool to create branches using if-els...
If you are stuck at "if" �?? Part 3 �?? Does Extension Exists model example
If you are stuck at "if" �?? Part 4 �?? Does Selection Exists model example

For your case just using the Calculate Value tool as shown in this blog If you are stuck at "if" �?? Part 1 will suffice.
0 Kudos
by Anonymous User
Not applicable
Original User: shitijmehta

As Nobbir suggested you can use the Copy Features tool.
0 Kudos
by Anonymous User
Not applicable
Original User: MCline19

The base data I am using are .sde files in a sde location.  When I try to make copies (using Copy Features) of the original .sde data, with my output location outside of the sde database, I am returned an error (which says, "A locator with this name does not exist.").  I need the output location to be outside of the sde database, which seems to be causing the problem. 

Am I doing something wrong or is there something I can do to make this work?

Thank you!
0 Kudos
NobbirAhmed
Esri Regular Contributor
Can you try copying one feature class manually?

Rigth-click on your data in the SDE database and select Copy...

Then, right-click on the local file geodatabase (outside of any SDE) and paste it.

Does it work?
0 Kudos
by Anonymous User
Not applicable
Original User: bblankner

Hi.  I'm helping Marie get this project done in her office.  We have the compare tool working and it outputs two items - 1. Output compare, and 2. Compare status. 

Compare status is a boolean.  How exactly do we connect that to the rest of the model that executes?  Do we create an if-then code block and then draw a line from the Compare Status to it?  And what should go in the if-then code block?  We're trying to get it to work, but keep hitting dead ends.

Thanks!
0 Kudos
NobbirAhmed
Esri Regular Contributor
What values you are setting for your Compare Status output? I guess True/False. Just connect your next step to this output. When you run your model the subsequent steps will only be executed if the status is True.
0 Kudos
by Anonymous User
Not applicable
Original User: shitijmehta

Hi

Did you try the if-then-else blogs? Please try the Part 1 using Calculate Value tool.

One of the outputs of the feature compare tool is Compare status which becomes false if the feature classes you are comparing are different. You will have to set an if-then-else condition here to say if it is false run the feature class to shapefile tool, else do nothing. The sequence of tools would be


  1. Feature Compare

  2. Calculate Value with if-then-else condition. Connect the output of feature compare tool to the calculate value tool as a precondition. Pass the variable name of the output as inline variable in the Calculate Value tool like this %Compare Status%. See examples in the Part 1 blog. Your code has to say if the variable value is false return true. Set the data type parameter of the Calculate Value to Boolean.

  3. Feature Class to Shapefile tool with the output of the Calculate Value tool connected to the Feature Class to Feature Class tool as a precondition.



There is a series of blogs on if-then-else blogs that will help you.
If you are stuck at "if" �?? Part 1
If you are stuck at "if" �?? Part 2 �?? Example of using Script tool to create branches using if-els...
If you are stuck at "if" �?? Part 3 �?? Does Extension Exists model example
If you are stuck at "if" �?? Part 4 �?? Does Selection Exists model example

For your case just using the Calculate Value tool as shown in this blog If you are stuck at "if" �?? Part 1 will suffice.
0 Kudos
by Anonymous User
Not applicable
Original User: MCline19

Shitijmehta,
This is how I am understanding your explaination of how to implement the If-Then condition using the Calculate Value tool; however, I'm sure my code block syntax is incorrect.

Expression: %CompareStatus(2)%

Code Block:
IF %CompareStatus(2)% is false THEN
return true
ELSE IF %CompareStatus(2)% is true THEN
return false
ELSE end processing

Data type:
Boolean

After entering this information into the Calculate Value tool, the tool will still not accept a connection from the CompareStatus(2) output. It returns the following error:

The Boolean value true does not meet the input requirements for any of the parameters of the Calculate Value tool.
Expression: (null)
Code Block: (null)
Data type: (null)

As always, thank you for your help!
0 Kudos