One shapefile, many countries, many colors?

karsten vennemann karsten at TERRAGIS.NET
Wed Jun 13 21:09:49 EDT 2007


Subject: Re: [UMN_MAPSERVER-USERS] One shapefile, many countries, many
colors?

Pascal Ehlert wrote:
> Hi all!
> 
> I used shp2pgsql to insert the definitions of many countries (the
> African continent actually ;)) into my PostGIS enabled database.
> 
> Is there still a way to distinguish between the countries now and assign
> different colors to them?
> ArcView does this in a really nice way so I think it should be possible
> with the MapServer too, isn't it?
> 
> 
> 
> Thank you
> 
> Pascal

> Yes, basically you would have to set up a column in the query to be a 
> CLASSITEM and have the column represent the color you want. Then in the 
> mapfile set up colors for each class.

> -Steve W.

As an example I am usually using something similar like this:

LAYER
	NAME "Countries"	
	GROUP "Africa"
 	TYPE POLYGON
	STATUS ON
  CONNECTIONTYPE postgis
  CONNECTION "user=me password=none dbname=africa host=localhost"
  DATA "the_geom from (select the_geom, countryname, area, gid from
africa_countries) as temp using unique gid using SRID=4326"
  # SRID 4326 is when using decimal degrees, replace with the correct SRID
for your data  
  CLASSITEM "countryname"	
 	CLASS
 		NAME "EGYPT"
 		COLOR 153 204 143
 		EXPRESSION ([countryname]=EGYPT)
 	END
 	CLASS
 		NAME "LYBIA"
 		COLOR 252 141 50
 		EXPRESSION ([countryname]=LYBIA)
 	END
 	CLASS
 		NAME "MADAGASCAR"
 		COLOR 255 190 232
 		EXPRESSION ([countryname]=MADAGASCAR)
 	END	
END

Cheers
Karsten



More information about the mapserver-users mailing list