"""
Translated from dump.pl in mapserver distribution
Norman Vine -- nhv@cape.com
"""
from mapscript import shapefileObj, shapeObj
import os

# use simple dictionary lookup for type
shape_type = {}
shape_type[1] = 'point'
shape_type[3] = 'arc',
shape_type[5] = 'polygon',
shape_type[8] = 'multipoint'


# file_name == path to shapefile with no .ext 
def dump_shape(file_name):
    SF = shapefileObj(file_name, -1)
    if SF == None:
        return
    print SF
    print "Shapefile %s opened type= %s NumShapes= %d" % ( 
            file_name, shape_type[SF.type], SF.numshapes )

    for i in range(SF.numshapes):
        S = shapeObj(-1);
        SF.get(i, S)
        print 'Shape %d has %d part(s)' % (i+1, S.numlines)
        print 'bounds (%f,%f) (%f,%f)' % (
                S.bounds.minx, S.bounds.miny, 
                S.bounds.maxx, S.bounds.maxy )

        for j in range(S.numlines):
            part = S.get(j);
            print '\tPart %d has %d point(s)' % (
                          j+1, part.numpoints )

            for k in range(part.numpoints):
                point = part.get(k)
                print '\t%d) x: %f  y: %f' % (
                        k+1, point.x, point.y )

if __name__ == "__main__":
    files = os.listdir("./data")
    for file in files:
        name,ext = os.path.splitext(file)
        if ext == ".shp":
#            print name
            dump_shape("./data/%s"%(name))
            