HOW TO
Instructions provided describe how to use Avenue to convert graphics, found in a view, to features in a shapefile.
Code:
'-- Scriptgra2shp.ave
'-- Converts all view graphics of the selected feature type into a shapefile,
'-- then adds that shapefile to the View.
theView=av.getactivedoc
theGPL=theView.getgraphics.findallbyclass(GraphicShape)
if (theGPL = nil) then msgbox.error("No graphic shapes in view","") return nil
end
theFTL={"Point", "Polyline", "Polygon"}
aShapeType=msgbox.listasstring(theFTL, "Select the type of graphics you want"+
"converted into a shapefile", "Choose a feature type")
if (aShapeType = nil) then return nil end
if (aShapetype = "point") then
theclass = point
elseif (aShapeType = "polyline") then
theclass = polyline
elseif (aShapeType = "polygon") then
theclass = polygon
end
theCLoF={}
for each g in theGPL
if ((g.getshape.is(rect)) or (g.getshape.is(circle))) then
g = graphicshape.make(g.getshape.aspolygon)
end
if (g.getshape.Is(theclass)) then
theCLoF.Add(g)
end
end
if (theCLoF.count = 0) then msgbox.error("No "+aShapeType+" graphic features in"+
"view","") return nil end
tmpfn = "c:\".asfilename.maketmp("test","shp")
theOutFileName=FileDialog.Put(tmpfn,"*.shp","Create new shapefile from simple"+
"graphics")
theFtab=Ftab.MakeNew(theOutFileName, theclass)
theIDfld=Field.Make("myID", #FIELD_LONG, 10, 0)
theShapeFld=theFtab.FindField("Shape")
theFldList={theIDfld}
theFtab.AddFields(theFldList)
for each fea in theCLoF
theRecNo=theFtab.AddRecord
theFtab.SetValue(theIDfld, theRecNo, theRecNo)
eachShape=fea.getshape
theFtab.SetValue(theShapeFld, theRecNo, eachShape)
end
theFTheme=Ftheme.Make(theFTab)
theView.AddTheme(theFTheme)
theView.Invalidate
Get help from ArcGIS experts
Download the Esri Support App