I am working on a script in Python to copy several Feature Classes hosted on ArcGIS Hub to a local fGDB. I am using the workflow provided by @JoshuaBixby in Using arcpy to copy a portal feature service to a fgdb feature class. This is working for most of the features but a few will have NULL values listed for their Shape_Length and Shape_Area once imported into the fGDB. Some features do not add these fields while others populate without issue. Any Idea as to how to resolve the Null values.
from arcgis.features import FeatureLayer
url_fl = r"https://the.url.com/arcgis/rest/services/structures/MapServer/0"
fgdb = r'c:\pathTo\mytest.gdb'
fc = r'thisfeature'
fl = FeatureLayer(url_fl)
fs = fl.query()
I do not own the data hosted on the Hub but have been given access to download/query the data. If I use the Feature Class to Feature Class tool in ArcGIS Pro the Shape_Length and Shape_Area fields populate, without issue.
After trying several different approaches, I found that I can run Project (Data Management) on the saved feature class and this will fix the NULL values. The output feature class has the correct Shape_Length and Shape_Area values assigned in the fGDB.
arcpy.management.Project(in_dataset, out_dataset, out_coor_system, transform_method)
It would be great is this could be resolved without having to run an additional data management function. It would also be great if you could just run the Feature Class To Feature Class (Conversion) from a python script for data hosted on ArcGIS Online and Hub.
I am going to put a ticket in for initial issue.