' Name: Spatial.ExtractByGraphic ' ' Topics: Spatial Analyst, grid extraction. ' ' Description: This script extracts a new grid by clipping from an ' overlaying graphic. ' ' Requires: Spatial Analyst Extension ' ' Self: ' ' Returns: ' test=Extension.Find("Spatial Analyst") if (test=NIL) then msgbox.error("You must have the spatial analyst extension loaded","ExtractbyShape") return(nil) end ' get the view and the selected graphics theView = av.GetActiveDoc theGraphics=theview.getgraphics theSelg=theGraphics.getselected if (theSelG.count=0) then msgbox.error("No Graphics Selected","ExtractbyShape") return(nil) end if (theSelG.count>1) then msgbox.error("More than one Graphic is Selected, just using one","ExtractbyShape") end agraphic=thegraphics.getselected.get(0) if (agraphic.getshape.is(point)) then msgbox.error("Shape must be a line or polygon","ExtractbyShape") return(nil) end ashp=agraphic.getshape.aspolygon ' set the projection to null since graphics are projected theprojection=Prj.MakeNull ashpext=agraphic.getbounds t = NIL for each at in theView.GetActiveThemes if (at.Is( GTHEME )) then t = at break end end if (t = NIL) then msgbox.info("A Grid Theme needs to be active in the view", "ExtractbyShape") return(NIL) end ' Set a temporary Analysis Environment g = t.GetGrid Grid.SetAnalysisExtent(#GRID_ENVTYPE_VALUE, ashpext) ' Extract the grid cells base on the selected graphic r = g.ExtractbyPolygon(ashp, theProjection, FALSE) ' rename data set aFN = av.GetProject.GetWorkDir.MakeTmp("gext", "") r.Rename(aFN) ' check if output is ok if (r.HasError) then return NIL end ' create a theme gthm = GTheme.Make(r) ' set name of theme gthm.SetName("Extract from " + t.GetName) ' add theme to the specifiedView theView.AddTheme(gthm) gthm.invalidate(true)