I created a feature layer from excel and csv data using makeFeatureLayer method and after creating the feature layer i want to add this feature layer to a newly created webmap object and then host it to AGOL
Is this possible if not suggest other way for this workFlow.
def make_feature_layer_using_csv_excel():
file_path=input("Enter the file Path: ")
file_name = os.path.splitext(os.path.basename(file_path))[0]
wm = WebMap()
feature_class_file_name=file_name+'_'+'featureClass'
feature_layer_name=file_name+'_'+'Layer'
print("fileName: ",file_name)
output_file_dir=os.path.join(os.getcwd(),"MyProject1.gdb")
output_file_path=os.path.join(output_file_dir,feature_class_file_name)
feature_layer_path=os.path.join(os.getcwd(),file_name+'.lyrx')
print("outputfilePath: ",feature_layer_path)
file_extension=os.path.splitext(file_path)[1].lower()
if file_extension == '.csv':
arcpy.conversion.TableToTable(file_path, output_file_dir, file_name)
elif file_extension in ['.xlsx', '.xls', '.xlsb']:
arcpy.conversion.ExcelToTable(file_path, output_file_dir,file_name)
else:
return "Unknown"
arcpy.management.XYTableToPoint(file_path, output_file_path,"Longitude", "Latitude")
feature_layer=arcpy.management.MakeFeatureLayer(output_file_path, out_layer='featureLayer')
arcpy.management.SaveToLayerFile('featureLayer',feature_layer_path )
featureLayer=feature_layer.getOutput(0)
print(type(featureLayer))
insertLyr = arcpy.mp.LayerFile(feature_layer_path)
this is the logic for feature layer creation
Code formatting ... the Community Version - Esri Community
would help to check for errors and provide help
Thanks for the help. done as said please provide solution
It lacks proper indentation, hence it won't work.
If it was properly indented, you don't indicate what it did, or is it untried?