Skip to main content

I'm wondering how to use the Python Caller transformer to run the arcpy.RepairGeometry_management geoprocessing tool.

 

I'm working with some input File Geodatabase data that's getting re-projected and producing self-intersections. The Geometry Validator transformer is identifying these but not repairing them (i.e. they come out the Failed port, not the Repaired port). I confirmed that using ArcGIS Geoprocessing tools on the same machine fixes the self-intersections, so I wanted to use the Python Caller to do the exact same thing in the context of the FME Workspace. What I'm getting is a generic error though, see below. Maybe my syntax is incorrect but I've tried a few different ways and haven't had success. Any help would be appreciated!

 

Python Syntax:

import fme

import fmeobjects

import arcpy

 

# Template Function interface:

# When using this function, make sure its name is set as the value of

# the 'Class or Function to Process Features' transformer parameter

 

def repair(feature):

   

  #Run repair geometry geoprocessing tool on each feature that failed geometry validation

  arcpy.RepairGeometry_management(feature,"DELETE NULL")

   

  pass

 

image 

Translation error:

Python Exception <RuntimeError>: Object: Error in executing tool

Error encountered while calling function `repair'

PythonCaller (PythonFactory): PythonFactory failed to process feature

A fatal error has occurred. Check the logfile above for details

 

System (I know this is old!):

FME 2019.1.3.1

ArcGIS 10.1

Python 2.7

 

 

The ArcPy RepairGeometry command will need to be performed at the Feature Class level of the geodatabase, not on individual features after they are read in by FME. Reference this article: https://community.safe.com/s/article/using-arcpy-for-fme-feature-processing. It can still be done via the PythonCaller, but you will need to define the environment workspace, and then perform the repair. If there are just certain features within the feature class you want to perform the processing on, you will need to query those out in the code by a unique ID. You can reference FME attributes in the code to accomplish that.

 

After the PythonCaller, you can use a FeatureReader to read back in the repaired geometry if you need it for additional processing in FME.


The ArcPy RepairGeometry command will need to be performed at the Feature Class level of the geodatabase, not on individual features after they are read in by FME. Reference this article: https://community.safe.com/s/article/using-arcpy-for-fme-feature-processing. It can still be done via the PythonCaller, but you will need to define the environment workspace, and then perform the repair. If there are just certain features within the feature class you want to perform the processing on, you will need to query those out in the code by a unique ID. You can reference FME attributes in the code to accomplish that.

 

After the PythonCaller, you can use a FeatureReader to read back in the repaired geometry if you need it for additional processing in FME.

Thank you @dustin​ . This works! I had read that article and just had not put it together that the arcpy.RepairGeometry is run at the feature class level as opposed to the feature level.

 

Thanks for the reply!


The error you're facing is likely due to a compatibility issue between FME 2019.1.3.1 and ArcGIS 10.1. I recommend updating your FME version to ensure compatibility. Additionally, ensure that the workspace and feature paths are correctly defined within your script.


Thank you @dustin​ . This works! I had read that article and just had not put it together that the arcpy.RepairGeometry is run at the feature class level as opposed to the feature level.

 

Thanks for the reply!

Timbo would you be willing to share your code? I'm trying to do the same exact thing.

 

Thanks!


Thank you @dustin​ . This works! I had read that article and just had not put it together that the arcpy.RepairGeometry is run at the feature class level as opposed to the feature level.

 

Thanks for the reply!

Based on some other workflow requirements, I ended up sticking this in my Startup Python script and adding logging (though not the actual arcpy log result, if anyone knows how to expose that, that would be great!). This is what I have:

 

import fme

import fmeobjects

import arcpy

import logging

 

dataset = "D:\\\\FME\\\\REMS\\\\SKE\\\\Sample_FGDB.gdb"

arcpy.env.workspace = dataset

logger = fmeobjects.FMELogFile()

 

# Execute Repair Geometry

 

try:

  arcpy.RepairGeometry_management(dataset + "/RE_HO_RIGHTS","KEEP_NULL")

  logger.logMessageString("Successfully ran Repair Geometry on RE_HO_RIGHTS")

except:

  logger.logMessageString("Could not run Repair Geometry on RE_HO_RIGHTS, it could be empty or corrupt")

try:

  arcpy.RepairGeometry_management(dataset + "/RE_LVR_POLY","KEEP_NULL")

  logger.logMessageString("Successfully ran Repair Geometry on RE_LVR_POLY")

except:

  logger.logMessageString("Could not run Repair Geometry on RE_LVR_POLY, it could be empty or corrupt")

 

 

etc.

 

Hope this helps!

 


Reply