Select to view content in your preferred language

Run buffer automatically when new data is registered.

1664
5
08-12-2016 09:47 AM
EvelynHernandez
Frequent Contributor

Hello,

Im pretty new on Geoprocessing tools and running automatic process in arcmap.

I wanna know if theres a way to run a buffer automatically when new data is found in a db table, layer or anything else i wanna use.

I just created a buffer in the toolbox and i save it, the structure is :

my layer -> buffer tool -> output file.

I save it and im trying to generate the python code to simulate the data will be loaded in that layer (its an example) and then i generate the buffer as a result.

My python code is going like this.

import arcpy

from arcpy import env

import arcgis

arcpy.ImportToolbox("C:\Users\myuser\Documents\ArcGIS\Toolbox","BufferTramosSelected")

arcpy.BufferTramosSelected_BufferTramosSelected() 

import time

mins = 0

while mins != 5:

  print ">>>", mins

  arcpy.BufferTramosSelected_BufferTramosSelected() 

  time.sleep(30)

  mins+=1

So is that correct? or theres another way to do this?

I need suggestions and code (if somebody already do this).

Thanks in advice!

0 Kudos
5 Replies
BlakeTerhune
MVP Regular Contributor

The Buffer geoprocessing tool is available in arcpy so you shouldn't need to make your own toolbox and import it. Could you clarify what exact circumstance you want to run this buffer? Is it when a new feature class is registered as versioned? Is it just when new data is added to an existing feature class? Is it on a schedule?

EvelynHernandez
Frequent Contributor

Lets say.

I have a db table that in certain moment the data that it has will be updated, so each time when that happen i need to run a buffer.

I wanna know how to run a script automatically (via scheduled task or something else) that allows me to run the buffer to keep a service updated(a layer that shows the result in a web app with a map) .

0 Kudos
JamesCrandall
MVP Frequent Contributor

I wanna know how to run a script automatically (via scheduled task or something else) that allows me to run the buffer to keep a service updated(a layer that shows the result in a web app with a map) .

You do this by writing your .py script that performs the desired service updating, create a .bat or .cmd that starts python.exe and runs your .py script and then create the scheduled event to point to the .bat/.cmd file.  The .bat should look something like this:

C:\Python27\ArcGIS10.2\python.exe E:\MyScript.py

0 Kudos
EvelynHernandez
Frequent Contributor

OK, but my last question is: the script that  i showed in the first comment is the way to do it? I mean , can i include that one or im missing something? (the logic)

Thanks in advice!

0 Kudos
JamesCrandall
MVP Frequent Contributor

I don't know why you need to import a toolbox to perform that operation.  Just add the required methods and parameters in the script you intend to run on a schedule.