Skip to main content

I am trying to modify an FME custom transformer to run the ESRI ArcPy clip_analysis function and I'm not sure how to write the script to read the two input datasets needed for the clip_analysis.  Here is a link to the custom transformer I am modifying.  using-arcpy-for-fme-feature-processing

I have each of the datasets going into the PythonCaller and the fme_feature_type attribute is added and populated when they input into the custom transformer.

import fme
import fmeobjects
import arcpy


def processFeature(feature):
    # Get clipper and clippee FC's and settings from feature attributes
    dataset = feature.getAttribute("pre_clipped")
    arcpy.env.workspace = dataset


    # Set local variables
    inFeatures = "pre_clipped"
    clipFeatures = feature.getAttribute("clipper")
    outFeatureClass = dataset + "/clipped"


    # Execute Clip using clipper and clippee
    arcpy.Clip_analysis(inFeatures, clipFeatures, outFeatureClass)

0684Q00000ArE1BQAV.png

What are the attribute values for "pre_clipped" and "clipper" entering your custom transformer when it runs?


What are the attribute values for "pre_clipped" and "clipper" entering your custom transformer when it runs?

They are fme_feature_types assigned using the attribute creators at the beginning of the transformer workflow.

What are the attribute values for "pre_clipped" and "clipper" entering your custom transformer when it runs?

I'm sure what I have there is completely wrong. What I'm mainly trying to figure out is how to run an ArcPy clip_analysis using the FME PythonCaller. My issue is that analysis requires two separate input feature classes to run and I do not know how to make it work.

 

 


Perhaps you already know this, but you should consider FME and the arcpy geoprocessing as two completely different and unrelated programs. When you call e.g. arcpy.Clip_analysis() from FME, you're basically pausing FME to start an external program, letting FME only resume when the arcpy procedure has ended.

Some implications are

  • you cannot pass an FME feature object to arcpy, you can only pass the name of a feature class that already contains the feature.
  • calling an arcpy geoprocessing function may take a long time, so in most cases executing it on a per-feature basis should be avoided (unless you only use a single trigger feature).

If you need to perform arcpy geoprocessing on features processed by FME, this could be one way to do it:

  • Read and process the data in FME
  • Write the data using FeatureWriters rather than regular writers
  • Connect a PythonCaller to the Summary port of the FeatureWriter. If you have several FeatureWriters, user a FeatureHolder and a Sampler (sample 1st feature) to only send a single trigger feature to the PythonCaller. This ensures that all the data has been written to the Geodatabase before continuing.
  • In the PythonCaller, execute arcpy.Clip_analysis() with the names of the feature classes used in the FeatureWriter(s)
  • If you need to do further processing in FME, consider the FeatureReader to read the results from the arcpy geoprocessing back into FME.

Hope this helps.


Reply