2

Using ArcGIS 10.4.1 ArcObjects with geoprocessing. I have an input feature class with 100s of polygons and also one raster. I iterate through each polygon and clip the raster and then do additional work. It has performed well up to today. It seems some our polygons are outside of the raster area.

So my code in VB.NET looks like this:

'create an IVariantArray to hold the parameter values.
Dim parameters As IVariantArray = New VarArray

'populate the variant array with parameter values.
parameters.Add(inSurfaceFullName)           'input surface
parameters.Add("")                          'rectangle to be used as the clipper
parameters.Add(outClippedRasterFullName)    'the output raster (ex Raster_3)
parameters.Add(inClippingPolyFullName)      'the input template dataset to be used as a clipper. in this case our sub feature class (NOT the input feature class)
parameters.Add("")                          'all the pixels with the specified value will be set to NoData in the output raster dataset.
parameters.Add("ClippingGeometry")          'the raster dataset is clipped based on the perimeter of the polygon shape.

'execute the model tool by name.
Dim res As IGeoProcessorResult = GP.Execute("Clip_management", parameters, Nothing)

When it gets to the polygon that does not intersect the raster I get this error:

System.Runtime.InteropServices.COMException (0x80004005): Error HRESULT E_FAIL has been returned from a call to a COM component.
   at ESRI.ArcGIS.Geoprocessing.GeoProcessorClass.Execute(String Name, IVariantArray ipValues, ITrackCancel pTrackCancel)

I have been looking in the ESRI SDK for a pre-process where I can check if the polygon intersects the raster with a True/False as the result. Is that something that exists? Or another way to check the intersection of a geometry with a raster?

The only thing I have tried is to check if the extents intersect but I can see where this may fail. For example a circle geometry just at the corner of the raster. the envelopes will intersect but the geometry and raster will not.


With help from @MichaelStimson, I ended up testing the raster envelope against the polygon geometry. Seems to work rather well. Here is the function I use to test all features in a feature class against the raster:

''' <summary>
''' this function will determine if the polygon feature class is outside of the raster boundary. it will test all features in the
''' feature class and return one result for the overall disjoint result.
''' <param name="pInSurfaceEnv">the input surface envelope</param>
''' <param name="pPolyDsName">the input polygon Dataset name object</param>
''' </summary>
''' <returns></returns>
''' <remarks></remarks>
Private Function IsFeatureClassDisjointWithRaster(pInSurfaceEnv As IEnvelope, pPolyDsName As IDatasetName) As Boolean
    Try
        Dim pRelOp As IRelationalOperator2 = CType(pInSurfaceEnv, IRelationalOperator2)
        Dim pFeatClass As IFeatureClass = OpenFileFeatClassDataset(pPolyDsName.WorkspaceName.PathName, pPolyDsName.Name)
        Dim pFeatCursor As IFeatureCursor = pFeatClass.Search(Nothing, True)

        Dim IsFeatClassDisjoint As Boolean = True 'we assume the entire feature class is disjoint
        Dim pFeature As IFeature = pFeatCursor.NextFeature
        Do While Not pFeature Is Nothing
            Dim IsFeatureDisjoint As Boolean = pRelOp.Disjoint(pFeature.ShapeCopy)

            'we only need one feature to be non disjoint to make the entire feature class non disjoint
            If Not IsFeatureDisjoint Then IsFeatClassDisjoint = False

            'next feature
            pFeature = pFeatCursor.NextFeature
        Loop

        Return IsFeatClassDisjoint
    Catch ex As Exception
        Throw
    End Try
End Function
  • 1
    I can't speak to vb.net, but you could do a raster to polygon conversion and check against that output. If that's too expensive with a million tiny polygons then convert to a boolean raster before polygonizing. – mikewatt Mar 27 at 23:22
  • That method has merit @mikewatt, if you have a spatial analyst license you can perform raster to polygon on IsNull(your_raster) then with the query filter of "GRIDCODE = 0" delete searched rows (help.arcgis.com/en/sdk/10.0/arcobjects_net/componenthelp/… FeatureClass implements ITable) to remove the null portion... this is more time consuming but ensures there is actual data in the image the polygon intersects. – Michael Stimson Mar 27 at 23:38
  • 1
    Why not just catch and handle the error? – user2856 Mar 27 at 23:47
  • Well I may have many polygons and they can be large. So wouldn't I be doing an extract twice for each polygon that is within the raster? – sinDizzy Mar 28 at 0:30
  • So test the extents are not disjoint, then do the clip and catch the exception where the envelopes intersect but the geometry and raster don't. – user2856 Mar 28 at 1:30
0

First you can start by obtaining the extent of the raster (IRasterDataset) with IGeodataset.Extent which returns an IEnvelope which can be cast as an IRelationalOperator.

For each polygon geometry (IGeometry) then test your relational operator for Disjoint which is quicker than trying to find Overlaps. If IRelationalOperator.Disjoint then the polygon does not intersect the extent of the raster so skip to the next one.

  • Thanks for the input. As per my post "The only thing I have tried is to check if the extents intersect but I can see where this may fail. For example a circle geometry just at the corner of the raster. the envelopes will intersect but the geometry and raster will not." – sinDizzy Mar 28 at 0:31
  • Do you have spatial analyst extension? Does the suggestion by mikewatt sound like a possibility? – Michael Stimson Mar 28 at 1:34
  • I misread the message. I think it will work. I will test with my data. – sinDizzy Mar 28 at 3:18

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service, privacy policy and cookie policy

Not the answer you're looking for? Browse other questions tagged or ask your own question.