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.
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
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
//etc
}
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?
Sorry - "CreateFeatureOfUnknownType" is no existing function, it's a placeholder in this example for the function you are using to create your feature.
Hi Frank,
I am creating feature in arcmap, not arcobjects.
Sorry to trouble you. I have followed the sample code from : http://resources.esri.com/help/9.3/arcgisengine/arcobjects/esriEditor/IEditEvents_OnCreateFeature.htm
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.
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
Any idea on how to get the layer name of the new created feature? Thanks.
I didn't checked it by myself but I think the following should work: the editor implements the interface IEditLayers which contains the property CurrentLayer. This is the layer the user selected to add the new feature:
Dim uid As UID
uid = New UIDClass()
uid.Value = "esriEditor.Editor"
Dim editor As IEditor
editor = CType(m_application.FindExtensionByCLSID(uid), IEditor)
Dim editLayers as IEditLayers
editLayers = CType(editor, IEditLayers)
Dim layer as ILayer
layer = editLayers.CurrentLayer
et voila ....
Aangemelde leden kunnen berichten plaatsen, updates volgen en meer. Nieuw hier? Registreer een gratis account.
Find useful guides, FAQs, and documents to help you navigate and make the most of Esri Community.