Hi Chris, thanks for that! It would not have surprised me if the attribute datatype was simply not compatible with shapefile, plenty of other things are not.
What I'm seeing in QGIS is that the gui interface for exporting a layer has an option for handling a binary blob attribute type and indeed when the option is checked, the new shape file is created without a warning or error. What I'm trying to figure out, I think, is how to put that option to work via pyqgis. Is there perhaps a way to see the exact command that the export data interface is running successfully? I think ive seen the processing plugins show the command to be run, or at least all the parameters in the interface while a process is going, but the export data utility just closes and shows progress in the bottom of the main qgis window as it works. Alternatively, If there is an example somewhere of how to exclude attributes by type when exporting with pyqgis I could just exclude attributes that are causing problems for now. I've searched around for that a bit but haven't turned up an exact example of it. It's straightforward to get and check the types of a layers attributes but I haven't figured out how to pass a subset of attributes to the writeasvector function. Thanks! On Fri, Feb 3, 2023, 5:13 PM chris hermansen <clherman...@gmail.com> wrote: > Hugh and list; > > On Fri, Feb 3, 2023 at 11:41 AM Hugh Kelley via QGIS-User < > qgis-user@lists.osgeo.org> wrote: > >> to follow up as I continue to work on this, >> >> I mistakenly understood the attribute type "binary" as a Boolean, but I >> think it's in fact an arbitrary value stored as binary. That is to say, not >> necessarily True/False or 0/1 but a series of 0/1's storing a value. >> >> If I can save it to the shapefile that would be great but I'm going to >> work on filtering those attributes out of what's saved as that's an >> acceptable solution too I think. >> >> On Fri, Feb 3, 2023 at 2:24 PM Hugh Kelley <hghk...@gmail.com> wrote: >> >>> Hi, >>> >>> I'm attempting to use pyqgis to export a few things to shapefile. >>> >>> the code below is working well except that a few of the attributes are >>> incompatible with shapefiles (amazing) lack of a binary datatype. >>> >>> ```py >>> pathToFile = "C:/Users/hkelley/Downloads/test_exports/ >>> >>> layers = QgsProject.instance().mapLayers() >>> >>> for layer_id, layer in layers.items(): >>> print(layer.name()) >>> QgsVectorFileWriter.writeAsVectorFormat( layer, pathToFile+ >>> layer.name() + ".shp", "utf-8", layer.crs(), driverName="ESRI >>> Shapefile" ) >>> ``` >>> >>> I see in the manual export options that I can check a box telling the >>> export process to use "Use Binary (BLOB)". Image linked below for clarity >>> [0] >>> >>> I haven't yet figured out how to pass that option to >>> writeAsVectorFormat. >>> >>> any suggestions? >>> >>> Iv'e had a pretty thorough look through the docs for writeAsVctorFormat, >>> is the solution related to >>> QgsVectorFileWriter.BoolOption(QgsVectorFileWriter.BoolOption)? >>> >>> > Have you looked at this https://en.wikipedia.org/wiki/.dbf to understand > how attributes are stored in .dbf files? > > In particular there you will see this comment: > > *All field data is ASCII. Depending on the field's type, the application > imposes further restrictions: * > > Does this help? > -- > Chris Hermansen · clhermansen "at" gmail "dot" com > > C'est ma façon de parler. >
_______________________________________________ QGIS-User mailing list QGIS-User@lists.osgeo.org List info: https://lists.osgeo.org/mailman/listinfo/qgis-user Unsubscribe: https://lists.osgeo.org/mailman/listinfo/qgis-user