Skip to content
This repository has been archived by the owner on Jan 12, 2024. It is now read-only.

Comparing fields fails #121

Closed
dhcole opened this issue Dec 1, 2011 · 14 comments
Closed

Comparing fields fails #121

dhcole opened this issue Dec 1, 2011 · 14 comments
Labels
Milestone

Comments

@dhcole
Copy link

dhcole commented Dec 1, 2011

Comparing two fields in a rule returns the error 'Cannot use operator ">" with value NaN'.

For example, I used this rule:

#data {
    marker-width: 5;
    [dem > rep] { marker-fill: #00f;}
}

Where dem and rep are integer values.

The full Mapnik xml is here: https://gist.github.com/58423739bc4418764062

@springmeyer
Copy link

I think this is basically a sub-issue of #92.

Mapnik supports comparison operators between attributes:

>>> from mapnik import Expression, Feature
>>> f = Feature(1)
>>> f['dem'] = 1
>>> f['rep'] = 0
>>> expr = Expression("[dem]>[rep]")
>>> expr.evaluate(f)
True

But Carto appears to simply not let an expression like this pass through. I'm not familiar with the Carto internals about why this is so. It may trace back to less.js's understanding of valid selectors. @tmcw and @kkaefer ideally could comment on the how/why of this.

@tmcw
Copy link
Contributor

tmcw commented Dec 2, 2011

This is just a minor quirk of filter validation. Should be fixable in an hour or two - I'll try to get to it today or this weekend.

@tmcw
Copy link
Contributor

tmcw commented Dec 4, 2011

Upon further inspection, this is going to get bad. We can do some silly guessing, but it's going to suck. Like,

You can do

#thing[MYFIELD > 5]

You can also do

#thing["MY FIELD" > 5]

To use a field in PostGIS or whatever with spaces.

And if you do

#thing["MY FIELD" > "MY FIELD"]

Then it compares MY FIELD with the string "MY FIELD"

Ideally this should be completely symmetric and flexible, so you can compare fields, numbers, strings, and so on.

I don't think there's a good way to implement this until we support

#thing [[MY FIELD] > "MY FIELD"]

And require that field references everywhere need brackets.

@springmeyer
Copy link

progress in master...refilter looks good.

I confirmed that #layer[[a]>[b]] { ... } works now on my end.

However, something like this should also work:

#layer[[a]>[b]*2] { ... }

or even (though less useful).

#layer[[a]>10*2] { ... }

This also breaks something like:

#layer[[name].match('^DC.*')]

@springmeyer
Copy link

more on what mapnik supports: http://mapnik.org/news/2009/12/08/future_mapnik2/

@springmeyer
Copy link

@tmcw - is it a good time to revisit this?

@tmcw
Copy link
Contributor

tmcw commented Jun 27, 2012

Yep, I'll take a look at it today.

@tmcw
Copy link
Contributor

tmcw commented Jun 27, 2012

This needs to wait on a rewrite of the filter logic. Right now this is absurdly complex and should probably be fixed at the mapnik level more, or something.

@springmeyer
Copy link

@tmcw - where is this one at now from your perspective?

@tmcw
Copy link
Contributor

tmcw commented Dec 19, 2012

Getting closer - the last push I did of the filter logic should make this doable, but there's still a strong assumption in filterset that needs to be sorted out.

@robertogyn19
Copy link

I just test the code below and everything works fine. I think this issue can be closed!
I'm using carto v0.9.6.

#style1[[billing] > [estimate]] {
   marker-fill: green;
}
#style2[[billing] < [estimate]] {
  marker-fill: red;
}
<?xml version="1.0" encoding="UTF-8" standalone="yes"?>
<Map srs="+proj=merc +a=6378137 +b=6378137 +lat_ts=0.0 +lon_0=0.0 +x_0=0.0 +y_0=0 +k=1.0 +units=m +nadgrids=@null +wktext +no_defs +over" maximum-extent="-20037508.34,-20037508.34,20037508.34,20037508.34">
    <Style name="style1" filter-mode="first">
        <Rule>
            <Filter>([billing] &gt; [estimate])</Filter>
            <MarkersSymbolizer fill="#008000"/>
        </Rule>
    </Style>
    <Style name="style2" filter-mode="first">
        <Rule>
            <Filter>([billing] &lt; [estimate])</Filter>
            <MarkersSymbolizer fill="#ff0000"/>
        </Rule>
    </Style>
</Map>

Att.

@tmcw tmcw mentioned this issue Jan 14, 2016
@nebulon42 nebulon42 added this to the 0.17 milestone Dec 11, 2016
@nebulon42
Copy link
Collaborator

nebulon42 commented Dec 24, 2016

but there's still a strong assumption in filterset that needs to be sorted out

@tmcw Could you point me towards what you mean here?

@nebulon42
Copy link
Collaborator

The examples mentioned in #121 (comment), #121 (comment) (except the last one) and #121 (comment) are (now) working.

I'm waiting with closing until I know if there is something left to do.

@nebulon42
Copy link
Collaborator

No further input, so I'm closing.

Sign up for free to subscribe to this conversation on GitHub. Already have an account? Sign in.
Labels
Projects
None yet
Development

No branches or pull requests

5 participants