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):
Martin, is ``with`` new? I don't see it in the docs. It looks familiar ... is it related to the :let modifier in Clojure's list comprehensions?
ReplyDeletehttp://clojuredocs.org/clojure_core/clojure.core/for
Martin, JEQL is looking very cool. Here is a Groovy GeoScript version.
ReplyDelete@sean:
ReplyDeleteYes, the JEQL with block is exactly analogous to the let: block in Clojure. It's an extension to standard SQL which is sorely needed IMHO. It allows factoring out and naming common subexpressions for legibility and performance.
I've added this as doc about it here:
http://tsusiatsoftware.net/jeql/spec/jeql-query.html
@Jared:
ReplyDeleteCool, I saw that. Wow, lots of SSLs to choose from!
Hmm, "SSL"... I may have to blog about what distinguishes Python and Fiona from a "mere" scripting language.
ReplyDeleteThe JEQL with block is handy, for sure. It's interesting how we're going in opposite directions here: you adding imperative features to a declarative language, me factoring functional forms out of imperative programs.
That would be interesting to read. I personally don't have a clear idea of what constitutes a "scripting language". Isn't it common to refer to Python as a scripting language? (Although I would agree that this sounds overly ghettoizing). Surely there must be prior discussion of this to refer to?
ReplyDeleteI think I can say that whatever a scripting language is, JEQL has no further aspirations than being one of them!
As for extending in opposite directions to meet in the middle, isn't this the eventual fate of all languages? There's just too much goodness on either side to completely ignore.