Setting Extent and Mask properties for Geoprocessor not working

2797
2
02-26-2013 05:08 AM
martinmaretta
Occasional Contributor
Hi

I am using Geoprocessor in VB.NET and was trying to set the extent so my process is constraint by this extent.
When I set the property 'gp.SetEnvironmentValue("extent", "-450554.414000, -1154206.896400, -445014.414000, -1146626.896400");' and ran the GP processor, the output does not match the extent. The same is for Mask property.

I have tried it inside ArcGIS 10 by setting the environment and it works. I am not sure why setting the extent in the code for Geoprocessor is not working.
I Found two similar problems on Forum but without reply. Is this Bug in ArcObjects or what? Thanks a lot.

this is my code:

Function GP_ShpToRaster(pFeatureLayer As IFeatureLayer, pFieldNameHeight As String, pFieldNamePriority As String) As IRaster
Try

Dim pCellSize As Short = 20
Dim pOutRaster As IRaster
Dim gp As IGeoProcessor2 = New ESRI.ArcGIS.Geoprocessing.GeoProcessor()
Dim util As IGPUtilities3 = New GPUtilitiesClass()
gp.OverwriteOutput = True
gp.ResetEnvironments()
gp.SetEnvironmentValue("extent", "-450554.414000, -1154206.896400, -445014.414000, -1146626.896400")
gp.SetEnvironmentValue("cellSize", 20)
gp.SetEnvironmentValue("mask", "B:\ISSOP\pokusneData\kysuce")
gp.SetEnvironmentValue("snapRaster", "B:\ISSOP\pokusneData\kysuce")
gp.SetEnvironmentValue("workspace", "B:\")

Dim parameters As IVariantArray = New VarArray
parameters.Add(pFeatureLayer)
parameters.Add(pFieldNameHeight)
parameters.Add("Output")
parameters.Add("")
parameters.Add(pFieldNamePriority)
parameters.Add(pCellSize)
Dim result As IGeoProcessorResult2
result = CType(gp.Execute("PolylineToRaster_conversion", parameters, Nothing), IGeoProcessorResult2)
Dim gpVal As IGPValue = result.GetOutput(0)
Dim inmemfc As String = gpVal.GetAsText()
Dim pRasDataset As IRasterDataset
pRasDataset = util.OpenRasterDatasetFromString(inmemfc)
Dim pRasterLayer As IRasterLayer
pRasterLayer = New RasterLayer
pRasterLayer.CreateFromDataset(pRasDataset)
pOutRaster = pRasterLayer.Raster

Return pOutRaster
Catch ex As Exception
MsgBox(ex.Message)
Return Nothing
End Try
End Function
0 Kudos
2 Replies
DuncanHornby
MVP Notable Contributor
Hi,

I zoomed into a map and set the extent to the current display and then ran the VBA script below to see what came out

Public Sub x()
    Dim p As IGeoProcessor
    Set p = New GeoProcessor
    Dim x As String
    Let x = p.GetEnvironmentValue("extent")
    Debug.Print x
End Sub


The result is a string with numbers separated by a single SPACE character and not commas. Also the values are anti-clockwise starting with "LEFT BOTTOM RIGHT TOP". Nothing I can find in the ArcObjects API help indicates this what so ever! The only place I have found any indication in what order the limits of your extent should be is here in Python.

Duncan
0 Kudos
KenBuja
MVP Esteemed Contributor
If you ever have questions about how the parameters for a geoprocessing tool should be entered, you should run it manually in ArcMap. The Results window will show how the tool expects the parameters to be passed to it. As Duncan states, the extent doesn't have any comma delimiters.

[ATTACH=CONFIG]22263[/ATTACH]
0 Kudos