[gdal-dev] Inquire mapped column names for conversion to shapefile
Jan Heckman
jan.heckman at gmail.com
Mon Apr 29 07:46:36 PDT 2024
That's pretty cool, you just saved me an awful lot of time!
Thanks,
Jan
On Mon, Apr 29, 2024 at 4:31 PM Even Rouault <even.rouault at spatialys.com>
wrote:
> 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 at lists.osgeo.org
> > https://lists.osgeo.org/mailman/listinfo/gdal-dev
>
> --
> http://www.spatialys.com
> My software is free, but my time generally not.
>
>
-------------- next part --------------
An HTML attachment was scrubbed...
URL: <http://lists.osgeo.org/pipermail/gdal-dev/attachments/20240429/c152ad4f/attachment-0001.htm>
More information about the gdal-dev
mailing list