Creating Point Layer at the intersection of Polygon & polyline Layer

348
2
05-21-2010 01:11 AM
vijipat
New Contributor
Hi All,

I have been trying using IBasicGeoprocessor interface's Intersect method, to create point layer at the point of intersection between the 2 layers.(one is line layer & other is polygon layer)

But even after setting outputFeatureClass's shapeType property to esriGeometryPoint, type of output layer is Polygon.

Could you please help me in resolving this issue.

Thanking you in advance.

Regards,
Viji

Code I used is as below:
Option Explicit
Public Sub Intersect()
  ' Get the input layer and feature class
  Dim pMxDoc As IMxDocument
  Set pMxDoc = ThisDocument
  Dim pLayer As ILayer
  Set pLayer = pMxDoc.FocusMap.Layer(1)
  Dim pInputFeatLayer As IFeatureLayer
  Set pInputFeatLayer = pLayer
  ' Use the Itable interface from the Layer (not from the FeatureClass)
  Dim pInputTable As ITable
  Set pInputTable = pLayer
  ' Get the input feature class.
  ' The Input feature class properties, such as shape type,
  ' will be needed for the output
  Dim pInputFeatClass As IFeatureClass
  Set pInputFeatClass = pInputFeatLayer.FeatureClass
  ' Get the overlay layer
  ' Use the Itable interface from the Layer (not from the FeatureClass)
  Set pLayer = pMxDoc.FocusMap.Layer(0)
  Dim pOverlayTable As ITable
  Set pOverlayTable = pLayer
  ' Error checking
  If pInputTable Is Nothing Then
    MsgBox "Table QI failed"
    Exit Sub
  End If
  If pOverlayTable Is Nothing Then
    MsgBox "Table QI failed"
    Exit Sub
  End If
'  Dim pFLayer_Ref As IFeatureLayer
'  Set pFLayer_Ref = pMxDoc.FocusMap.Layer(2)
  ' Define the output feature class name and shape type (taken from the
  ' properties of the input feature class)
  Dim pFeatClassName As IFeatureClassName
  Set pFeatClassName = New FeatureClassName
  With pFeatClassName
    .FeatureType = esriFTSimple
    .ShapeFieldName = "Shape"
    .ShapeType = esriGeometryPoint
  End With
    pFeatClassName.ShapeType = esriGeometryPoint
    pFeatClassName.FeatureType = esriFTSimple
  ' Set output location and feature class name
  Dim pNewWSName As IWorkspaceName
  Set pNewWSName = New WorkspaceName
  pNewWSName.WorkspaceFactoryProgID = "esriDataSourcesFile.ShapeFileWorkspaceFactory.1"
  pNewWSName.PathName = "C:\temp"
  Dim pDatasetName As IDatasetName
  Set pDatasetName = pFeatClassName
  pDatasetName.Name = "Intersect_result1"
 
  Set pDatasetName.WorkspaceName = pNewWSName
  ' Set the tolerance. Passing 0.0 causes the default tolerance to be used.
  ' The default tolerance is 1/10,000 of the extent of the data frame's spatial domain
  Dim tol As Double
  tol = 0#   ' Perform the intersect
  Dim pBGP As IBasicGeoprocessor
  Set pBGP = New BasicGeoprocessor
  Dim pOutputFeatClass As IFeatureClass
 
  Set pOutputFeatClass = pBGP.Intersect(pInputTable, False, pOverlayTable, False, _
    tol, pFeatClassName)
  ' Add the output layer to the map
  Dim pOutputFeatLayer As IFeatureLayer
  Set pOutputFeatLayer = New FeatureLayer
  Set pOutputFeatLayer.FeatureClass = pOutputFeatClass
  pOutputFeatLayer.Name = pOutputFeatClass.AliasName
  pMxDoc.FocusMap.AddLayer pOutputFeatLayer
End Sub
0 Kudos
2 Replies
MelitaKennedy
Esri Notable Contributor
Hi All,

I have been trying using IBasicGeoprocessor interface's Intersect method, to create point layer at the point of intersection between the 2 layers.(one is line layer & other is polygon layer)

But even after setting outputFeatureClass's shapeType property to esriGeometryPoint, type of output layer is Polygon.

Could you please help me in resolving this issue.

Thanking you in advance.

Regards,
Viji


When I read the description of IBasicGeoprocessor's Intersect method, it says:

[INDENT]Intersect clips the features of a line or polygon layer with features of an overlay polygon layer. The output feature class will have the attributes of both input and overlay layers. [/INDENT]

It's never going to return a point feature class. As IBasicGeoprocessor says, you should use the Geoprocessing framework and tools. The Analysis toolbox has an Intersect tool that should do what you want. I haven't used it, so I don't have any sample code. There's a sample in the SDK that may help you get started:

http://resources.esri.com/help/9.3/ArcGISDesktop/dotnet/43d8cc77-5193-4ca8-9878-6027782e2bbb.htm

Melita
0 Kudos
KirkKuykendall
Occasional Contributor III
If you are able to create a topology and have both featureclasses participate, then it would not be that hard to code this.


// pseudocode
// Make a list of points common to both 
List<Point> myPoints = new List<Point>();
For each node in ITopologyGraphNodes
     parent1count = 0
     parent2count = 0
     For each parent in node.parents
         if parent.m_pfC.Alias == "MyPointFeatureclass" then
               parent1count++;
         else if parent.m_FC.Alias == "MyLineFeatureclass" then
               parent2count++;
     next parent
     if parent1Count > 0 and parent2Count > 0 then
          List.Add((IPoint)node.Geometry);
next node

// write each point in List to featureclass.
foreach point in List
    Write point to output featureclass
next point
0 Kudos