[fdo-users] RE: Conditional "IF" in Expressions

Traian Stanev traian.stanev at autodesk.com
Wed Jul 18 10:36:00 EDT 2007


Hi,

I assume that since you are talking about labeling, you are using
MapGuide and my advice below applies. Otherwise, ignore my email.

For the purposes of MapGuide theming expressions, you can simulate IF by
creating several theming rules. So in your case you would have one
theming Rule that is triggered with the condition (Lanes = 1) that draws
in red for example and another Rule that triggers when (Lanes > 1) that
draws in yellow for example.

That said, it is fairly simple to implement an IF as an expression in
MapGuide, and it is not necessary that argument types match. One problem
currently is that an FDO function cannot have a conditional as argument
(the parser can't handle it). So for example something like 

IF(Lanes>2, 7, 8) 

would not parse.

However, if you implement the IF such that if the first argument is say
>0, then it means true and otherwise false, you can do it. For example
the following 

IF (Lanes-2, 'Hello', 12345)

would be equivalent and would also parse successfully. In order to
evaluate such a thing in MapGuide, you can use the attached patch (if
you are running from source of course :). MapGuide still does implicit
type conversion, so the example I give above with the string and the
number works fine for conditional labeling, that's what I used to test
it.



Traian



-----Original Message-----
From: fdo-users-bounces at lists.osgeo.org
[mailto:fdo-users-bounces at lists.osgeo.org] On Behalf Of Maksim Sestic
Sent: Wednesday, July 18, 2007 10:18 AM
To: fdo-users at lists.osgeo.org
Subject: [fdo-users] RE: Conditional "IF" in Expressions


Hi Orest,

You're right, it returns different types depending on it's return
parameters
(true and false parts). As a rule, both parameters (therefor function's
return value, too) must be of the same type, i.e.:

if(Road.Lanes>1,"Multiple lanes","Single lane")

Here, return value is String - so both params must conform to this rule.
This sort of conditional branching is quite useful when building label
expressions, here's an example:

- Parcel feature class has two data properties - Number and SubNumber
(both
are strings)
- if there's subnumber set, then it should display "Number/SubNumber"
(notice slash sign inbetween)
- otherwise, it displays only "Number" part

if(Parcel.SubNumber="",Parcel.Number,concat(Parcel.Number,(concat("/",Pa
rcel.SubNumber))))

This happens even more often when it comes to labeling infrastructure
entities, since it's labels depend on multiple states of a network
element,
etc.

Certainly, labeling is not the only use of conditional branching of that
sort :-)

Regards,
Maksim Sestic



Orest Halustchak wrote:
> 
> Hi Maksim,
> 
> This seems doable. It's similar to a null value function that some
> providers such as rdbms providers could support: nvl(a,b) which
returns
> a if a is not null, otherwise b. In your case it's if(a,b,c) where a
is
> boolean. This would need a number of signatures for different data
types
> that it would return, e.g. int16 = if(boolean, int16, int16), but
> FdoFunctionDefinition can deal with it.
> 
> The main concern that I would have about it is implementation in an
> efficient manner, although for rdbms providers, SQL includes a CASE
> expression that could be used.
> 
> Thanks,
> Orest.
> 
> -----Original Message-----
> From: fdo-users-bounces at lists.osgeo.org
> [mailto:fdo-users-bounces at lists.osgeo.org] On Behalf Of Maksim Sestic
> Sent: Wednesday, July 18, 2007 4:52 AM
> To: fdo-users at lists.osgeo.org
> Subject: [fdo-users] Conditional "IF" in Expressions
> 
> 
> I was wondering if future versions of FDO will support conditional
> branching
> in Expressions (and Filtering) mechanism, i.e.:
> 
> if(conditional_expression,true_part,false_part)
> 
> if(Road.Lanes>1,"Multiple lanes","Single lane")
> 
> also
> 
> if(Road.Lanes>0,if(Road.Lanes>1,"Multiple lanes","Single lane"),"No
> lanes
> set")
> 
> Useful link:
> http://www.codeplex.com/dotMath Steve Heberts dotMath library 
> 
> Regards,
> Maksim Sestic
> 
> 
> -- 
> View this message in context:
>
http://www.nabble.com/Conditional-%22IF%22-in-Expressions-tf4101935s1816
> 2.html#a11664863
> Sent from the fdo-users mailing list archive at Nabble.com.
> 
> _______________________________________________
> fdo-users mailing list
> fdo-users at lists.osgeo.org
> http://lists.osgeo.org/mailman/listinfo/fdo-users
> 
> _______________________________________________
> fdo-users mailing list
> fdo-users at lists.osgeo.org
> http://lists.osgeo.org/mailman/listinfo/fdo-users
> 
> 

-- 
View this message in context:
http://www.nabble.com/Conditional-%22IF%22-in-Expressions-tf4101935s1816
2.html#a11669595
Sent from the fdo-users mailing list archive at Nabble.com.

_______________________________________________
fdo-users mailing list
fdo-users at lists.osgeo.org
http://lists.osgeo.org/mailman/listinfo/fdo-users


-------------- next part --------------
A non-text attachment was scrubbed...
Name: FilterExecIF.patch
Type: application/octet-stream
Size: 1023 bytes
Desc: FilterExecIF.patch
Url : http://lists.osgeo.org/pipermail/fdo-users/attachments/20070718/e21f6384/FilterExecIF.obj


More information about the fdo-users mailing list