ShapefileReader t file: "test_uk.shp";
trans = select * except GEOMETRY,
CRS.transform(GEOMETRY, "epsg:4326", "epsg:27700") geom from t;
clean = select * except geom, isValid ? 1 : 0 isValid, cleanGeom
with {
isValid = Geom.isValid(geom);
cleanGeom = isValid ? geom : geom; //Geom.buffer(geom, 0);
} from trans;
ShapefileWriter clean file: "test_uk_valid.shp";
The code is spread out a bit for clarity. It could have been done in single SELECT statement, apart from the isValid flag added for reporting purposes. Note the use of the JEQL extension with clause, which improves code clarity, and also allows a more imperative style of coding which can sometimes be preferable.
Fiona gets points for being able to define any function directly in the language, but there's a price to be paid in code complexity.
Here's the result (seen in the new JEQL Workbench Geometry Viewer):