[mapserver-users] Join CSV to Shapefile

Mirko Siebold mirko.siebold at destatis.de
Wed Oct 1 03:32:35 EDT 2008


Hello,

I have to join a CSV-file (containing statistical data) to a shape 
(containing administrative districts) - and I have no idea at all why it 
doesn't work.

The CSV-file looks like this:
'AGS','Gebietseinheit','Einwohner'
1001000,Flensburg: Stadt,87792
1002000,Kiel: Landeshauptstadt,236902
1003000,Lübeck: Hansestadt,211541
1004000,Neumünster: Stadt,77595
...

where:
AGS: key for joining shapefile to CSV (same key 'AGS' exists in 
attribute table of shapefile)
Gebietseinheit: name of administrative unit
Einwohner: number of inhabitants

Now I want the number of inhabitants to be displayed inside the 
administrative districts of the map (e.g. inside the polygon of 
'Flensburg' appears the number 87792).

I use shp2img to test my mapfile but I always receive an error message 
that item 'Einwohner' could not be found.

My mapfile looks like this:

MAP
   NAME MyMap
   SIZE 3600 2400
   UNITS dd

   EXTENT 3089902.716067 5229413.721979 4125004.235344 6124664.247035
   PROJECTION
     'proj=longlat'
     'ellps=WGS84'
     'datum=WGS84'
     'no_defs'
     ''
   END

   # Background color for the map canvas -- change as desired
   IMAGECOLOR 255 255 255
   IMAGEQUALITY 95
   IMAGETYPE PNG
   OUTPUTFORMAT
     NAME 'PNG'
     DRIVER 'GD/PNG'
     MIMETYPE 'image/png'
     #IMAGEMODE PC256
     EXTENSION 'png'
   END
   # Legend
   LEGEND
       IMAGECOLOR 255 255 255
     STATUS ON
     KEYSIZE 18 12
     LABEL
       TYPE BITMAP
       SIZE MEDIUM
       COLOR 0 0 89
     END
   END

   LAYER
     NAME 'vg250_krs'
     TYPE POLYGON
     DATA 'vg250_krs.shp' # Shapefile with administrative districts
     STATUS DEFAULT
     TRANSPARENCY 100
     PROJECTION
     'proj=longlat'
     'ellps=WGS84'
     'datum=WGS84'
     'no_defs'
     ''
     END
   JOIN
       NAME 'testcon'
       TABLE 'BevLk3.csv' # CSV with statistical data (see above)
       FROM 'AGS'
       TO 'AGS'
	  TYPE ONE-TO-ONE
     END
	LABELITEM 'Einwohner' # Item can't be found!
# If I use another item from attribute table of vg250_krs.shp it works
# If I use an item from BevLk3.csv nothing works
# I think BevLk3.csv isn't linked correctly. But why?
     CLASS
        NAME 'vg250_krs'
        STYLE
          SYMBOL 0
          SIZE 3
          OUTLINECOLOR 0 0 0
          COLOR 144 50 207
        END
	   LABEL
	      MINFEATURESIZE 10
	   END
     END
   END
END

CSV-file, mapfile and shapefile are in the same directory.

What is wrong with my mapfile? Or is my mapfile correct but it simply 
isn't possible to join attributes from other files with shp2img?
Or does the CSV-File have to have another syntax?

As I am new to UMN mapserver I would be very grateful for your help!

Thank you,
Mirko Siebold


More information about the mapserver-users mailing list