[mapserver-users] mapscript Perl/Python: DBF
Lowell.Filak
lfilak at medinaco.org
Tue Jul 23 07:51:11 PDT 2002
Is it possible to generate & use a unique name for the new shape/dbffile?
This should eliminate a name conflict that could be causing the crash.
Lowell F.
On Tue, 23 Jul 2002, Michael Schulz wrote:
> Hi List,
>
> i have a python-mapscript script that queries a database, queries for
> each returned value a layer (via filteritem/filter) and then retrieves
> the resulting shapeOj and puts it in a new shapefileObj. the dbf-file
> for the new shapefileObj is also generated with msDBFCreate, then twqo
> fields are created and later records are added to the dbf, finally the
> dbf file are closed.
>
> The problem is now, that this sometimes does not work and it crashes
> with a segmentation fault. It seems, this script is working when the
> dbf-files that are to be created do not exist in the specified
> directory. So i build a method that prior to creating the shape and dfb
> files looks in the directory and if present deletes the shp/shp/dbf
> file. But still the script crashes- if i do it manually it works.
>
> Can somebody give me a hint, i if have to do something special with the
> DBFInfoObj's or sth similar: That would be great.
>
> Cheers, Michael
>
> P.S.: the source code of the script:
>
> --snip
>
> newshpname = '/var/www/plz_veranst'
> newshp = shapefileObj(newshpname,MS_SHAPEFILE_POINT)
> newshpdbf = msDBFCreate(newshpname+'.dbf')
> msDBFAddField(newshpdbf,'PLZ',0,5,0)
> msDBFAddField(newshpdbf,'NAME',0,35,0)
>
> # Query existing plz-points and copy values to new plz_veranst
> plzdbf = msDBFOpen('/var/www/plz_points.dbf',"rb")
> plzmap = mapObj('/var/www/test.map')
> plzlayer = plzmap.getLayerByName('orte_gesamt')
> plzlayer.filteritem="PLZ"
> plzshp = shapefileObj('/var/www/plz_points',-1)
> count=0
> for vlist_item in vlist: # vlist is a list of integers
> plzlayer = plzmap.getLayerByName('orte_gesamt')
> plzlayer.filteritem="PLZ"
> plzlayer.setFilter("\"%d\"" % int(vlist_item))
> plzlayer.queryByAttributes(plzmap,MS_SINGLE)
> if plzlayer.resultcache.numresults == 1:
> r = plzlayer.getResult(0)
> ptshp = shapeObj(-1)
> plzshp.get(r.shapeindex, ptshp)
> name = msDBFReadStringAttribute(plzdbf,r.shapeindex,2)
> newshp.add(ptshp)
> msDBFWriteStringAttribute(newshpdbf, count, 0, vlist_item)
> msDBFWriteStringAttribute(newshpdbf, count, 1, name)
> count=count+1
> msDBFClose(plzdbf)
> msDBFClose(newshpdbf)
>
> --snip
>
> --
> -----------------------------------------------------------
> Michael Schulz in medias res
> Dipl.-Geologe Gesellschaft für
> Informationstechnologie mbH
> Sautierstr. 38, 79104 Freiburg
> 0761 55695-95 (Fax 96)
> mschulz at webgis.de www.webgis.de
>
>
More information about the MapServer-users
mailing list