' RegPoly.ave ' Emulates (sort of) the ARC/INFO REGIONPOLY command ' Outputs a polygon theme (representing a self-intersection of the input ' theme) and a table containing attributes; a unique id field allows ' one-to-many relationship of the output theme to the output table. Note ' that, unlike REGIONPOLY, the output polygons are unsorted. theView = av.GetActiveDoc theFTab = theView.GetActiveThemes.Get(0).GetFTab if (theFTab.GetShapeClass.GetClassName <> "Polygon") then MsgBox.Error("Not polygon FTheme","RegionPoly") return nil end shpname = FileName.GetCWD.MakeTMP("Theme","shp") shpname = FileDialog.Put(shpname,"*.shp","Output Shapefile") if (shpname = nil) then return nil end tabname = shpname.ReturnDir.MakeTMP("Pat","dbf") tabname = FileDialog.Put(tabname,"*.dbf","Output Attribute List") if (tabname = nil) then return nil end idname = MsgBox.Input("Name of relate field","RegionPoly","poly_id") if (idname = nil) then return nil end if (theFTab.FindField(idname) <> nil) then MsgBox.Error("Field Exists.","RegionPoly") return nil end '**** create and define table structures PShape = FTab.MakeNew(shpname, Polygon) idf = Field.Make(idname,#FIELD_DECIMAL,11,0) PShape.AddFields({idf.Clone}) PTab = VTab.MakeNew(tabname,dbase) PTab_flist = List.Make PTab_flist.Add(idf.Clone) for each f in theFTab.GetFields if (f.IsTypeShape.Not) then PTab_flist.Add(f.Clone) end end PTab.AddFields(PTab_flist) sf = theFTab.FindField("shape") psf = PShape.FindField("shape") pif = PShape.FindField(idname) tif = PTab.FindField(idname) '**** get list of shapes to self-intersect plist = List.Make for each r in theFTab plist.Merge(theFTab.ReturnValue(sf,r).Explode) end '**** generate list of intersected shapes av.ShowMsg("Performing self-intersection...") av.ClearStatus rec = 1 numrec = plist.Count i_list = {plist.Get(0)} for each i in 1..(plist.Count - 1) p = plist.Get(i) chopp = p.Clone j_list = List.Make for each s in i_list p1 = s.ReturnIntersection(p) if (p1.IsNull.Not) then j_list.Merge(p1.Explode) p2 = s.ReturnDifference(p1) if (p2.IsNull.Not) then j_list.Merge(p2.Explode) end chopp = chopp.ReturnDifference(p1) else j_list.Add(s) end end if (chopp.IsNull.Not) then j_list.Merge(chopp.Explode) end i_list = j_list rec = rec + 1 av.SetStatus(rec / numrec * 100) end plist = nil '**** add record(s) as appropriate av.ShowMsg("Building records...") av.ClearStatus rec = 1 numrec = i_list.Count for each s1 in i_list r1 = PShape.AddRecord PShape.SetValue(psf,r1,s1) PShape.SetValue(pif,r1,rec) theFTab.SelectByShapes({s1},#VTAB_SELTYPE_NEW) for each rr in theFTab.GetSelection s2 = theFTab.ReturnValue(sf,rr) if (s2.Contains(s1).Not) then continue end r2 = PTab.AddRecord for each ff in theFTab.GetFields if (ff.IsTypeShape.Not) then val = theFTab.ReturnValue(ff,rr) f = PTab.FindField(ff.GetName) PTab.SetValue(f,r2,val) end end PTab.SetValue(tif,r2,rec) end rec = rec + 1 av.SetStatus(rec / numrec * 100) end av.ClearMsg av.ClearStatus theBitmap = theFTab.GetSelection theBitmap.ClearAll theFTab.UpdateSelection i_list = nil PShape.Flush PTab.Flush av.PurgeObjects '**** ask if add to View if (MsgBox.YesNo("Add shapefile as theme to the view?", "Convert to Shapefile",true)) then fthm = FTheme.Make(PShape) theView.AddTheme(fthm) theView.GetWin.Activate end