0

I'm trying to convert a csv file to an ESRI Shapefile with OGR in Python. The problem is obviously that my header entries are too long for the default field size:

Warning 6: Normalized/laundered field name: 'SEEHOEHE [m]' to 'SEEHOEHE ['

I want to loop over all header elements (the number of columns in my csv file is unknown) and create new fields in the shapefile - "on the fly", so to speak:

for i in range(0,len(header)):
    layer_out.CreateField(ogr.FieldDefn(header[i], ogr.OFTString))

works fine, but with the header entries cut off (this is problematic, because i need to address them later on). Is there a way to define the header entry size in the same step? I tried it with SetField(32), but I fear this alters only the size for the table entries. Can anyone help? Thanks in advance!

user3017048
  • 2,711
  • 3
  • 22
  • 32
  • The limitation of 10 characters is a fixed property of the format. Perhaps you can bypass it by also addressing them with this cutoff, eg `header[i][:10]` etc. – Rutger Kassies Jul 30 '14 at 12:51
  • Thank you, that's how I solved the issue finally in order not to get into trouble all the time...anyways, this limitation seems a bit strange to me. – user3017048 Jul 30 '14 at 16:10
  • The `Shapefile` format is long overdue and only still popular because it offers great interoperability. Perhaps recent alternatives like the `GeoPackage` from OGC will catch on in the near future. – Rutger Kassies Jul 31 '14 at 08:14

0 Answers0