mapscript with python
Norman Vine
nhv at cape.com
Wed Jun 28 10:26:56 EDT 2000
>Norman Vine wrote:
>
>I have attached the makefile I used to compile 3.3.009
>with Python 1.52 and Cygwin. You can probably modify
>this to work for you.
>
>I am having problems getting later versions to compile
>of course I have upgraded my compiler and Python and SWIG
>so I am not blaming MapServer :-)
Quick update
I was not having problems compiling Mapscript but runing it.
After changing my test script ( see attached ) to reflect the
current mapscript language, the Python Mapscript extension
seems to work fine :-))
On another note:
There is a pending release of a Python module that will be
very similar and as easy to use as Perl's MakeMaker module.
I will post a python mapscript module similar to the Perl
version of mapscripts Makefile.PL shortly after the official
python Distutils module's release.
Cheers
Norman
-------------- next part --------------
"""
Translated from dump.pl in mapserver distribution
Norman Vine -- nhv at 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))
More information about the mapserver-users
mailing list