Skip to main content
Solved

Can I pass multiple features to a Python Caller and use ArcPy in the script?


jonathanchiang0
Contributor
Forum|alt.badge.img

Hi all,

I've got a question about integrating ArcPy in FME. It would appear that FME won't let me to read in multiple features and process them using ArcPy functions through PythonCaller. This can be easily done outside FME with one line of code such as:

arcpy.LocateFeaturesAlongRoutes_lr(feats, rts, rid, tol, tbl, props)

What I would hope to achieve with PythonCaller is that it can be used just like one of the transformers like clipper and buffer. Not sure anybody else has experienced the same issue?

Thanks!

Best answer by courtney_m

@jonathanchiang0, yes, this is possible - you need to make sure you import arcpy in your script. Also, make sure you set the python interpreter in the navigation panel, as shown below:

As an example - In the screenshot below, I used a PythonCaller to take each incoming shapefile, check to see if it already exists in the specified geodatabase, and if the FC does not already exist, it imports the shapefile into the GDB.

Make sure you drag/drop parameters and attributes from the panel on the left.

-Courtney

View original
Did this help you find an answer to your question?

5 replies

courtney_m
Contributor
Forum|alt.badge.img+5
  • Contributor
  • Best Answer
  • August 11, 2017

@jonathanchiang0, yes, this is possible - you need to make sure you import arcpy in your script. Also, make sure you set the python interpreter in the navigation panel, as shown below:

As an example - In the screenshot below, I used a PythonCaller to take each incoming shapefile, check to see if it already exists in the specified geodatabase, and if the FC does not already exist, it imports the shapefile into the GDB.

Make sure you drag/drop parameters and attributes from the panel on the left.

-Courtney


bruceharold
Contributor
Forum|alt.badge.img+17
  • Contributor
  • August 11, 2017

Another option is a shutdown script.


courtney_m
Contributor
Forum|alt.badge.img+5
  • Contributor
  • August 11, 2017
bruceharold wrote:

Another option is a shutdown script.

If you decide to use a Shutdown Script, you will manually have to type in parameters with the following format: $(PARAM_NAME)

 

Another thing to be aware of with shutdown scripts, is that you cannot incorporate attribute values into your script.

 

 

An example of when it is a good idea to use a shutdown script, is if you want to compress a versioned GDB after your workspace is done writing to it. You would use the following shutdown script (where there is a user parameter called GEODATABASE_SDE_CONNECTION_FILE that references the appropriate file):

 

import arcpyarcpy.Compress_management('$(GEODATABASE_SDE_CONNECTION_FILE)')

jonathanchiang0
Contributor
Forum|alt.badge.img
courtney_m wrote:

@jonathanchiang0, yes, this is possible - you need to make sure you import arcpy in your script. Also, make sure you set the python interpreter in the navigation panel, as shown below:

As an example - In the screenshot below, I used a PythonCaller to take each incoming shapefile, check to see if it already exists in the specified geodatabase, and if the FC does not already exist, it imports the shapefile into the GDB.

Make sure you drag/drop parameters and attributes from the panel on the left.

-Courtney

@courtney_m Hi Courtney, Thanks a lot for providing such information. I am also wondering if it's possible to pass 2 or more feature types (data sets) to one python caller and let it process the data? In the python example I listed above, "feats" and "rts" represent 2 different feature classes and they were being gracefully processed through an arcpy function. Can FME handle such task?

 

 


jonathanchiang0
Contributor
Forum|alt.badge.img
Maybe I used the term "features" wrong, what I really meant is Feature Types or data sets. In the python example I listed above, "feats" and "rts" represent 2 different feature classes and they are gracefully being processed through an arcpy function. I am not sure if FME's Python Caller can handle multiple feature types at a time? Thanks.

 

 


Cookie policy

We use cookies to enhance and personalize your experience. If you accept you agree to our full cookie policy. Learn more about our cookies.

 
Cookie settings