Classes in a Layer obstructing each other (I don't think they should be)
Matt Pettis
matt.pettis at THOMSON.COM
Wed Oct 24 19:39:50 PDT 2007
Thanks David,
I did the "two classes with exclusive min/max" solution, and that works. It is the cleanest I've seen, like you said, with the downside of having to repeat the EXPRESSION statement, which makes me violate the "Don't repeat yourself" maxim of coding, but ya gotta do what you gotta do.
I considered doing this in separate layers, but it suffered from the same problem and, on top of that, had the extra cost of re-executing a very expensive query. Below is the solution you suggested that I am implementing now...
thanks again,
Matt
------------------------------
LAYER
NAME "Precincts"
CONNECTIONTYPE postgis
CONNECTION "user=postgres dbname=postgis password=xxxx"
DATA "the_geom from (select distinct on (county_id, prct_id) county_name , prct_name , candidate_name , party_abbr , percentage_of_votes_for_candidate_by_office , the_geom from ( select distinct on (county_id, prct_id) county_id , prct_id , office_name , max(votes_for_candidate) as votes_for_candidate from sos_stateracespct where office_name = 'US SENATOR' group by county_id , prct_id , office_name having max(votes_for_candidate) > 0 ) m inner join sos_stateracespct using (county_id, prct_id, office_name, votes_for_candidate) inner join shp_prct using (county_id, prct_id) inner join sos_coprct_f using (county_id, prct_id)) as foo using unique the_geom using SRID=-1"
STATUS on
TYPE polygon
TRANSPARENCY 0
LABELITEM "prct_name"
# Large-scale ... no boundaries
CLASS
NAME "DFL Votes"
MINSCALE 50001
EXPRESSION ("[party_abbr]" = 'DFL' AND [percentage_of_votes_for_candidate_by_office] > 0.5)
COLOR 153 204 255
END
CLASS
NAME "R Votes"
MINSCALE 50001
EXPRESSION ("[party_abbr]" = 'R' AND [percentage_of_votes_for_candidate_by_office] > 0.5)
COLOR 255 153 255
END
CLASS
NAME "No Clear Majority"
MINSCALE 50001
EXPRESSION ( !("[party_abbr]" = 'R' and [percentage_of_votes_for_candidate_by_office] > 0.5) and !("[party_abbr]" = 'DFL' and [percentage_of_votes_for_candidate_by_office] > 0.5))
COLOR 255 255 153
END
# Small-scale ... boundaries
CLASS
NAME "DFL Votes s"
MAXSCALE 50000
EXPRESSION ("[party_abbr]" = 'DFL' AND [percentage_of_votes_for_candidate_by_office] > 0.5)
COLOR 153 204 255
STYLE
OUTLINECOLOR 0 0 0
COLOR -1 -1 -1
WIDTH 1
END
LABEL
FONT "arial"
TYPE truetype
SIZE 6
COLOR 0 0 0
POSITION cc
END
END
CLASS
NAME "R Votes s"
MAXSCALE 50000
EXPRESSION ("[party_abbr]" = 'R' AND [percentage_of_votes_for_candidate_by_office] > 0.5)
COLOR 255 153 255
STYLE
OUTLINECOLOR 0 0 0
COLOR -1 -1 -1
WIDTH 1
END
LABEL
FONT "arial"
TYPE truetype
SIZE 6
COLOR 0 0 0
POSITION cc
END
END
CLASS
NAME "No Clear Majority s"
MAXSCALE 50000
EXPRESSION ( !("[party_abbr]" = 'R' and [percentage_of_votes_for_candidate_by_office] > 0.5) and !("[party_abbr]" = 'DFL' and [percentage_of_votes_for_candidate_by_office] > 0.5))
COLOR 255 255 153
STYLE
OUTLINECOLOR 0 0 0
COLOR -1 -1 -1
WIDTH 1
END
LABEL
FONT "arial"
TYPE truetype
SIZE 6
COLOR 0 0 0
POSITION cc
END
END
END
-----Original Message-----
From: UMN MapServer Users List on behalf of Fawcett, David
Sent: Wed 10/24/2007 9:06 PM
To: MAPSERVER-USERS at LISTS.UMN.EDU
Subject: Re: [UMN_MAPSERVER-USERS] Classes in a Layer obstructing each other (I don't think they should be)
Matt,
I believe that only the first class that matches the expression gets used. I think that to get the borders, you might want to create a second scale-dependent layer that does the outlines.
That would be the cleanest way to do it. I am not sure about the order of evaulation for expression and maxscale. If MapServer looks at maxscale first, you could have two classes with the same expression, but with mutually exclusive min/max scales. One could have the fill plus the outline and one could have just the fill. My guess is that the expression gets higher priority and that this second case wouldn't work. There are a lot of people who could confirm or deny this, I am just not one of them...
David.
-----Original Message-----
From: UMN MapServer Users List on behalf of Matt Pettis
Sent: Wed 10/24/2007 8:00 PM
To: MAPSERVER-USERS at LISTS.UMN.EDU
Subject: [UMN_MAPSERVER-USERS] Classes in a Layer obstructing each other (I don't think they should be)
Hi,
I'm trying to render a layer that colors polygons. Three of the classes are used to color the polygon, and they are mutually exclusive classes (i.e., only one class at a time will be applicable to a given polygon). The fourth class I have is meant to draw an outline of the polygon at a certain maxscale value, otherwise, do not display a border.
What I am getting is that the 'border' class doesn't work with the other three. If it is the first class in the layer, it totally obstructs the results of the other three (even though I am making this layer transparent and the style of the class have a color of -1 -1 -1). If it is the last class, the borders do not show up at all at any scale. Any advice or clarification on my misunderstanding of how Mapserver is operating would be appreciated. Below is the relevant layer:
-----------
LAYER
NAME "Precincts"
CONNECTIONTYPE postgis
CONNECTION "user=postgres dbname=postgis password=xxxx"
DATA "the_geom from (select distinct on (county_id, prct_id) county_name , prct_name , candidate_name , party_abbr , percentage_of_votes_for_candidate_by_office , the_geom from ( select distinct on (county_id, prct_id) county_id , prct_id , office_name , max(votes_for_candidate) as votes_for_candidate from sos_stateracespct where office_name = 'US SENATOR' group by county_id , prct_id , office_name having max(votes_for_candidate) > 0 ) m inner join sos_stateracespct using (county_id, prct_id, office_name, votes_for_candidate) inner join shp_prct using (county_id, prct_id) inner join sos_coprct_f using (county_id, prct_id)) as foo using unique the_geom using SRID=-1"
STATUS on
TYPE polygon
TRANSPARENCY 0
CLASS
NAME "Draw Prct Boundaries"
MAXSCALE 500000
STYLE
OUTLINECOLOR 0 0 0
COLOR -1 -1 -1
WIDTH 1
END
END
CLASS
NAME "DFL Votes"
EXPRESSION ("[party_abbr]" = 'DFL' AND [percentage_of_votes_for_candidate_by_office] > 0.5)
COLOR 153 204 255
END
CLASS
NAME "R Votes"
EXPRESSION ("[party_abbr]" = 'R' AND [percentage_of_votes_for_candidate_by_office] > 0.5)
COLOR 255 153 255
END
CLASS
NAME "No Clear Majority"
EXPRESSION ( !("[party_abbr]" = 'R' and [percentage_of_votes_for_candidate_by_office] > 0.5) and !("[party_abbr]" = 'DFL' and [percentage_of_votes_for_candidate_by_office] > 0.5))
COLOR 255 255 153
END
END
More information about the MapServer-users
mailing list