Skip to main content

I have a workspace in 2023.2.1 that is writing to ArcGIS Portal. 

What I am finding that in some cases the original layer that is in portal had spaces in the layer name i.e. Layer Name. When it is written to Portal either FME or Portal replaces the spaces and with underscores i.e. Layer_Name and when I try to update it, FME can’t find the layer as it is looking for the original name with the spaces.

 

The only attribute that is available is fme_feature_type or my user parameters.

 

 

Is there a way to create a parameter prior to both of these writers that replaces the spaces with underscores and is then available to the FeatureWriter layer name attribute?

Hi ​@deanhowell ,

If the point of the question was "How to replace space in an attribute value with underscore", I think StringReplacer would be a general solution.

 


Thanks ​@takashi that part I have figured out but just can't get that attribute as part of the layer name for the feature writer transformer 


Why not create a extra python scripted parameter $(_protallayernamecorrected) where spaces are replaced by underscores?

return FME_MacroValues['_protallayername'].replace(' ', '_')


Thanks ​@nielsgerrits I have never tried this but looks like a possible option. Cheers Dean


Thanks ​@nielsgerrits I have never tried this but looks like a possible option. Cheers Dean

Just be sure the scripted parameter is under the original parameter because parameters are processed in the order from top to bottom, else _protallayernamecorrected can’t find _protallayername and it will fail.


@deanhowell , you can use ParameterFetcher to assign the value of a user paremeter to a new attribute, and set the attribute to the feature type name parameter in the FeatureWriter.

 

Alternatively, you can also use the @ReplaceString function to set the required layer name to the feature type name parameter in the FeatureWriter. 

@ReplaceString($(_protalLayerName)," ",_,caseSensitive=TRUE)

 


Thanks again ​@takashi. I am using a string replacer to update the fme_feature_type and that is getting me a step closer, but because I need to use the dynamic schema (although maybe that is my issue for the update) to ArcGIS Portal, the only attribute I can use is fme_feature_type

 

It is now finding the right layer in portal but giving me a python error when trying to update

 

 


Does the fme_feature_type_name on the schema have the value with the spaces or with the underscores?


Thanks all for the suggestions and assistance. I ended up using a python caller earlier in the workbench to replace any spaces in the actual file names with underscores.

 

From

rest areas/rest areas.shp
rest areas/rest areas.dbf

To 

rest_areas/rest_areas.shp
rest_areas/rest_areas.dbf

 

The end result

  • C:/Projects/AIDP/DataToProcess/rest_areas/rest_areas.shp

  • C:/Projects/AIDP/DataToProcess/rest_areas/rest_areas.dbf

 

For those interested here is my python code:

 

import fmeobjects
import os

class renameFeature(object):
def __init__(self):
self.folder_map = {}

def input(self, feature):
original_path = os.path.normpath(feature.getAttribute('path_unix'))
directory, filename = os.path.split(original_path)

# Determine renamed directory (and store mapping)
if directory not in self.folder_map:
new_directory = directory.replace(" ", "_")

if new_directory != directory:
try:
if not os.path.exists(new_directory):
os.rename(directory, new_directory)
self.folder_maprdirectory] = new_directory
except Exception as e:
feature.setAttribute('rename_dir_error', str(e))
self.folder_maprdirectory] = directory # fallback
else:
self.folder_maprdirectory] = directory
else:
new_directory = self.folder_maprdirectory]

# Now reconstruct real file path using renamed folder
original_full_path = os.path.join(new_directory, filename)
new_filename = filename.replace(" ", "_")
new_path = os.path.join(new_directory, new_filename)

try:
if new_filename != filename:
os.rename(original_full_path, new_path)
feature.setAttribute('rename_status', 'renamed')
else:
feature.setAttribute('rename_status', 'unchanged')

feature.setAttribute('_clean_filename', new_path)
except Exception as e:
feature.setAttribute('rename_error', str(e))
feature.setAttribute('_clean_filename', original_full_path) # fallback

self.pyoutput(feature)

def close(self):
pass


 


Hi ​@deanhowell ,

Good to hear you got a solution, but I think there might be a simpler way without using Python script.

According to the original screenshot you posted, you have configured dynamic schema derived from schema feature, and set "fme_feature_type" to the Schema Definition Name parameter. I assume that you are using FeatureReader to read the source dataset and the schema feature output from the <Schema> port of FeatureReader as the schema source.

In that case, the value of attribute called "fme_feature_type_name" in the schema feature should match the schema definition name - i.e. the value of "fme_feature_type" in the data features. That is, I think, if you have modified the value of "fme_feature_type" in the data features - i.e. replaced space with underscore, you can just modify "fme_feature_type_name" in the schema feature as well as the same way, so that the dynamic schema definition could work as expected.


Thanks ​@takashi I will give that a go as well and see.


Reply