|
POST
|
Since you're working in C#, try pLayer = pMap.get_Layer(i);
... View more
05-22-2012
09:12 AM
|
0
|
0
|
756
|
|
POST
|
Sure. Here's one way to do it in an edit session as an Add-in. And don't forget to mark the question as answered.
Private pEditLayers As ESRI.ArcGIS.Editor.IEditLayers = My.ArcMap.Editor
Private pEditor As ESRI.ArcGIS.Editor.IEditor = My.ArcMap.Editor
Private Sub SplitFeature(ByRef pfeature As ESRI.ArcGIS.Geodatabase.IFeature, ByRef pSplitPoints As ESRI.ArcGIS.Geometry.IPointCollection)
Dim pEnumVertex As ESRI.ArcGIS.Geometry.IEnumVertex
Dim pGeoColl As ESRI.ArcGIS.Geometry.IGeometryCollection
Dim pPolyCurve As ESRI.ArcGIS.Geometry.IPolycurve2
Dim pEnumSplitPoint As ESRI.ArcGIS.Geometry.IEnumSplitPoint
Dim pNewFeature As ESRI.ArcGIS.Geodatabase.IFeature
Try
pfeature.Shape.Project(pEditor.Map.SpatialReference)
pEnumVertex = pSplitPoints.EnumVertices
pPolyCurve = pfeature.Shape
pEnumSplitPoint = pPolyCurve.SplitAtPoints(pEnumVertex, True, True, -1)
If Not pEnumSplitPoint.SplitHappened Then Exit Sub
pGeoColl = pPolyCurve
pfeature.Shape = BuildPolyline(pGeoColl.Geometry(0))
pfeature.Store()
For i As Integer = 1 To pGeoColl.GeometryCount - 1
pNewFeature = pEditLayers.CurrentLayer.FeatureClass.CreateFeature
pNewFeature.Shape = BuildPolyline(pGeoColl.Geometry(i))
CopyAttributes(pfeature, pNewFeature)
pNewFeature.Store()
Next
Catch ex As Exception
System.Windows.Forms.MessageBox.Show(ex.ToString, "SplitLine: SplitFeatures")
End Try
End Sub
Private Function BuildPolyline(ByRef pSegColl As ESRI.ArcGIS.Geometry.ISegmentCollection) As ESRI.ArcGIS.Geometry.IPolyline
Dim pPolyline As ESRI.ArcGIS.Geometry.IGeometryCollection = New ESRI.ArcGIS.Geometry.Polyline
Dim pGeometry As ESRI.ArcGIS.Geometry.IGeometry
Try
pGeometry = pPolyline
pGeometry.SpatialReference = pEditor.Map.SpatialReference
pPolyline.AddGeometries(1, pSegColl)
Return pPolyline
Catch ex As Exception
System.Windows.Forms.MessageBox.Show(ex.ToString, "SplitLine: BuildPolyline")
Return Nothing
End Try
End Function
Private Sub CopyAttributes(ByRef pInFeature As ESRI.ArcGIS.Geodatabase.IFeature, ByRef pOutFeature As ESRI.ArcGIS.Geodatabase.IFeature)
Dim pField As ESRI.ArcGIS.Geodatabase.IField
Dim pFields As ESRI.ArcGIS.Geodatabase.IFields
Try
pFields = pInFeature.Fields
For i As Integer = 0 To pFields.FieldCount - 1
pField = pFields.Field(i)
If pField.Editable Then
If Not pField.Type = ESRI.ArcGIS.Geodatabase.esriFieldType.esriFieldTypeOID And Not pField.Type = ESRI.ArcGIS.Geodatabase.esriFieldType.esriFieldTypeGeometry Then
pOutFeature.Value(i) = pInFeature.Value(i)
End If
End If
Next
Catch ex As Exception
System.Windows.Forms.MessageBox.Show(ex.ToString, "SplitLine: CopyAttributes")
End Try
End Sub
... View more
05-17-2012
07:43 AM
|
1
|
0
|
2628
|
|
POST
|
Glad to help. Don't forget to mark the question as answered.
... View more
05-16-2012
06:07 AM
|
0
|
0
|
1272
|
|
POST
|
Here's how I split a polyline using points.
Private Sub SplitFeature(ByRef pfeature As ESRI.ArcGIS.Geodatabase.IFeature, ByRef pSplitPoints As ESRI.ArcGIS.Geometry.IPointCollection)
Dim pEnumVertex As ESRI.ArcGIS.Geometry.IEnumVertex
Dim pPolyCurve As ESRI.ArcGIS.Geometry.IPolycurve2
Dim pEnumSplitPoint As ESRI.ArcGIS.Geometry.IEnumSplitPoint
pEnumVertex = pSplitPoints.EnumVertices
pPolyCurve = pfeature.Shape
pEnumSplitPoint = pPolyCurve.SplitAtPoints(pEnumVertex, True, True, -1)
'You can check to see if the line was actually split if you need to do more things with the resultant polylines.
'If Not pEnumSplitPoint.SplitHappened Then Exit Sub
End Sub
... View more
05-15-2012
06:45 AM
|
0
|
0
|
2628
|
|
POST
|
Here's an example that ESRI support sent to me on using several inputs for the Intersect tool ESRI.ArcGIS.Geoprocessor.Geoprocessor GP = new ESRI.ArcGIS.Geoprocessor.Geoprocessor(); GP.OverwriteOutput = true; IGPUtilities2 gpUtils = new GPUtilitiesClass(); IFeatureClass inFeature1 = gpUtils.OpenFeatureClassFromString(@"E:\Test.gdb\states"); IFeatureClass inFeature2 = gpUtils.OpenFeatureClassFromString(@"E:\Test.gdb\us_rivers"); IGpValueTableObject vt = new GpValueTableObjectClass(); //vt.SetColumns(1); vt.SetColumns(2); object weight; weight = 1 as object; object obj1 = inFeature1; vt.AddRow(ref obj1); vt.SetValue(0, 1, ref weight); object obj2 = inFeature2; vt.AddRow(ref obj2); vt.SetValue(1, 1, ref weight); ESRI.ArcGIS.AnalysisTools.Intersect intersect = new ESRI.ArcGIS.AnalysisTools.Intersect(); intersect.in_features = vt; intersect.out_feature_class = "E:\testout.shp"; GP.Execute(intersect, null);
... View more
05-15-2012
06:04 AM
|
0
|
0
|
1272
|
|
POST
|
Actually, it doesn't mention Service Pack 1 for Visual Studios 2010: [TD="class: rteleft"] ArcGIS Desktop, ArcGIS Engine Runtime or ArcGIS Server is required to develop with the ArcObjects SDK. Microsoft .NET Framework 3.5 SP1 [/TD] ArcObjects SDK for the Microsoft .NET Framework Microsoft Visual Studio 2008 SP1 Visual Basic Express Microsoft Visual Studio 2008 SP1 Visual C# Express Microsoft Visual Studio 2008 SP1 (C#, VB.NET) Standard, Professional, Team Edition Microsoft Visual Studio 2010 (C#, VB.NET) Professional, Premium, Ultimate Edition
... View more
05-09-2012
04:56 AM
|
0
|
0
|
1801
|
|
POST
|
It's a little old (and not in C#), but here's an example of splitting a line with points
... View more
05-07-2012
01:49 PM
|
0
|
0
|
1180
|
|
POST
|
I have just gone through my code again using the Cut Polygon Features task. It tests the size of the newly cut polygon and if it doesn't meet the minimum size and I don't want to add it, it will delete the new feature and revert to the original polygon. This operation does not result in any additional vertices.
... View more
05-04-2012
05:41 AM
|
0
|
0
|
2553
|
|
POST
|
By the way, I was able to solve my problem with the view not refreshing after applying a renderer. In my case, I had a routine to create a new featureclass and apply a renderer, but new layer wouldn't get the renderer applied to it. I had a separate routine to just apply a renderer to a selected layer, which did work properly. So I ended up just calling that separate routine at the end of the create new featureclass routine and the renderer was applied as expected. Maybe it's a related bug.
... View more
05-03-2012
06:11 AM
|
0
|
0
|
2411
|
|
POST
|
That ID should work. In my add-in, I get a reference to the editor by using Dim theEditor As ESRI.ArcGIS.Editor.IEditor = My.ArcMap.Editor I noticed that you didn't delete createdFeature (createdFeature.Delete())
... View more
05-03-2012
06:00 AM
|
0
|
0
|
2553
|
|
POST
|
Here's an Add-in I'm working on that checks for a minimum polygon size (which is a setting found in a dictionary, theDict). In my OnCreateFeature sub, I check the minimum size. pInFeature = CType(obj, ESRI.ArcGIS.Geodatabase.IFeature) CanDelete = False pFClass = CType(pDataset, ESRI.ArcGIS.Geodatabase.IFeatureClass) If pFClass.ShapeType = ESRI.ArcGIS.Geometry.esriGeometryType.esriGeometryPolygon Then pArea = pInFeature.Shape If theDict.TryGetValue("HDX.MMU", MMUList) Then If pArea.Area < MMUList(1) Then If Windows.Forms.MessageBox.Show("The area of the polygon (" & Format(pArea.Area, "##,##0.00") & ") is less than the specified Minimum Mapping Unit." & vbNewLine & vbNewLine & "Do you want to add this polygon to your layer?", "Area Smaller than MMU", Windows.Forms.MessageBoxButtons.YesNo, Windows.Forms.MessageBoxIcon.Question) = Windows.Forms.DialogResult.No Then pInFeature.Delete() CanDelete = True Exit Sub End If End If End If End If Then in the OnStopOperation sub (one of the Editor2 events), I remove the last operation if the polygon will be deleted. I have stepped through this code and the OperationStack does have the last operation removed. Private Sub OnStopOperation() Dim LastOp As Integer Dim pOperation As ESRI.ArcGIS.SystemUI.IOperation Try LastOp = My.ArcMap.Document.OperationStack.Count - 1 If CanDelete Then If LastOp > -1 Then pOperation = My.ArcMap.Document.OperationStack.Item(LastOp) If pOperation.CanUndo Then pOperation.Undo() My.ArcMap.Document.OperationStack.Remove(LastOp) Else System.Windows.Forms.MessageBox.Show("Can't undo last operation", "", Windows.Forms.MessageBoxButtons.OK, Windows.Forms.MessageBoxIcon.Exclamation) End If End If End If Catch ex As Exception System.Windows.Forms.MessageBox.Show(ex.ToString, "EditorExtention: OnStopOperation") End Try End Sub
... View more
05-02-2012
07:27 AM
|
0
|
0
|
2553
|
|
POST
|
Glad to hear it worked and that you caught that extra "Globals." It was a remnant of the original code, which I modified for this example. I just didn't modify it well enough...
... View more
04-30-2012
07:18 AM
|
0
|
0
|
1748
|
|
POST
|
A layer file will allow you to do this. Export a layer file (right click on the layer and choose "Save as Layer File") and give this file along with your dataset to others. When they open the layer file, it will have the same symbology that you created.
... View more
04-27-2012
12:35 PM
|
0
|
0
|
1638
|
|
POST
|
Here's an example for my VB.NET addin. In my project, I have created the class Win32HWNDWrapper and I have a form FieldInfoForm.
'this is the code in my main program to open the form
Dim FieldForm As New FieldInfoForm
FieldForm.ShowDialog(New Win32HWNDWrapper(My.ArcMap.Application.hWnd))
'this is the code for the Win32HWNDWrapper class
Public Class Win32HWNDWrapper
Implements System.Windows.Forms.IWin32Window
Private _hwnd As System.IntPtr
Public ReadOnly Property Handle As System.IntPtr Implements System.Windows.Forms.IWin32Window.Handle
Get
Return _hwnd
End Get
End Property
Public Sub New(ByVal Handle As System.IntPtr)
_hwnd = Handle
End Sub
End Class
... View more
04-27-2012
11:36 AM
|
0
|
0
|
3977
|
|
POST
|
Apparently the way around the bug is to use the GeoProcessing tool CalculateField, which does have the ability to select the parser. Here's how I use the tool in one of my projects Public Sub CalculateField(ByVal InputTable As Object, ByVal FieldName As String, ByVal Expression As String, Optional ByVal ExpressionType As String = Nothing, Optional ByVal CodeBlock As String = Nothing, Optional ByVal Output As Object = Nothing) Dim Calc As New ESRI.ArcGIS.DataManagementTools.CalculateField Dim Result As ESRI.ArcGIS.Geoprocessing.IGeoProcessorResult2 Try Using releaser As New ESRI.ArcGIS.ADF.ComReleaser releaser.ManageLifetime(Calc) Calc.in_table = InputTable Calc.field = FieldName Calc.expression = Expression Calc.expression_type = ExpressionType 'VB, PYTHON, or PYTHON_9.3 Calc.code_block = CodeBlock Calc.out_table = Output Result = RunTool(Calc, Nothing) If Result Is Nothing Then System.Windows.Forms.MessageBox.Show("Could not calculate field") End If End Using Catch ex As Exception System.Windows.Forms.MessageBox.Show(ex.ToString, "Calculate Field error") End Try End Sub Friend Function RunTool(ByVal Process As ESRI.ArcGIS.Geoprocessor.IGPProcess, ByVal TC As ESRI.ArcGIS.esriSystem.ITrackCancel) As ESRI.ArcGIS.Geoprocessing.IGeoProcessorResult Dim Result As ESRI.ArcGIS.Geoprocessing.IGeoProcessorResult Try System.Windows.Forms.Cursor.Current = Windows.Forms.Cursors.WaitCursor Dim GP As New ESRI.ArcGIS.Geoprocessor.Geoprocessor Result = CType(GP.Execute(Process, Nothing), ESRI.ArcGIS.Geoprocessing.IGeoProcessorResult) If Result.Status <> ESRI.ArcGIS.esriSystem.esriJobStatus.esriJobSucceeded Then If GP.MessageCount > 0 Then For Count = 0 To Globals.GP.MessageCount - 1 Message += GP.GetMessage(Count) & vbNewLine Next System.Windows.Forms.MessageBox.Show(Message, "GP Failure") End If Return Nothing End If Return Result Catch ex As Exception System.Windows.Forms.MessageBox.Show(ex.ToString & vbNewLine & ex.StackTrace, "Run Geoprocessor") Return Nothing End Try End Function
... View more
04-27-2012
11:22 AM
|
0
|
0
|
1748
|
| Title | Kudos | Posted |
|---|---|---|
| 1 | 02-04-2025 06:39 AM | |
| 1 | 3 weeks ago | |
| 1 | 04-10-2026 12:01 PM | |
| 1 | 04-13-2026 09:11 AM | |
| 1 | 10-11-2023 06:18 AM |
| Online Status |
Offline
|
| Date Last Visited |
yesterday
|