Skip to main content
Became Hot Network Question
deleted 29 characters in body
Source Link
PolyGeo
  • 65.4k
  • 29
  • 114
  • 345

This is a follow up to https://gis.stackexchange.com/questions/322653 in which I received no response.

I am trying to convert a shapefile to a feature class, I also have a GeoJSON file with the field names as I would like them to appear in the output feature class. The arcpy.FeatureClassToFeatureClass_conversion functionality accepts a field map, so I tried to build one by looping through a GeoPandas geodataframe of the GeoJSON file (to set my output field names) and by adding the shapefile to a fieldMappings object, and replacing the field map for each iteration:

import archook
archook.get_arcpy()
import arcpy
import geopandas

file_path = 'damage_results/Culverts/Culverts.shp'
original_fields = arcpy.ListFields(file_path)
original_fields = original_fields[2:]
gdf = geopandas.read_file('damage_results/Culverts/result_culverts.json')
new_field_names = gdf.columns[:-1].to_list()

fms = arcpy.FieldMappings()
fms.addTable(file_path)

for i,field in enumerate(original_fields):
    print i
    fm = fms.getFieldMap(i)

    out_field = fm.outputField
    out_field.name = new_field_names[i]
    fm.outputField = out_field
    fms.replaceFieldMap(i, fm)

for fm in fms:
    print fm.outputField.name
arcpy.FeatureClassToFeatureClass_conversion(file_path, 'intermediate_damage.gdb',
                                            'Culverts', field_mapping = fms)

The second for loop is to verify that the output field names have been written properly, and it seems from within the script that they are. However when I open the Culverts feature class the field names are unchanged from the shapefile, which is rather infuriating.

Does the output field attribute in the FieldMap object work?

This is a follow up to https://gis.stackexchange.com/questions/322653 in which I received no response.

I am trying to convert a shapefile to a feature class, I also have a GeoJSON file with the field names as I would like them to appear in the output feature class. The arcpy.FeatureClassToFeatureClass_conversion functionality accepts a field map, so I tried to build one by looping through a GeoPandas geodataframe of the GeoJSON file (to set my output field names) and by adding the shapefile to a fieldMappings object, and replacing the field map for each iteration:

import archook
archook.get_arcpy()
import arcpy
import geopandas

file_path = 'damage_results/Culverts/Culverts.shp'
original_fields = arcpy.ListFields(file_path)
original_fields = original_fields[2:]
gdf = geopandas.read_file('damage_results/Culverts/result_culverts.json')
new_field_names = gdf.columns[:-1].to_list()

fms = arcpy.FieldMappings()
fms.addTable(file_path)

for i,field in enumerate(original_fields):
    print i
    fm = fms.getFieldMap(i)

    out_field = fm.outputField
    out_field.name = new_field_names[i]
    fm.outputField = out_field
    fms.replaceFieldMap(i, fm)

for fm in fms:
    print fm.outputField.name
arcpy.FeatureClassToFeatureClass_conversion(file_path, 'intermediate_damage.gdb',
                                            'Culverts', field_mapping = fms)

The second for loop is to verify that the output field names have been written properly, and it seems from within the script that they are. However when I open the Culverts feature class the field names are unchanged from the shapefile, which is rather infuriating.

Does the output field attribute in the FieldMap object work?

This is a follow up to https://gis.stackexchange.com/questions/322653 in which I received no response.

I am trying to convert a shapefile to a feature class, I also have a GeoJSON file with the field names as I would like them to appear in the output feature class. The arcpy.FeatureClassToFeatureClass_conversion functionality accepts a field map, so I tried to build one by looping through a GeoPandas geodataframe of the GeoJSON file (to set my output field names) and by adding the shapefile to a fieldMappings object, and replacing the field map for each iteration:

import archook
archook.get_arcpy()
import arcpy
import geopandas

file_path = 'damage_results/Culverts/Culverts.shp'
original_fields = arcpy.ListFields(file_path)
original_fields = original_fields[2:]
gdf = geopandas.read_file('damage_results/Culverts/result_culverts.json')
new_field_names = gdf.columns[:-1].to_list()

fms = arcpy.FieldMappings()
fms.addTable(file_path)

for i,field in enumerate(original_fields):
    print i
    fm = fms.getFieldMap(i)

    out_field = fm.outputField
    out_field.name = new_field_names[i]
    fm.outputField = out_field
    fms.replaceFieldMap(i, fm)

for fm in fms:
    print fm.outputField.name
arcpy.FeatureClassToFeatureClass_conversion(file_path, 'intermediate_damage.gdb',
                                            'Culverts', field_mapping = fms)

The second for loop is to verify that the output field names have been written properly, and it seems from within the script that they are. However when I open the Culverts feature class the field names are unchanged from the shapefile.

Does the output field attribute in the FieldMap object work?

added 1 character in body; edited tags; added 21 characters in body; deleted 50 characters in body; edited title
Source Link
PolyGeo
  • 65.4k
  • 29
  • 114
  • 345

What is up with Using ArcPy FieldMappings?

