arcgis-python-api icon indicating copy to clipboard operation
arcgis-python-api copied to clipboard

Add Field length in to_featurelayer, or any sdf.spatial.to_

Open hildermesmedeiros opened this issue 2 years ago • 2 comments

It would be greate to be possible to control string fields length using pandas dataframe and to_featurelayer or to featureCollection With methods like numpy astype('<u1000') works, but, if I'm not wrong, in pandas it will be string or str.

import pandas as pd
from arcgis.gis import GIS
from arcgis.features import FeatureLayer
from arcgis.features import GeoAccessor

WGS84_WKID = 4326
EMPTY_POINT = Geometry({'x': .0, 'y': .0, 'spatialReference': {'wkid': WGS84_WKID}})
df = pd.DataFrame({'text_col': ['short text']}, 'SHAPE':[EMPTY_POINT ])
sdf = GeoAccessor.from_df(df, geometry_column='SHAPE')
##sdf.mensagem_monitoramento = sdf.mensagem_monitoramento.astype('<U1000') <----pandas will not use it
gis = GIS('pro')

sdf.spatial.to_featurelayer(
    title='String_test',
    gis=gis ,
    tags='test',
    folder=None,
    sanitize_columns=False,
    service_name=None
)

Describe the solution you'd like A parameter to parse a list of tuples ('col_name', col_length)

hildermesmedeiros avatar Aug 09 '22 03:08 hildermesmedeiros

Just to be clear, any one can automate it with arcpy, but is not that pratical.

import arcpy
arcpy.env.workspace = 'https://url_to/FeatureServer'
#assuming one feature on service (in id 0)
layer_name = arcpy.ListFeatureClasses()[0]

arcpy.AddField_management(
    in_table=layer_name,
    field_name='temp_col',
    field_type='TEXT',
    field_precision=None,
    field_scale=None,
    field_length=1000,
    field_alias=None,
    field_is_nullable=None,
    field_is_required=None,
    field_domain=None,
)

And from there we copy data from one colum to other, dele the correct one, use addfield again to recreate it, copy data from temp_col to the new text field with correct size, and finally - delete de temp column.

hildermesmedeiros avatar Aug 09 '22 13:08 hildermesmedeiros

Interesting idea we will think about it and let you know.

achapkowski avatar Sep 29 '22 18:09 achapkowski