Summary
This Avenue script allows you to create a shapefile from an ArcInfo generate file.
Procedure
- Open a new script window.
A. Activate the Project window.
B. Click the Scripts icon.
C. Click New.
- Paste the following code into the script window:
Code:
'-- Script: gen2shp.ave
'-- This script takes an ASCII ungenerate file from
'-- ArcInfo and converts it to a shapefile
'-- Setup intiial objects
'-- Name and locate the input ungenerate file
genFN = FileDialog.Show("*.*", "Ungenerate Files",
"Select the Ungenerated file")
'-- Make a linefile object out of it
genLF = LineFile.Make(genFN,#FILE_PERM_READ)
'-- Ask the user what type of features are there
feaTypeList = {"Points","Lines","Polygons"}
selFeaType = MsgBox.ListAsString(feaTypeList,
"Choose which feature type is contained" +NL+
"in the selected ungenerate file:",
"Feature Type Selection")
'-- Name and locate the output shapefile
outSF = FileDialog.Put("".AsFileName,"*.shp",
"Output Shapefile Name")
'-- Make a new field to store the coverate ID
idFld = Field.Make("ID", #FIELD_LONG, 12, 0)
'-- Make a list of the views in the current project
listofViews = {}
for each aDoc in av.GetProject.GetDocs
if (aDoc.Is(View)) then
listofViews.Add(aDoc)
end
end
'-- Begin the conversion process
'-- Process points
if (selFeaType = "Points") then
'SETUP THE NEW OUTPUT FTAB
outFTab = FTab.MakeNew(outSF, Point)
outFTab.AddFields({idFld})
shpFld = outFTab.FindField("Shape")
numLines = genLF.GetSize
ctr = 2
av.ShowMsg("Converting points to shapefile...")
thisLine = genLF.ReadElt
thisLine = thisLine.Translate(","," ")
while (thisLine <> "END")
'-- Read data and setup objects for each line
av.SetStatus((ctr/numLines) * 100)
ctr = ctr + 1
recno = outFTab.AddRecord
theID = thisLine.Extract(0).AsNumber
ptX = thisLine.Extract(1).AsNumber
ptY = thisLine.Extract(2).AsNumber
pt = Point.Make(ptX, ptY)
'-- Put objects into output FTAB record
outFTab.SetValue(idFld, recno, theID)
outFTab.SetValue(shpFld, recno, pt)
thisLine = genLF.ReadElt
thisLine = thisLine.Translate(","," ")
end
outFTab.SetEditable(false)
newFTheme = FTheme.Make(outFTab)
selView = MsgBox.ListAsString(listofViews,
"Put new point shapefile into which View?",
"View Selection")
selView.AddTheme(newFTheme)
newFTheme.SetVisible(true)
selView.Invalidate
av.ClearMsg
av.ClearStatus
end
- '-- Process line
if (selFeaType = "Lines") then
'SETUP THE NEW OUTPUT FTAB
outFTab = FTab.MakeNew(outSF, Polyline)
outFTab.AddFields({idFld})
shpFld = outFTab.FindField("Shape")
numLines = genLF.GetSize
ctr = 2
av.ShowMsg("Converting lines to shapefile...")
thisLine = genLF.ReadElt
thisLine = thisLine.Translate(","," ")
while (thisLine <> "END") '-- End of File
idVal = thisLine.Extract(0).AsNumber
recno = outFTab.AddRecord
outFTab.SetValue(idFld, recno, idVal)
thisLine = genLF.ReadElt
thisLine = thisLine.Translate(","," ")
lop = {}
while (thisLine <> "END") '-- End of Line
ptX = thisLine.Extract(0).AsNumber
ptY = thisLine.Extract(1).AsNumber
pt = Point.Make(ptX, ptY)
lop.Add(pt)
thisLine = genLF.ReadElt
thisLine = thisLine.Translate(","," ")
end
pLine = Polyline.Make({lop})
outFTab.SetValue(shpFld, recno, pLine)
thisLine = genLF.ReadElt
thisLine = thisLine.Translate(","," ")
end
outFTab.SetEditable(false)
newFTheme = FTheme.Make(outFTab)
selView = MsgBox.ListAsString(listofViews,
"Put new line shapefile into which View?",
"View Selection")
selView.AddTheme(newFTheme)
newFTheme.SetVisible(true)
selView.Invalidate
av.ClearMsg
av.ClearStatus
end
'-- End processing for lines
'-- Process polygons
if (selFeaType = "Polygons") then
'-- Setup the new output FTAB
outFTab = FTab.MakeNew(outSF, Polygon)
outFTab.AddFields({idFld})
shpFld = outFTab.FindField("Shape")
numLines = genLF.GetSize
ctr = 2
av.ShowMsg("Converting polygons to shapefile...")
thisLine = genLF.ReadElt
thisLine = thisLine.Translate(","," ")
while (thisLine <> "END") '-- End of File
idVal = thisLine.Extract(0).AsNumber
recno = outFTab.AddRecord
outFTab.SetValue(idFld, recno, idVal)
thisLine = genLF.ReadElt
thisLine = thisLine.Translate(","," ")
lop = {}
lolop = {}
while (thisLine <> "END") '-- End of Line
ptX = thisLine.Extract(0).AsNumber
ptY = thisLine.Extract(1).AsNumber
pt = Point.Make(ptX, ptY)
lop.Add(pt)
thisLine = genLF.ReadElt
thisLine = thisLine.Translate(","," ")
end
lolop.Add(lop)
thisLine = genLF.ReadElt
thisLine = thisLine.Translate(","," ")
'-- Process possible donut holes
endofPolygonReached = false
while (endofPolygonReached.Not)
if (thisLine.Extract(0) = "-99999") then
endofPolygonReached = false
lop = {}
thisLine = genLF.ReadElt
thisLine = thisLine.Translate(","," ")
while (thisLine <> "END") '-- End of Line
ptX = thisLine.Extract(0).AsNumber
ptY = thisLine.Extract(1).AsNumber
pt = Point.Make(ptX, ptY)
lop.Add(pt)
thisLine = genLF.ReadElt
thisLine = thisLine.Translate(","," ")
end
lolop.Add(lop)
thisLine = genLF.ReadElt
thisLine = thisLine.Translate(","," ")
else
endofPolygonReached = true
end
end
'-- End of processeing possible donut holes
pLine = Polygon.Make(lolop)
outFTab.SetValue(shpFld, recno, pLine)
end
outFTab.SetEditable(false)
newFTheme = FTheme.Make(outFTab)
selView = MsgBox.ListAsString(listofViews,
"Put new polygon shapefile into which View?",
"View Selection")
selView.AddTheme(newFTheme)
newFTheme.SetVisible(true)
selView.Invalidate
av.ClearMsg
av.ClearStatus
end
'-- End Of Script: gen2shp.ave
- Select Compile from the Script menu or click the
![[O-Image] Script compile button](https://webapps-cdn.esri.com/CDN/support-site/technical-articles-images/000003779/00N39000003LL2C-0EM39000000wcZ8.png)
button. - Click the
![[O-Image] Run compiled script button](https://webapps-cdn.esri.com/CDN/support-site/technical-articles-images/000003779/00N39000003LL2C-0EM39000000wcZA.png)
button to run the script.