[mapserver-users] color attribute question
Do Wi
dowi84 at gmail.com
Mon Jun 23 12:51:36 PDT 2014
Hi, and thanks!
another user here wrote me about it - see below
and it did work, so thanks!!
as i said to him, the 'only' problem with it is that the color is fixed at
the db level and cannot be changed later if for example the user chooses a
blue gradient
Cristiano also said it can be done with functions and i will check that road
again, thanks!
On Mon, Jun 23, 2014 at 3:29 PM, Cristiano Sumariva <sumariva at gmail.com>
wrote:
> Hum, mapserver has some builtin functions available:
> http://mapserver.org/mapfile/expressions.html#functions-that-return-a-string
>
> But you using data stored at a database. I would prefer the "db" way since
> it has been created to do this stuff very fast.
> Write a "formatter" function that would change the appearance of your
> data( or raw ) to a format that fits to mapserver.color.
> With this, you do not change the data but adapt it to mapserver usage.
>
> Well, I do not known what to say about functions, this is database
> specific in this case.
> A simple function in postgis database would be something like this:
>
> CREATE OR REPLACE FUNCTION ms_colorMath( percentage double precision )
> RETURNS varchar
> LANGUAGE sql
> AS
> $$
> SELECT percentage || ' 0 0';
> $$
> ;
> COMMENT ON FUNCTION ms_colorMath( double precision ) IS
> 'Compute a mapserver color based on a percentage value
> @param percentage double precision the percentage value
> @return varchar
> @version 2014-06-23';
>
> At mapfile, you would need to change the data attribute to use a database
> subquery:
>
> data ' geom FROM ( SELECT *, ms_colorMath( <attribute> ) AS ms_attribute
> FROM <tablename> ) USING UNIQUE gid SRID=<integer>'
>
> and replace the color attribute in mapfile to <ms_attribute>.
>
> A simpler way would be put this inside a database view and just change the
> tablename in mapfile, more transparent at mapfile level.
> The function can be reused for several layers stored on postgis.
>
> Preprocessing is useful when functions calculations becomes large to
> execute.
> To this you would need to change or complement data in some way with the
> preprocessed data.
> It is similar to stuff above but with additional commands on the database
> to resolve when or how the preprocessing would be done.
>
> Hope it helps.
>
> 2014-06-23 5:01 GMT-03:00 Do Wi <dowi84 at gmail.com>:
>
> Hi, and thank you!
>> not a db guy :) but i learnt now about string concatenation and by using
>> [my calculated num] || ' 0 0' it works (even though i would prefer the data
>> to remain data and not set the look of things)
>>
>> can you please elaborate on the functions? when/how would i call it - in
>> the mapfile data somehow? preprocessing?
>>
>> again, thanks!
>>
>>
>>
>>
>> On Mon, Jun 23, 2014 at 6:24 AM, Cristiano Sumariva <sumariva at gmail.com>
>> wrote:
>>
>>> Just create an expression in SQL that returns the string in a way that
>>> maps to case one or two.
>>> You can alternatively implement a function that returns the type varchar
>>> with the math required.
>>>
>>> Never did this to colors but should work.
>>>
>>
On Mon, Jun 23, 2014 at 5:59 PM, Lime, Steve D (MNIT) <
Steve.Lime at state.mn.us> wrote:
> You can compute a color string using PostgreSQL string functions:
>
>
>
> SELECT percentage || ‘ 0 0’ AS color FROM …
>
>
>
> Steve
>
>
>
> *From:* mapserver-users-bounces at lists.osgeo.org [mailto:
> mapserver-users-bounces at lists.osgeo.org] *On Behalf Of *Do Wi
> *Sent:* Sunday, June 22, 2014 3:50 PM
> *To:* mapserver-users at lists.osgeo.org
> *Subject:* [mapserver-users] color attribute question
>
>
>
> hi!
>
>
>
> i have this scenario:
>
> i have a column in my postgis table which contains a double representing a
> percentage.
>
>
>
> i want to color my polygons in a gradient fashion based on that number.
>
>
>
> the docs states three ways to specify color:
>
> 1. three [1-255] numbers
>
> 2. hex string
>
> 3. [attribute]
>
>
>
> but the attribute must be a string by itself in the same format as options
> 1 or 2.
>
>
>
> how can i achieve something like
>
>
>
> COLOR [percentage]*255 0 0
>
> or
>
> COLOR [percentage] 0 0
>
> if percentageis already 0..255
>
>
>
> for a red gradient for example?
>
>
>
> thanks allot!
>
-------------- next part --------------
An HTML attachment was scrubbed...
URL: <http://lists.osgeo.org/pipermail/mapserver-users/attachments/20140623/957fa2e9/attachment.htm>
More information about the MapServer-users
mailing list