Hi,

Something like:


from osgeo import ogr
original_field_names = [ "toolongforshapefile1", "toolongforshapefile2"]
map_to_shp = {}
tmpfilename = "/vsimem/temp.shp"
ds = ogr.GetDriverByName("ESRI Shapefile").CreateDataSource(tmpfilename)
lyr = ds.CreateLayer("temp")
lyr_defn = lyr.GetLayerDefn()
for name in original_field_names:
    lyr.CreateField(ogr.FieldDefn(name))
    shp_field_name = lyr_defn.GetFieldDefn(lyr_defn.GetFieldCount() - 1).GetNameRef()
    map_to_shp[name] = shp_field_name
ds = None
ogr.GetDriverByName("ESRI Shapefile").DeleteDataSource(tmpfilename)
print(map_to_shp)

Even

Le 29/04/2024 à 16:23, Jan Heckman via gdal-dev a écrit :
Hi everyone,
I want to make a map of original (let's say postgresql/postgis) column names to those used in a shapefile after conversion; assuming that at least some column names in postgis will be over 10 characters in length, and shortening may produce conflicts. Basically I know how this is done, appending _<n>, but I hope that there is preferably a python method available in Qgis python to get the list of column names used in the shapefile.
Any help or pointers are welcome!
Thanks,
Jan

_______________________________________________
gdal-dev mailing list
gdal-dev@lists.osgeo.org
https://lists.osgeo.org/mailman/listinfo/gdal-dev

--
http://www.spatialys.com
My software is free, but my time generally not.

_______________________________________________
gdal-dev mailing list
gdal-dev@lists.osgeo.org
https://lists.osgeo.org/mailman/listinfo/gdal-dev

Reply via email to