'xyz2shp_multi.ave 'Importa uno o piu' file ascii x y z 'in uno o piu' shapefile point 'il file txt dovra' avere il seguente formato 'x y z '656435 916587 175.2337 '656935 916587 188.4299 '657435 916587 188.7727 'oppure eliminando la lettura del primo record: '656435 916587 175.2337 '656935 916587 188.4299 '657435 916587 188.7727 '...... ...... ........ ' 'Aprire una nuova vista, ed eseguire lo script ' 'R.B. Aprile 2004 '======================================================================= theView = av.getActiveDoc '**** get input file 'txt_name = FileDialog.Show("*.*", "Input ASCII File", "Import ASCII") 'if (txt_name = nil) then ' exit 'end theTitle = "Immetti il nome del file ASCII (xyz) da importare:" thePatterns = {"*.*"} theLabels = {"ASCII xyz (*.*)"} inFNList = FileDialog.ReturnFiles(thePatterns,theLabels,theTitle,0) if (inFNList = NIL) then return NIL end if (inFNList.Count < 1) then return NIL end for each inFN in inFNList Av.ShowMsg("Importazione TXT:"+inFn.AsString) txt_file = LineFile.Make(inFN, #FILE_PERM_READ) '**** create shapefile and fields out_name = inFN.clone out_name.SetExtension("shp") LShape = FTab.MakeNew(out_name, Point) fields = List.Make fields.Add(Field.Make("x",#FIELD_DECIMAL,18,6)) fields.Add(Field.Make("y",#FIELD_DECIMAL,18,6)) fields.Add(Field.Make("z",#FIELD_DECIMAL,18,6)) LShape.AddFields(fields) '**** process records id = 0 numRec = txt_file.GetSize 'leggo l'intestazione record = txt_file.ReadElt 'leggo il primo record con le coordinate record = txt_file.ReadElt while (record <> nil) rec = LShape.AddRecord ''''''token = record.astokens(9.asChar.Quote) token = record.astokens(" ") x = token.Get(0).asNumber y = token.Get(1).asNumber z = token.Get(2).asNumber thePoint = Point.Make(x,y) '**** create shape entry LShape.SetValue(LShape.FindField("shape"),rec,thePoint) LShape.SetValue(LShape.FindField("x"),rec,x) LShape.SetValue(LShape.FindField("y"),rec,y) LShape.SetValue(LShape.FindField("z"),rec,z) '**** read next record record = txt_file.ReadElt id = id +1 av.SetStatus((id/numRec)*100) av.ShowMsg("Importazione record:"++id.asString) end txt_file.close av.ClearStatus '--- aggiungo il tema alla vista newTheme = Ftheme.Make(LShape) theView.AddTheme(newTheme) newTheme.SetVisible(true) end '======================================================================= av.ShowMsg("") av.ClearStatus ' Name: View.GridMaker ' ' Title: Creates arbitrary grid(vector) shapefile ' ' Topics: Views, Geodata ' ' Description: This script is attached to a tool. When you drag a rectangle with the tool, ' you are then prompted for how many rows and columns you want in the grid. Then you are asked ' for the name of a shapefile to create, and the grid is created. One attribute is added to this ' grid shape theme, a label, that is "A1 A2 B1 B2...." as you might see on an index map. The ' labeling starts at the upper left. ' ' The grid is added to your current view as a theme called "Grid" with hollow fill pattern and thick ' (thickness 2) black lines. You are prompted as to whether you want to label the grid. If you say yes, ' it will put the labels in the grid box using the current textsymbol. ' ' Requires: ' ' Self: ' ' Returns: if (self.Is(Tool).Not) then System.Beep MsgBox.Error("This script must be run from a tool.","Error") exit end theView=av.GetActiveDoc viewUnits=theView.GetDisplay.GetUnits viewProj=theView.GetProjection theRect=theView.ReturnUserRect if (theRect=nil) then exit end llx=therect.getleft lly=therect.getBottom theWidth=therect.getwidth theHeight=therect.getheight rows=Msgbox.Input("How many rows (up/down):","hello","10") if ((rows = nil) or (rows.asNumber < 1)) then MsgBox.Error("Must use more than one row.","Aborting") exit end cols=Msgbox.Input("How many columns:","Hello","10") if ((cols =nil) or (cols.asNumber < 1)) then MsgBox.Error("Must use more than one column.","Aborting") exit end rows=rows.asnumber cols=cols.asnumber rsize=theheight/rows csize=thewidth/cols letters="ABCDEFGHIJKLMNOPQRSTUVWXYZ" newshpname=filedialog.Put("grid.shp".AsFilename,"*.shp","Grid file") if (newshpname =nil) then exit end gridftab=Ftab.MakeNew(newshpname,POLYGON) labelfield=Field.Make("Label",#FIELD_CHAR,6,0) gridftab.SetEditable(true) gridftab.Addfields({labelfield}) gridftab.SetEditable(True) shpfield=gridftab.FindField("shape") labfield=gridftab.FindField("label") countup=0 sizer=rows*cols av.setstatus(0) Av.ShowMsg("Creating grid...") for each r in 1..rows row_id=(rows-r+1).AsString for each c in 1..cols countup=countup+1 av.setstatus(countup/sizer*100) if ((c/26) > 1) then col_prefix=letters.middle((c/26).floor-1,1) else col_prefix="" end if (c.Mod(26) = 0) then col_name=letters.Middle(25,1) else col_name=letters.Middle(c.Mod(26)-1,1) end col_id=col_prefix+col_name originx=llx+((c-1)*csize) originy=lly+((r-1)*rsize) size=csize@rsize theOrigin=originx@originy rct=rect.make(theOrigin,size) if (viewunits=#UNITS_LINEAR_METERS) then rct=rct.ReturnUnprojected(viewproj) end newrec=gridftab.AddRecord gridftab.SetValue(shpfield,newrec,rct.aspolygon) gridftab.SetValue(labfield,newrec,col_id+row_id) end end gridftab.SetEditable(false) av.clearMsg mytheme=ftheme.Make(gridftab) mysym=av.GetSymbolWin.GetPalette.GetList(#PALETTE_LIST_FILL).Get(0) mysym.setolwidth(2) mytheme.GetLegend.GetSymbols.Set(0,mysym) mytheme.SetName("Grid") mytheme.SetActive(true) myTheme.SetVisible(true) theview.AddTheme(mytheme) mytheme.Invalidate(true) theview.GetDisplay.Flush yn=MsgBox.YesNo("Label the grid?","Gridmaker",true) if (yn) then for each thm in theView.GetThemes if (thm <> mytheme) then thm.SetActive(False) end end theView.LabelThemes(false) end