Skip to main content

I have a point feature class that I'm creating 1nm buffers around using the Bufferer tool. I need to add an attribute called AreaKm2 and populate the fields with the spherical or geodesic area in km2. In ArcGIS you can do this as a field calculation using the following python script:

!

From what I understand there is no FME transformer that enables me to calculate the geodesic area of a polygon. Therefore I was hoping to be able to run the above script using the Python Caller transformer. I'm pretty basic with Python and have so far come up with this:

import fme

 

import fmeobjects

 

# 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 processFeature(feature):

 

feature.setAttribute("AreaKm2")

 

feature.CalculateAttribute("AreaKm2", "!")

and a whole lot of errors! Does anyone have any advice they could please send through to me to get this to work? The other way would be to bring the feature class back into ArcGIS and carry out the calculation there. It would be awesome though if it could be automated. Thanks

Hi @Lharrhy, 

I've found the function getArea() in the Python API Documentation.

This function is only applicable on objects of the FMEGeometry-type and returns the area. Next you can use this value in the function setAttribute(attrName, attrValue). Be carefull, this function requires both an attribute name as well as an attribute value.

import fme
import fmeobjects

def processFeature(feature):
    # Get Area
    geomFeature = feature.getGeometry()
    area = geomFeature.getArea()
    
    # Set Area to feature
    feature.setAttribute("AREA", area)

Good luck with your automation project !


Hi @Lharrhy, 

I've found the function getArea() in the Python API Documentation.

This function is only applicable on objects of the FMEGeometry-type and returns the area. Next you can use this value in the function setAttribute(attrName, attrValue). Be carefull, this function requires both an attribute name as well as an attribute value.

import fme
import fmeobjects

def processFeature(feature):
    # Get Area
    geomFeature = feature.getGeometry()
    area = geomFeature.getArea()
    
    # Set Area to feature
    feature.setAttribute("AREA", area)

Good luck with your automation project !

For info, this function does the exact same thing as the AreaCalculator transformer.

 


The AreaCalculator transformer and getArea() method only calculate the planar area.

I tried using the free GeographicLib Python module within a PythonCaller to calculate the geodesic area, using a Shape file of the countries of the world as a test dataset. This would produce results for some country polygons, but failed on others for no reason I could determine. The area reported also differed quite a bit from the area reported by the ArcGIS function on the same dataset.

You could try using the Arcpy method within a PythonCaller, but this is more complex than it appears, since the FMEObjects and Arcpy feature objects are quite different, and you would need to convert from one to the other by transferring the geometry vertex by vertex.

I am attaching the GeographicLib workspace, in case you would like to experiment with it. Some of the PythonCaller code may be a good starting point for Arcpy as well.

For more information on GeographicLib, please see http://geographiclib.sourceforge.net/html/python/index.html

 


Thank you for your replies - it's much appreciated. I'll have a look into them and I will post back any progress!


Reply