'This script will intersect an active PolyLine theme with a user-specified 'theme and produce a new third theme that shows the intersection of the 'two, with the selected fields and values of each of the original themes. 'The script works on the selected features of each of the two themes. 'It is particularly useful for line-on-line intersections, to combine 'attributes from two linear themes based on the same linework. '***********************GET FIRST LINEAR THEME************************** theView = av.GetActiveDoc theActiveThemes = theView.GetActiveThemes theFirstTheme = theActiveThemes.Get(0) theFirstFTab = theFirstTheme.GetFTab theFirstShapeField = theFirstFTab.FindField("Shape") theFirstSelection = theFirstFTab.GetSelection if (theFirstSelection.Count = 0) then theFirstSelection = theFirstFTab end theFirstFieldList = theFirstFTab.GetFields theFirstFields = List.Make for each theField in theFirstFieldList if (theField.GetAlias <> "Shape") then theFirstFields.Add(theField.GetAlias) end end theFirstChoices = MsgBox.MultiListAsString(theFirstFields, "Which fields from"++theFirstTheme.AsString++"would you like in the ouput file?","Select Fields from First Theme") if (theFirstChoices = nil) then exit end '*************************GET SECOND LINEAR THEME************************ theThemeList = theView.GetThemes theThemeListClone = theThemeList.Clone theThemeListClone.RemoveObj(theFirstTheme) theSecondTheme = MsgBox.List(theThemeListClone, "Choose a theme to intersect with"++theFirstTheme.AsString,"Input Dialog") if (theSecondTheme = Nil) then exit end theSecondFtab = theSecondTheme.GetFtab theSecondShapeField = theSecondFTab.FindField("Shape") theSecondSelection = theSecondFTab.GetSelection if (theSecondSelection.Count = 0) then theSecondSelection = theSecondFTab end theSecondFieldList = theSecondFTab.GetFields theSecondFields = List.Make for each theField in theSecondFieldList if (theField.GetAlias <> "Shape") then theSecondFields.Add(theField.GetAlias) end end theSecondChoices = MsgBox.MultiListAsString(theSecondFields, "Which fields from"++theSecondTheme.AsString++"would you like in the ouput file?","Select Fields from Second Theme") if (theSecondChoices = nil) then exit end '********************CREATE NEW INTERSECTION THEME************************ def = av.GetProject.MakeFileName("theme", "shp") def = FileDialog.Put(def, "*.shp", "Specify Output Shapefile") if (def <> nil) then tbl = FTab.MakeNew(def, polyline) if (tbl.HasError) then if (tbl.HasLockError) then MsgBox.Error("Unable to acquire Write Lock for file " + def.GetBaseName, "") else MsgBox.Error("Unable to create " + def.GetBaseName, "") end return nil end tbl.SetEditable(False) theNewTheme = FTheme.Make(tbl) theView.AddTheme(theNewTheme) theNewTheme.SetActive(True) theNewTheme.SetVisible(True) av.GetProject.SetModified(True) else exit end theNewFtab = theNewTheme.GetFtab theNewFTab.SetEditable(True) theNewShapeField = theNewFTab.FindField("Shape") '****************ADD FIELDS FROM ORIGINAL THEMES**************** theNewFieldList = List.Make theNewLengthField = Field.Make("New Length",#FIELD_DECIMAL,7,2) theNewFieldList.Add(theNewLengthField) for each theField in theFirstFieldList if (theFirstChoices.FindByValue(theField.GetAlias) <> -1) then theNewFieldList.Add(Field.Make(theField.GetAlias,theField.GetType,theField.GetWidth,theField.GetPrecision)) end end for each theField in theSecondFieldList if (theSecondChoices.FindByValue(theField.GetAlias) <> -1) then theNewFieldList.Add(Field.Make(theField.GetAlias,theField.GetType,theField.GetWidth,theField.GetPrecision)) end end theNewFtab.AddFields(theNewFieldList) '*********ADD NEW LINES TO SHAPEFILE & POPULATE ATTRIBUTES************ av.ShowMsg("Intersecting"++theFirstTheme.AsString++"with"++theSecondTheme.AsString++"...") av.UseWaitCursor av.ShowStopButton if (theFirstSelection.Is(BitMap)) then theTotalRecs = theFirstSelection.Count else theTotalRecs = theFirstSelection.GetNumRecords end theCurrentRecNumber = 0 for each theFirstRec in theFirstSelection '****LOOP THROUGH RECORDS IN FIRST THEME theCurrentRecNumber = theCurrentRecNumber + 1 theProgress = (theCurrentRecNumber/theTotalRecs) * 100 GoOn = av.SetStatus(theProgress) if (not GoOn) then break end theFirstLine = theFirstFTab.ReturnValue(theFirstShapeField, theFirstRec) for each theSecondRec in theSecondSelection '****LOOP THROUGH RECORDS IN SECOND THEME theSecondLine = theSecondFTab.ReturnValue(theSecondShapeField, theSecondRec) theNewLine = theFirstLine.LineIntersection(theSecondLine) if (theNewLine.is(Polyline) and theNewLine.IsNull.Not) then '****CHECK IF THEMES INTERSECT AS A LINE theNewRec = theNewFTab.AddRecord theNewFTab.SetValue(theNewShapeField, theNewRec, theNewLine) theNewFTab.SetValue(theNewLengthField, theNewRec, Units.Convert(theNewLine.ReturnLength,#UNITS_LINEAR_METERS,#UNITS_LINEAR_MILES )) for each theField in theFirstFieldList if (theFirstChoices.FindByValue(theField.GetAlias) <> -1) then theValue = theFirstFTab.ReturnValue(theField,theFirstRec) theNewFtab.SetValue(theNewFtab.FindField(theField.GetAlias),theNewRec,theValue) end end for each theField in theSecondFieldList if (theSecondChoices.FindByValue(theField.GetAlias) <> -1) then theValue = theSecondFTab.ReturnValue(theField,theSecondRec) theNewFtab.SetValue(theNewFtab.FindField(theField.GetAlias),theNewRec,theValue) end end end end end av.ClearMsg theNewFTab.SetEditable(False) theNewTheme.Invalidate(False)