'-------------------------------- 'Name: shpupdtarpr.bat 'Date: 1-25-01 ' ' prompts the user for multiple shapefiles on disk ' ' inserts the following fields into the shapefile ' on disk and populates with the following information: ' (1) numeric field named 'area_m2' ' area (meters^2) of each polygon ' (2) numeric field named 'area_ha' ' area (hectares) of each polygon ' (3) numeric field named 'perim_m' ' perimeter (meters) of each polygon ' ' WARNING: assumes all shapefile units are meters ' 'Returns: 'None ' 'Called By: 'MANY ' 'Calls: 'NONE ' 'Arguments: 'None '--------------------------------- MsgBox.Report("shpupdtarpr.bat" + NL + "1. prompts the user for multiple shapefiles on disk" + NL + "2. inserts the following fields into the shapefile" + NL + " on disk and populates with the following information:" + NL + " (1) numeric field named 'area_m2':" + NL + " area (meters^2) of each polygon" + NL + " (2) numeric field named 'area_ha'" + NL + " area (hectares) of each polygon" + NL + " (3) numeric field named 'perim_m'" + NL + " perimeter (meters) of each polygon", "About Script....") '--------------------------------------------- 'retrieve FileNames of shapefiles to process '--------------------------------------------- theFileNameList = FileDialog.ReturnFiles({"*.shp"}, {"ShapeFiles(*.shp)"}, "Select Shapefiles To Update Area And Perimeter Attributes", 0) if ( theFileNameList.Count = 0 ) then return NIL end '--------------------------------- 'make SrcNames from FileNames '--------------------------------- theSrcNameList = List.Make for each fname in theFileNameList theSrcName = SrcName.Make(fname.AsString) if ( theSrcName <> NIL ) then theSrcNameList.Add(theSrcName) end end '---------------------------------------------------- 'add fields to each src name and update attributes '---------------------------------------------------- for each sn in theSrcNameList theTheme = Theme.Make(sn) if ( theTheme = NIL ) then continue end theFTab = theTheme.GetFTab if ( theFTab = NIL ) then continue end if ( theFTab.CanEdit = FALSE ) then MsgBox.Warning("Cannot edit the attributes of theme: " + theTheme.GetName, "Warning") continue end theFTab.SetEditable(TRUE) the_area_m2_Field = Field.Make("area_m2", #FIELD_DOUBLE, 16, 2) the_area_ha_Field = Field.Make("area_ha", #FIELD_DOUBLE, 16, 2) the_perim_m_Field = Field.Make("perim_m", #FIELD_DOUBLE, 16, 2) theFTab.AddFields({the_area_m2_Field, the_area_ha_Field, the_perim_m_Field}) theFTab.Calculate("[Shape].ReturnArea", the_area_m2_Field) theFTab.Flush theFTab.Calculate("[area_m2] * 0.0001 ", the_area_ha_Field) theFTab.Flush theFTab.Calculate("[Shape].ReturnLength", the_perim_m_Field) theFTab.Flush theFTab.SetEditable(FALSE) end av.PurgeObjects return NIL