logic test before ShapefileWriter

10 views
Skip to first unread message

Keith

unread,
Sep 17, 2008, 2:51:32 PM9/17/08
to JEQL Users
Hello,

What statement or construct can I use to prevent the ShapefileWriter
from creating an empty shapefile? The following example is pretty
simple - I'm separating a shapefile.

t_fed = select * from table where ownership = "Federal";
t_state = select * from table where ownership = "State";

fed_count = select count(*) from t_fed;
state_count = select count(*) from t_state;

// I don't want to create an empty shapefile
// How do I mimic an If/Then construct?

If Val(fed_count) > 0 then
ShapefileWriter t_fed file: "federal.shp";
End if

If Val(state_count) > 0 then
ShapefileWriter t_state file: "state.shp";
End if

Keith

Martin Davis

unread,
Sep 17, 2008, 6:37:00 PM9/17/08
to jeql-...@googlegroups.com
Unfortunately conditional logic like this isn't supported in JEQL at this point. 

This was originally by design, in order to keep the language simple and declaritive - but I agree that it would be very nice to have in some situations.  It's fairly easy to add - probably the best thing is just to add it, and not worry too much about theoretical purity!

A short term workaround might be to write the shapefile, and then delete it if it's empty.  This can be done using the System.exec("<cmd string>") function, in conjunction with the conditional expression.  Somthing like this:

fed_count <= 0 ? System.exec("delete federal.shp") : 1;
fed_count <= 0 ? System.exec("delete federal.dbf") : 1;
fed_count <= 0 ? System.exec("delete federal.shx") : 1;

Yes, this is a hack - but maybe at least convenient.

I'll start thinking about adding the capability for if-else logic....
Reply all
Reply to author
Forward
0 new messages