[mapserver-users] new user question on shapefiles

David Turover dturover at student.santarosa.edu
Tue Jul 23 17:26:41 EDT 2002


On Tue, 23 Jul 2002, Patrick Stanistreet wrote:

> I have tried to hack the first tutorial lesson and substitute the Calif. 
> state
> shapefile without luck.  What I think I need are the basics of how
> mapserver takes a shapefile and displays it.
>  I have also tried substituting the Calif. shapefile in the Itasca demo.
> Although I see a png files being created in the tmp directory,
> I dont believe I have the right approach as looking at the files
> none appear to be the state outline.

First, you need to make sure that all of the URLs and pathnames in your
.map and .html files are correct. Check your server error log. Another
likely problem is that your extent may be wrong. If your extent says to
look at Minnesota, then your California shape is going to be offscreen
and you won't see it.

Shapefiles are the mix of three files with the same basename:
.dbf	--	A database table containing the data you make when you
		edit a shapefile's "attribute table"; basically, all
		of the extended data you create for your own purposes is
		stored here.

.shp	--	The actual shapes of your shapes (I'm guessing)

.shx	--	The geographical coordinates of your shapes (I'm guessing)

These three files are linked by row order; I've found that I can swap out
.dbf files at will without needing to change any of the other files as
long as I keep all the database rows in order. In any case, you need these
three files in your data directory. You may have other files with the same
basename, but they're not really necessary as these three are.

In your map file, you just reference the shapefile by its basename. For
instance, if your shapefile is called foobar.shp, you would then use "DATA
foobar" in your map file.

As far as I know, you need to have LAYERs in your mapfile to display
anything in Mapserver, but I could be horribly mistaken.


If everything looks right but you still can't see your shapefile, use the
shpinfo tool to make sure that the shapefile's type is 0-9 or 20-29 and
not in the 10-19 range that Mapserver can't read. If you didn't get
shpinfo with Mapserver, you can get it from Frank Warmerdam's shapelib
tools:
http://gdal.velocet.ca/projects/shapelib/

Some info about different shape types is here:
http://www.esricanada.com/english/support/faqs/arcgis/aifaq811.asp

If it turns out that you have Z data in the 10-19 range, the shapelib
library can be used to make a program to convert it to regular data.
It's far more likely that your problem is simply a bad pathname or extent,
but I hacked up a POINTZ to POINT converter when I was faced with this
issue. It will need to be modified to fit another situation:


/* shp_unz.c
** Convert a POINTZ to a POINT
*/

#include <shapefil.h>   /* shapelib */

int main(){
        SHPHandle in, out;
        SHPObject *foo;
        int i =0;

        in = SHPOpen("merged", "rb");
        out = SHPCreate("merged2", SHPT_POINT);

        if(in == NULL || out == NULL){
                SHPClose(in);
                SHPClose(out);
                puts("failed");
        }

        while((foo = SHPReadObject(in, i)) != NULL){
                if(foo->nSHPType != SHPT_POINTZ){
                        printf ("%d Not a POINTZ", i);
                } else {
                        foo->nSHPType = SHPT_POINT;
                        SHPWriteObject(out, -1, foo);
                }
                /* the docs say to destroy WriteObject returns */
                SHPDestroyObject(foo);

                i++;

        }

        SHPClose(in);
        SHPClose(out);

        return 0;
}





More information about the mapserver-users mailing list