This is a follow up to a previous questionhttps://gis.stackexchange.com/questions/322653 in which I received no response.

I am trying to convert a shapefile to a feature class, I also have a GeoJSON file with the field names as I would like them to appear in the output feature class. The arcpy.FeatureClassToFeatureClass_conversion functionality accepts a field map, so I tried to build one by looping through a GeoPandas geodataframe of the GeoJSON file (to set my output field names) and by adding the shapefile to a fieldMappings object, and replacing the field map for each iteration:

import archook
archook.get_arcpy()
import arcpy
import geopandas

file_path = 'damage_results/Culverts/Culverts.shp'
original_fields = arcpy.ListFields(file_path)
original_fields = original_fields[2:]
gdf = geopandas.read_file('damage_results/Culverts/result_culverts.json')
new_field_names = gdf.columns[:-1].to_list()

fms = arcpy.FieldMappings()
fms.addTable(file_path)

for i,field in enumerate(original_fields):
    print i
    fm = fms.getFieldMap(i)

    out_field = fm.outputField
    out_field.name = new_field_names[i]
    fm.outputField = out_field
    fms.replaceFieldMap(i, fm)

for fm in fms:
    print fm.outputField.name
arcpy.FeatureClassToFeatureClass_conversion(file_path, 'intermediate_damage.gdb',
                                            'Culverts', field_mapping = fms)

The second for loop is to verify that the output field names have been written properly, and it seems from within the script that they are. However when I open the Culverts feature class the field names are unchanged from the shapefile, which is rather infuriating.

Does the output field attribute in the FieldMap object actually work? Or is this a bug that Esri needs to fix?

What is up with ArcPy FieldMappings?

This is a follow up to a previous question in which I received no response.

I am trying to convert a shapefile to a feature class, I also have a GeoJSON file with the field names as I would like them to appear in the output feature class. The arcpy.FeatureClassToFeatureClass_conversion functionality accepts a field map, so I tried to build one by looping through a GeoPandas geodataframe of the GeoJSON file (to set my output field names) and by adding the shapefile to a fieldMappings object, and replacing the field map for each iteration:

import archook
archook.get_arcpy()
import arcpy
import geopandas

file_path = 'damage_results/Culverts/Culverts.shp'
original_fields = arcpy.ListFields(file_path)
original_fields = original_fields[2:]
gdf = geopandas.read_file('damage_results/Culverts/result_culverts.json')
new_field_names = gdf.columns[:-1].to_list()

fms = arcpy.FieldMappings()
fms.addTable(file_path)

for i,field in enumerate(original_fields):
    print i
    fm = fms.getFieldMap(i)

    out_field = fm.outputField
    out_field.name = new_field_names[i]
    fm.outputField = out_field
    fms.replaceFieldMap(i, fm)

for fm in fms:
    print fm.outputField.name
arcpy.FeatureClassToFeatureClass_conversion(file_path, 'intermediate_damage.gdb',
                                            'Culverts', field_mapping = fms)

The second for loop is to verify that the output field names have been written properly, and it seems from within the script that they are. However when I open the Culverts feature class the field names are unchanged from the shapefile, which is rather infuriating.

Does the output field attribute in the FieldMap object actually work? Or is this a bug that Esri needs to fix?

Using ArcPy FieldMappings?

This is a follow up to https://gis.stackexchange.com/questions/322653 in which I received no response.

I am trying to convert a shapefile to a feature class, I also have a GeoJSON file with the field names as I would like them to appear in the output feature class. The arcpy.FeatureClassToFeatureClass_conversion functionality accepts a field map, so I tried to build one by looping through a GeoPandas geodataframe of the GeoJSON file (to set my output field names) and by adding the shapefile to a fieldMappings object, and replacing the field map for each iteration:

import archook
archook.get_arcpy()
import arcpy
import geopandas

file_path = 'damage_results/Culverts/Culverts.shp'
original_fields = arcpy.ListFields(file_path)
original_fields = original_fields[2:]
gdf = geopandas.read_file('damage_results/Culverts/result_culverts.json')
new_field_names = gdf.columns[:-1].to_list()

fms = arcpy.FieldMappings()
fms.addTable(file_path)

for i,field in enumerate(original_fields):
    print i
    fm = fms.getFieldMap(i)

    out_field = fm.outputField
    out_field.name = new_field_names[i]
    fm.outputField = out_field
    fms.replaceFieldMap(i, fm)

for fm in fms:
    print fm.outputField.name
arcpy.FeatureClassToFeatureClass_conversion(file_path, 'intermediate_damage.gdb',
                                            'Culverts', field_mapping = fms)

The second for loop is to verify that the output field names have been written properly, and it seems from within the script that they are. However when I open the Culverts feature class the field names are unchanged from the shapefile, which is rather infuriating.

Does the output field attribute in the FieldMap object work?

naming
Source Link
Vince
  • 20.3k
  • 16
  • 48
  • 65

what What is up with arcpy fieldmappingsArcPy FieldMappings?

This is a follow up to a [previous question][1]previous question in which I received no response.

