Closed riccardoklinger closed 10 years ago
testfile is available here: https://drive.google.com/file/d/0B91v4YI-I7pCcUZxcjhsS1p5Z1E
Unfortunately it doesn't look like an easy task to do... most providers doesn't support direct editing on attribute names.One could do a search and replace on the properties section but the problem is, thta it is not really distinguishable for me in Python. Nevertheless I've always learned not to use non-UTF8 chars for attribute names. so this is more a user-awareness problem, than a plugin problem. When one save a shapefile as geojson in QGIS using "save as..." you also get the blanks and special chars in the geojson properties fields...
I think we can run the same re.sub() on attribute names when they are being written out as JS vars.
but this can lead to rewriting the attribute content as you cannot separate attribute name from attribut content just by looking in the JS.
I think I understand the problem now. My idea will work for remote WFS layers, but not for the /data/*.js ones. qgis.core.QgsVectorFileWriter.writeAsVectorFormat() has already created the whole file and written the possibly unsafe string values. I can't think of a way around this for the moment.
To clarify, it's not whether the field names are UTF-8. It's that they can't have spaces in them. Can you confirm that attribute names with spaces in cause a problem (and not just with the recent autolinker patch)?
See this:
https://hub.qgis.org/issues/10806
If QGIS don't see this as an issue, perhaps we shouldn't. We just need to add some exception handling to give a friendly error message.
[Github won't let me edit my comment]
To clarify, my comment above relates specifically to spaces in attribute names.
this friendly error message would be good but the problem still exist: following case ATM in one of my projects: user has a shapefile and does a join with a table. table has colums "ID" "Category short" and "Category long".ID is for the join itself. We now export it to geojson which works fine. But we then access the file like this in leaflet:
feature.properties.Category long
This creates an error. Now in my project the whole map was created by this "Category long". What are the options now? 1) make an obvious statement in the plugin: USE NO SPACES IN COLUMN NAMES!!! 2) copy all columns to new columns without spaces
The first one is understandable. The second one is not managable as you need to rebuild the visualisiation of the customers project with the new columns, you alter the original data and stuff like that.
I would prefer the first one!
I've added now a messagebox and the layer with the special attribute is skipped in export. The user is informed, what is the character in which layer that causes the problem and what plugin he/she/it can use to "cure" the problem.
when exporting attribute names with blanks or special chars it fails to open the webmap