vb.net arcobjects determine new create feature geometry

2881
12
Jump to solution
09-14-2014 07:44 PM
LiYao
by
New Contributor III

Dear all,

I want to check whether I can determine the geometry type of the new created feature, is it a point, polyline or polygon?

I am using vb.net and arcmap 10.2.1, thanks.

0 Kudos
1 Solution

Accepted Solutions
FrankHellwich1
New Contributor III

Hi,

so you're looking for a way to run code each time a new feature is created in an edit-session ?  This can be done by using Editor-events (see "ArcGIS Desktop editing for developers" in the online help): the editor object that handles editing tasks in ArcMap owns an event "OnCreateFeature" where you can react on new features inserted by the user.

I hope this helps you and meets your needs. Otherwise please give some more informations about the workflow you want to support.

Frank

View solution in original post

0 Kudos
12 Replies
FrankHellwich1
New Contributor III

Hi,

you could check the GeometryType of the Shape-property of IFeature:

     IFeature feature = CreateFeatureOfUnknownType();

     //do some null-checks here

     //then

     switch(feature.Shape.GeometryType)

     {

          case ESRI.ArcGIS.Geometry.esriGeometryType.esriGeometryPolygon:

               //blah

               break;

          case ESRI.ArcGIS.Geometry.esriGeometryType.esriGeometryPolyline:

               //blahblah

               break;

          //etc

     }

0 Kudos
LiYao
by
New Contributor III

Thank you Frank for the quick reply.

I convert the code you provided to vb.net and insert into my vb.net project.

But I get an error:

'CreateFeatureOfUnknownType' is not declared. Is there any library need to import? 

0 Kudos
FrankHellwich1
New Contributor III

Sorry - "CreateFeatureOfUnknownType" is no existing function, it's a placeholder in this example for the function you are using to create your feature.

0 Kudos
LiYao
by
New Contributor III

Hi Frank,

I am creating feature in arcmap, not arcobjects.

0 Kudos
FrankHellwich1
New Contributor III

Hi,

so you're looking for a way to run code each time a new feature is created in an edit-session ?  This can be done by using Editor-events (see "ArcGIS Desktop editing for developers" in the online help): the editor object that handles editing tasks in ArcMap owns an event "OnCreateFeature" where you can react on new features inserted by the user.

I hope this helps you and meets your needs. Otherwise please give some more informations about the workflow you want to support.

Frank

0 Kudos
LiYao
by
New Contributor III

Hi Frank,

Thanks for the update. Yes I am looking for a way  to run code each time a new feature is created in an edit-session. Will follow the instruction you give me.

0 Kudos
LiYao
by
New Contributor III

Hi Frank,

Sorry to trouble you. I have followed the sample code from : http://resources.esri.com/help/9.3/arcgisengine/arcobjects/esriEditor/IEditEvents_OnCreateFeature.ht...

I can determine when the new feature is created, but I don't know how to get the geometry type, any hints? So sorry I know little about arcobjects.

0 Kudos
FrankHellwich1
New Contributor III

Hi Li,

no problem. In the event-handler OnCreateFeature you receive the parameter "obj" of type IObject. IFeature inherites from IObject - in this case the parameter obj is an IFeature so that you can cast obj to IFeature and use the code above to check the GeometryType.

I'm no vb-crack but I guess it should look like this (at least similar):

Private Sub OnCreateFeature(ByVal obj As ESRI.ArcGIS.Geodatabase.IObject)
   Dim feature as IFeature
   feature = DirectCast(obj, IFeature)
   if feature.Shape.GeometryType = ESRI.ArcGIS.Geometry.esriGeometryType.esriGeometryPolygon then
      'do something with a polygonfeature
   else etc.
   ...
 End Sub

regards

Frank

LiYao
by
New Contributor III

Thanks Frank, it works.

0 Kudos