I am trying to convert a shapefile to a feature class, I also have a geojsonGeoJSON file with the field names as I would like them to appear in the output feature class. The arcpy.FeatureClassToFeatureClass_conversion functionality accepts a field map, so I tried to build one by looping through a geopandasGeoPandas geodataframe of the geojsonGeoJSON file (to set my output field names) and by adding the shapefile to a fieldMappings object, and replacing the field map for each iteration:

import archook
archook.get_arcpy()
import arcpy
import geopandas

file_path = 'damage_results/Culverts/Culverts.shp'
original_fields = arcpy.ListFields(file_path)
original_fields = original_fields[2:]
gdf = geopandas.read_file('damage_results/Culverts/result_culverts.json')
new_field_names = gdf.columns[:-1].to_list()

fms = arcpy.FieldMappings()
fms.addTable(file_path)

for i,field in enumerate(original_fields):
    print i
    fm = fms.getFieldMap(i)

    out_field = fm.outputField
    out_field.name = new_field_names[i]
    fm.outputField = out_field
    fms.replaceFieldMap(i, fm)

for fm in fms:
    print fm.outputField.name
arcpy.FeatureClassToFeatureClass_conversion(file_path, 'intermediate_damage.gdb',
                                            'Culverts', field_mapping = fms)

The second for loop is to verify that the output field names have been written properly, and it seems from within the script that they are. However when I open the Culverts feature class the field names are unchanged from the shapefile, which is rather infuriating.

Does the output field attribute in the FieldMap object actually work? Or is this a bug that ESRIEsri needs to fix?

Thanks. [1]: https://gis.stackexchange.com/questions/322653/output-field-name-not-showing-up-in-spatial-join-result

what is up with arcpy fieldmappings?

This is a follow up to a [previous question][1] in which I received no response.

I am trying to convert a shapefile to a feature class, I also have a geojson file with the field names as I would like them to appear in the output feature class. The arcpy.FeatureClassToFeatureClass_conversion functionality accepts a field map, so I tried to build one by looping through a geopandas geodataframe of the geojson file (to set my output field names) and by adding the shapefile to a fieldMappings object, and replacing the field map for each iteration:

import archook
archook.get_arcpy()
import arcpy
import geopandas

file_path = 'damage_results/Culverts/Culverts.shp'
original_fields = arcpy.ListFields(file_path)
original_fields = original_fields[2:]
gdf = geopandas.read_file('damage_results/Culverts/result_culverts.json')
new_field_names = gdf.columns[:-1].to_list()

fms = arcpy.FieldMappings()
fms.addTable(file_path)

for i,field in enumerate(original_fields):
    print i
    fm = fms.getFieldMap(i)

    out_field = fm.outputField
    out_field.name = new_field_names[i]
    fm.outputField = out_field
    fms.replaceFieldMap(i, fm)

for fm in fms:
    print fm.outputField.name
arcpy.FeatureClassToFeatureClass_conversion(file_path, 'intermediate_damage.gdb',
                                            'Culverts', field_mapping = fms)

The second for loop is to verify that the output field names have been written properly, and it seems from within the script that they are. However when I open the Culverts feature class the field names are unchanged from the shapefile, which is rather infuriating.

Does the output field attribute in the FieldMap object actually work? Or is this a bug that ESRI needs to fix?

Thanks. [1]: https://gis.stackexchange.com/questions/322653/output-field-name-not-showing-up-in-spatial-join-result

What is up with ArcPy FieldMappings?

This is a follow up to a previous question in which I received no response.

I am trying to convert a shapefile to a feature class, I also have a GeoJSON file with the field names as I would like them to appear in the output feature class. The arcpy.FeatureClassToFeatureClass_conversion functionality accepts a field map, so I tried to build one by looping through a GeoPandas geodataframe of the GeoJSON file (to set my output field names) and by adding the shapefile to a fieldMappings object, and replacing the field map for each iteration:

import archook
archook.get_arcpy()
import arcpy
import geopandas

file_path = 'damage_results/Culverts/Culverts.shp'
original_fields = arcpy.ListFields(file_path)
original_fields = original_fields[2:]
gdf = geopandas.read_file('damage_results/Culverts/result_culverts.json')
new_field_names = gdf.columns[:-1].to_list()

fms = arcpy.FieldMappings()
fms.addTable(file_path)

for i,field in enumerate(original_fields):
    print i
    fm = fms.getFieldMap(i)

    out_field = fm.outputField
    out_field.name = new_field_names[i]
    fm.outputField = out_field
    fms.replaceFieldMap(i, fm)

for fm in fms:
    print fm.outputField.name
arcpy.FeatureClassToFeatureClass_conversion(file_path, 'intermediate_damage.gdb',
                                            'Culverts', field_mapping = fms)

The second for loop is to verify that the output field names have been written properly, and it seems from within the script that they are. However when I open the Culverts feature class the field names are unchanged from the shapefile, which is rather infuriating.

Does the output field attribute in the FieldMap object actually work? Or is this a bug that Esri needs to fix?

Source Link
user32882
  • 3.6k
  • 2
  • 32
  • 71
Loading