theview = av.GetActiveDoc thecover = av.GetActiveDoc.getactivethemes.get(0) theftab = thecover.getftab afilename = thecover.getname.middle(0, thecover.getname.indexof(".")) thef = afilename + ".txt" NewFile = FileDialog.put(thef.asfilename,"*.txt","Save shapefile to") if (NewFile = nil) then exit end lf = LineFile.Make( Newfile, #FILE_PERM_WRITE ) lf.SetEolType(#FILE_UNIX_EOL) picklist = {} for each f in theftab.getfields if (f.istypeshape.not) then picklist.add(f) end end flist = msgbox.multilist(picklist, "Choose fields to export", "") if (flist = nil) then exit end dumptype = msgbox.choiceasstring({"Create new table", "Append to existing table"}, "Type of dump", "") if (dumptype = nil) then exit end tabname = msgbox.input("Table name to create", "", afilename.asstring).lcase if (tabname = nil) then exit end thefeat = msgbox.choiceasstring({"MULTIPOLYGON", "POLYGON", "MULTILINESTRING", "LINESTRING", "MULTIPOINT","POINT"}, "Type of dump", "") if (thefeat = nil) then exit end createstr = "create table "+ tabname+ "(geoid int4, geo_value geometry" if (dumptype = "Create new table") then for each f in picklist if (f.gettype = #FIELD_BYTE) then thetype = "bit" end if (f.gettype = #FIELD_CHAR) then thetype = "varchar" end if (f.gettype = #FIELD_DATE) then thetype = "date" end if (f.gettype = #FIELD_DECIMAL) then thetype = "float8" end if (f.gettype = #FIELD_DOUBLE) then thetype = "float8" end if (f.gettype = #FIELD_FLOAT) then thetype = "float8" end if (f.gettype = #FIELD_ISODATE) then thetype = "date" end if (f.gettype = #FIELD_ISODATETIME) then thetype = "timestamp" end if (f.gettype = #FIELD_ISOTIME) then thetype = "time" end if (f.gettype = #FIELD_LOGICAL) then thetype = "bool" end if (f.gettype = #FIELD_LONG) then thetype = "int8" end if (f.gettype = #FIELD_MONEY) then thetype = "money" end if (f.gettype = #FIELD_SHORT) then thetype = "int4" end if (f.gettype = #FIELD_VCHAR) then thetype = "varchar" end fname1 = f.getname.substitute("#","num") fname2 = fname1.substitute("-","_") createstr = createstr + ", " + fname2 + " " + thetype end createstr = createstr + ");" lf.writeelt(createstr) end lf.writeelt("COPY "+ tabname.quote +" from stdin;") av.ShowStopButton x = 0 for each rec in theftab shp = thefTab.ReturnValue(thefTab.FindField("Shape"), rec).aspolygon partlist = shp.aspolygon.aslist 'shpstr = x.setformat("dddddddd").asstring + 9.aschar + thefeat+"(((" shpstr = x.setformat("dddddddd").asstring + 9.aschar + thefeat+"((" '<--- modified for each part in partlist ii = 0 shpstr = shpstr + "(" 'for each p in part for each i in 0..(part.count - 2) '<--- modified p = part.get(i) '<--- modified shpstr = shpstr + p.getX.setformat("d.dddddd").asstring + " " + p.getY.setformat("d.dddddd").asstring +", " end p = part.get(part.count - 1) '<--- modified shpstr = shpstr + p.getX.setformat("d.dddddd").asstring + " " + p.getY.setformat("d.dddddd").asstring + ")" '<--- modified 'shpstr = shpstr + ")" '<--- modified ii = ii + 1 '<--- modified if (ii < partlist.count) then '<--- modified shpstr = shpstr + "," '<--- modified end '<--- modified end 'polystr = shpstr.left(shpstr.count - 2) + ")))" + 9.aschar polystr = shpstr.left(shpstr.count) + "))" + 9.aschar '<--- modified for each f in flist theval = theFTab.ReturnValueString (f, rec) + 9.aschar polystr = polystr + theval end finalstr = polystr.left(polystr.count-1) x = x + 1 lf.writeelt(finalstr ) progress = (x/theftab.getnumrecords) * 100 doMore = av.SetStatus( progress ) if (not doMore) then break end end lf.close