Skip to main content
Question

PythonCaller ArcPy clip_analysis inputs

  • August 1, 2017
  • 4 replies
  • 93 views

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

This post is closed to further activity.
It may be an old question, an answered question, an implemented idea, or a notification-only post.
Please check post dates before relying on any information in a question or answer.
For follow-up or related questions, please post a new question or idea.
If there is a genuine update to be made, please contact us and request that the post is reopened.

4 replies

david_r
Celebrity
  • August 2, 2017

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


  • Author
  • August 2, 2017

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.

  • Author
  • August 2, 2017

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.

 

 


david_r
Celebrity
  • August 3, 2017

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.