Select to view content in your preferred language

Issue with attribute types when publishing GeoJSON to ArcGIS Online

581
0
07-13-2023 06:28 AM
Labels (2)
JiříKomínek
Occasional Contributor

Hello,

I'm trying to publish a GeoJSON file containing lines and points to ArcGIS Online. The publication process is successful, resulting in a Feature Layer with two layers - point and line. Everything looks fine, except that all attributes are automatically converted to the "string" type. I've attempted to modify the attribute types using the following code, but I haven't achieved the desired outcome. The attributes still remain as "string" instead of the intended "date" type.

# Name of the layer you want to load
layer_name = "Test GeoJSON File"

# Retrieve the Feature Layer through search
layer = gis_agol.content.search(query=layer_name, item_type="Feature Layer")[0]

# Get the Feature Layer object
feature_layer = layer.layers[0]

# Retrieve information about the attribute table of the Feature Layer
attributes = feature_layer.properties['fields']

# Define new attribute types to be used
new_types = {
    "realizace_do": "esriFieldTypeDate",
    # Continue with other attributes you want to modify
}

# Update the attribute types in the attribute table of the Feature Layer
for attribute in attributes:
    attribute_name = attribute['name']
    if attribute_name in new_types:
        attribute_type = new_types[attribute_name]
        attribute['type'] = attribute_type

feature_layer.manager.update_definition({'fields': attributes})
Tags (3)
0 Kudos
0 Replies