|
POST
|
Andrew, You do this by creating User Interfaces that capture and manipulate information from the user. How this occurs depends upon which path the developer intends to take things. Here's a good resource to start reading that reviews these various options -- building Add-ins or installable components, it really depends upon specific requirements only you can determine: http://help.arcgis.com/en/sdk/10.0/arcobjects_net/conceptualhelp/index.html
... View more
01-04-2012
08:21 AM
|
0
|
0
|
483
|
|
POST
|
Add Try Catch blocks to each of your methods/functions and ditch the "On Error GoTo EH" (VB6.0 stuff I think). This will kill the crashes you get and display an actual error message when something does go wrong. I didn't fully check into the depth of your code, but if I were to guess I'd say the Editing stuff if probably cause of your issues. Just not real sure though. Edit: also, I don't think this actually removes the reference/kills the form like you may think:
'Kill form
Me.Close()
Shouldn't your form have a dispose method?
... View more
12-15-2011
08:51 AM
|
0
|
0
|
1085
|
|
POST
|
Hello James, Thank you for your input. I saw your response over on the page with your download, and figured out what to do... Works great now... One would figure that ESRI would have something along these lines, but I couldn't find it... Thanks again, Kevin Orcutt Hey, that's great to hear! The majority of my projects/implementations nowadays is about spatial and non-spatial database integration, so that means lots and lots of ADO.NET and Transact-SQL. Also, and this is just from my own experience, building GIS solutions with an n-Tier architecture/approach has been very beneficial and I'd recommend looking into it. Basically, I just veiw/treat ArcGIS as any other UI (but one that comes with very powerful spatial data processing) -- thus having the n-Tier architecture allows me to integrate other layers and databases. Spend some time over at MSDN and look into some of the patterns & practices approaches to software design. This article is a bit dated but the basic ideas still apply: http://msdn.microsoft.com/en-us/library/ms973279.aspx
... View more
12-12-2011
04:10 AM
|
0
|
0
|
1536
|
|
POST
|
Kevin, I just realized that you commented on the download page of the CodeGallery where I make the vbproj and class available. To answer your question, after you download it: 1. Extract the files. 2. Disregard the vbproj file. After the new Code Gallery switch, this seems to have gotten corrupted. 3. Not a big deal, in your current assembly/vb project's Solution Explorer window, right click the project and choose "Add", then "Existing Item". 4. Navigate to where you extracted the downloaded files and select the DatTabConverter class file. This will add the code to your project. You can simply reference the class to access the ConvertToADONETDataTableFromLayer function, or just copy and paste into your own classes. Good luck and let me know if you need more assistance. Thanks for downloading!
... View more
12-09-2011
09:51 AM
|
0
|
0
|
1536
|
|
POST
|
Sure. Have a look/download one of my uploads to the Code Gallery: http://resources.arcgis.com/gallery/file/arcobjects-net-api/details?entryID=675318D8-1422-2418-8814-772B0A56383D Let me know if you need additional help! Here's the relevent code from the sample. Returns an ADO.NET DataTable: Public Function ConvertToADONETDataTableFromLayer(ByVal inLayer As IFeatureLayer) As DataTable
Try
Dim tmpDT As New DataTable("tmpDT")
Dim column As DataColumn
Dim pTable As ITable = inLayer.FeatureClass
Dim pFields As IFields = pTable.Fields
Dim pCur As ICursor = pTable.Search(Nothing, False)
For c = 0 To pCur.Fields.FieldCount - 1
column = New DataColumn()
column.ColumnName = (pFields.Field(c).Name)
If pFields.Field(c).Type = esriFieldType.esriFieldTypeString Then
column.DataType = System.Type.GetType("System.String")
ElseIf pFields.Field(c).Type = esriFieldType.esriFieldTypeInteger Then
column.DataType = System.Type.GetType("System.Int32")
ElseIf pFields.Field(c).Type = esriFieldType.esriFieldTypeDouble Then
column.DataType = System.Type.GetType("System.Double")
ElseIf pFields.Field(c).Type = esriFieldType.esriFieldTypeDate Then
column.DataType = System.Type.GetType("System.DateTime")
ElseIf pFields.Field(c).Type = esriFieldType.esriFieldTypeSingle Then
column.DataType = System.Type.GetType("System.Single")
ElseIf pFields.Field(c).Type = esriFieldType.esriFieldTypeBlob Then
column.DataType = System.Type.GetType("System.Byte")
End If
column.ReadOnly = False
tmpDT.Columns.Add(column)
Next
Dim pRow As IRow = pCur.NextRow
Dim newRow As DataRow
Do Until pRow Is Nothing
newRow = tmpDT.NewRow()
newRow.BeginEdit()
For cols = 0 To pCur.Fields.FieldCount - 1
newRow(cols) = pRow.Value(pRow.Fields.FindField(pFields.Field(cols).Name))
Next
newRow.EndEdit()
tmpDT.Rows.Add(newRow)
tmpDT.AcceptChanges()
pRow = pCur.NextRow
Loop
Return tmpDT
Catch ex As Exception
MsgBox(ex.ToString)
Return Nothing
End Try
End Function James
... View more
12-08-2011
11:43 AM
|
0
|
0
|
1536
|
|
POST
|
Agree with Neil --- if you are going to use and manipulate the Layout View for map production, then it is going to be difficult to non implement some ArcObjects. One idea is to implement a new customized CrystalReport as a replacement to the actual Layout View, just use the data for filling the informational portions (your textboxes) and add a the map view as a .jpg (you'd have to automate the export map functionality). In any event, this would be a much more involved approach instead of just getting your ArcObjects implmented into your Layout View in ArcGIS Desktop.
... View more
12-05-2011
06:25 AM
|
0
|
0
|
722
|
|
POST
|
Hello James, thank you for your answers. Now I have a program, that works: I make a ADO-Datatable with a SQL-Query. Then I convert the ADO-Datatable into ITable and from this a made a XY-Event-Layer. To update the Layer I refill the ADO-Datatable, then I delete all Rows in the ITable and transfer the ADO-Datatable in this ITable again, so the reference between XYEventLayer and ITable is the same. It requires at this moment, that the structure has not been changed. Also I only tested with 30 points. But I'm confident that the performance is acceptable. Again, many thanks for all. 🙂 Great to hear, Hagen! Were you able to use the code I provided?
... View more
11-18-2011
03:15 AM
|
0
|
0
|
2147
|
|
POST
|
I don't want to convert the ADO-Datatable to an ESRI-Table, I thought there is a possiblity to use the Datatable directly thru QueryInterface. Sorry I misunderstood -- have a look at the thread title you wrote and I think you'll see why I misundertood 😉 That'd sure would be nice! Please let me know if you find a way to accomplish this. I found this in the old forums that shows there used to be a ToDataset utility (ESRI.ArcGIS.Utility.Converter namespace) in 9.1 but was moved to ESRI.ArcGIS.Server.WebControls.Converter so this is not avail to Desktop apps. http://forums.esri.com/Thread.asp?c=93&f=993&t=256271&mc=7#msgid786105 The way I deal with this now is to just build and re-build a Point FeatureClass with the conversion code (or something close) I provided. That is, instead of processing the ADO.NET DataTable into an ITable, I just generate a new point FeatureClass from it. Haven't tried it with an X/Y Event Layer. This approach has worked pretty darn well --- as long as the filling of the DataTable is quick, which is accomplished by way of utilizing my own StoredProcedures that deal with the SqlDataAdapter. Once that is complete, the actual ArcObjects to build the point FeatureClass is what generates some overhead. Good luck!
... View more
11-17-2011
01:10 AM
|
0
|
0
|
2147
|
|
POST
|
Not so much a suggestion, but a solution. First, please have a look at the sample project I have uploaded to the code gallery, it might come in handy: http://resources.arcgis.com/gallery/file/arcobjects-net-api/details?entryID=675318D8-1422-2418-8814-772B0A56383D Second, here is the code to do what you want -- basically the reverse of the process in the sample app I uploaded. This works for an ITable in a PGDB, so you'll have to make adjustments for other types (SDE tables will require special additions and are outside of the scope of this thread). Just issue the ADO.NET DataTable reference and an ITableName value to this function (you'll have to set the db_path string to your own system. Good luck! james Private Function ConvDT_To_ITab(ByVal inDataTable As DataTable, ByVal inITableName As String) As ITable
Try
'**Open the PGDB for temp layers
Dim db_path As String = "C:\yourpathname\yourPGDBname.mdb"
Dim pWS As IWorkspace
Dim pFWS As IFeatureWorkspace
Dim pWorkspaceFactory As IWorkspaceFactory
pWorkspaceFactory = New ESRI.ArcGIS.DataSourcesGDB.AccessWorkspaceFactory
pFWS = pWorkspaceFactory.OpenFromFile(db_path, 0)
pWS = pFWS
' Set up a simple fields collection
Dim pFields As ESRI.ArcGIS.Geodatabase.IFields
Dim pFieldsEdit As ESRI.ArcGIS.Geodatabase.IFieldsEdit
pFields = New ESRI.ArcGIS.Geodatabase.Fields
pFieldsEdit = New ESRI.ArcGIS.Geodatabase.Fields
pFieldsEdit = pFields
Dim pField As ESRI.ArcGIS.Geodatabase.IField
Dim pFieldEdit As ESRI.ArcGIS.Geodatabase.IFieldEdit
pField = New ESRI.ArcGIS.Geodatabase.Field
pFieldEdit = pField
'' create the object id field
pField = New ESRI.ArcGIS.Geodatabase.Field
pFieldEdit = pField
pFieldEdit.Name_2 = "OBJECTID"
pFieldEdit.Type_2 = esriFieldType.esriFieldTypeOID
pFieldsEdit.AddField(pField)
For i = 0 To inDataTable.Columns.Count - 1
pField = New ESRI.ArcGIS.Geodatabase.Field
pFieldEdit = pField
With pFieldEdit 'set all the properties according to the columns in the recordset
.Length_2 = inDataTable.Columns(i).MaxLength
.Name_2 = inDataTable.Columns(i).ColumnName
.Type_2 = ESRI.ArcGIS.Geodatabase.esriFieldType.esriFieldTypeInteger
End With
Dim ColName As String = inDataTable.Columns(i).ColumnName.ToString
Dim dtColType As String = inDataTable.Columns(i).DataType.ToString
If inDataTable.Columns(i).DataType.FullName.ToString = "System.Int32" Then
pFieldEdit.Type_2 = ESRI.ArcGIS.Geodatabase.esriFieldType.esriFieldTypeInteger
ElseIf inDataTable.Columns(i).DataType.FullName.ToString = "System.String" Then
pFieldEdit.Type_2 = ESRI.ArcGIS.Geodatabase.esriFieldType.esriFieldTypeString
ElseIf inDataTable.Columns(i).DataType.FullName.ToString = "System.Double" Then
pFieldEdit.Type_2 = ESRI.ArcGIS.Geodatabase.esriFieldType.esriFieldTypeDouble
ElseIf inDataTable.Columns(i).DataType.FullName.ToString = "System.Decimal" Then
pFieldEdit.Type_2 = ESRI.ArcGIS.Geodatabase.esriFieldType.esriFieldTypeDouble
ElseIf inDataTable.Columns(i).DataType.FullName.ToString = "System.DateTime" Then
pFieldEdit.Type_2 = ESRI.ArcGIS.Geodatabase.esriFieldType.esriFieldTypeDate
End If
pFieldsEdit.AddField(pField)
Next i
'**Check for existing FeatClass and delete if present
Dim pExistingDs As ESRI.ArcGIS.Geodatabase.IDataset
Dim pEnumDataset As IEnumDataset
pEnumDataset = pWS.Datasets(esriDatasetType.esriDTTable)
pExistingDs = pEnumDataset.Next
Do Until pExistingDs Is Nothing
If pExistingDs.Name = inITableName Then
If pExistingDs.CanDelete Then
pExistingDs.Delete()
End If
End If
pExistingDs = pEnumDataset.Next
Loop
Dim UID_FEATURE As String = "esriGeodatabase.Object"
'** create a UID for simple features
Dim pUID As ESRI.ArcGIS.esriSystem.UID
pUID = New ESRI.ArcGIS.esriSystem.UID
pUID.Value = UID_FEATURE
''** Create new FeatClass in PGDB
Dim newITable As ITable = pFWS.CreateTable(inITableName, _
pFields, _
pUID, _
Nothing, Nothing)
Dim pCur As ICursor
Dim pRowBuf As IRowBuffer
pRowBuf = newITable.CreateRowBuffer
pCur = newITable.Insert(True)
Dim dtCol As DataColumn
Dim dtColname As String
Dim row As DataRow
For i = 0 To inDataTable.Rows.Count - 1
row = inDataTable.Rows(i)
If Not IsDBNull(row.Item(0)) Then
'***add the rest of the attributes
For Each dtCol In inDataTable.Columns
dtColname = dtCol.ColumnName.ToString
Dim dtColType As String = dtCol.DataType.ToString
If Not IsDBNull(row.Item(dtColname)) Then
pRowBuf.Value(pRowBuf.Fields.FindField(dtColname)) = row.Item(dtColname)
Else
If dtCol.DataType.FullName.ToString = "System.Int32" Then
pRowBuf.Value(pRowBuf.Fields.FindField(dtColname)) = CInt(0)
ElseIf dtCol.DataType.FullName.ToString = "System.String" Then
pRowBuf.Value(pRowBuf.Fields.FindField(dtColname)) = CStr("NA")
ElseIf dtCol.DataType.FullName.ToString = "System.Double" Then
pRowBuf.Value(pRowBuf.Fields.FindField(dtColname)) = CDbl(0.0)
ElseIf dtCol.DataType.FullName.ToString = "System.Decimal" Then
pRowBuf.Value(pRowBuf.Fields.FindField(dtColname)) = CDec(0.0)
ElseIf dtCol.DataType.FullName.ToString = "System.DateTime" Then
pRowBuf.Value(pRowBuf.Fields.FindField(dtColname)) = CDate(Now())
End If
End If
Next
pCur.InsertRow(pRowBuf)
Else
End If
Next
pCur.Flush()
Return newITable
Catch ex As Exception
MsgBox(ex.ToString)
Return Nothing
End Try
End Function
... View more
11-16-2011
03:58 AM
|
0
|
0
|
2147
|
|
POST
|
Hi Ari, No problem. Sorry, I am not very well versed in C# and wouldn't want to provide poor/bad code examples, so you'll have to convert the VB into C# yourself or hopefully someone else can comment on this thread to help you out. In any event, here is a Private Function that will accept a string (the layer name you wish to set) and return the IFeatureLayer. This would go hand-in-hand with the other codebase I provided.
Private Function Get_Lyr(ByVal sLayerName As String) As IFeatureLayer
Dim i As Integer
Dim pLayer As IFeatureLayer
pLayer = Nothing
pDoc = m_pApp.Document
pMap = pDoc.FocusMap
For i = 0 To pMap.LayerCount - 1
If pMap.Layer(i).Name = sLayerName Then
pLayer = pMap.Layer(i)
pLayer.Selectable = False
Exit For
End If
Next
Return pLayer
End Function
In the original code, just set the pFSelection to this function name and specify the layer name you wish to work on.
Dim pFCursor As IFeatureCursor
Dim pSelectionSet As ISelectionSet
Dim pFSelection As IFeatureSelection
pFSelection = Get_Lyr("YourLayerNameGoesHere") 'use the new Get_Lyr function
pSelectionSet = pFSelection.SelectionSet
''set the pfeaturecursor
pFCursor = Nothing
''Get a cursor from the selected features
pSelectionSet.Search(Nothing, False, pFCursor)
Dim curTextValue As String
Dim curIntegerValue As Integer
Dim curDateValue As DateTime
Dim pFeat As IFeature
pFeat = pFCursor.NextFeature
Do Until pFeat Is Nothing
curTextValue = pFeat.Value(pFeat.Fields.FindField("YourTextFieldName"))
curDateValue = pFeat.Value(pFeat.Fields.FindField("YourDateFieldName"))
curIntegerValue = pFeat.Value(pFeat.Fields.FindField("YourIntegerFieldName"))
pFeat = pFCursor.NextFeature
Loop
... View more
11-09-2011
05:00 AM
|
0
|
0
|
952
|
|
POST
|
Could you clarify what you want to do exactly? 1. Do you want to get related rows of a selected feature by a RelationshipClass? 2. Do you just want to get attributes of a selected feature? I am leaning towards #2, but please let us know otherwise. Here's how you'd access attribute values of selected features:
pDoc = m_pApp.Document 'setting m_pApp is a seperate question for another thread
pMap = pDoc.FocusMap
Dim pFCursor As IFeatureCursor
Dim pSelectionSet As ISelectionSet
Dim pFSelection As IFeatureSelection
pFSelection = pMap.Layer(0) 'just use the first layer in the TOC for simplicity
pSelectionSet = pFSelection.SelectionSet
''set the pfeaturecursor
pFCursor = Nothing
''Get a cursor from the selected features
pSelectionSet.Search(Nothing, False, pFCursor)
Dim curTextValue As String
Dim curIntegerValue As Integer
Dim curDateValue As DateTime
Dim pFeat As IFeature
pFeat = pFCursor.NextFeature
Do Until pFeat Is Nothing
curTextValue = pFeat.Value(pFeat.Fields.FindField("YourTextFieldName"))
curDateValue = pFeat.Value(pFeat.Fields.FindField("YourDateFieldName"))
curIntegerValue = pFeat.Value(pFeat.Fields.FindField("YourIntegerFieldName"))
pFeat = pFCursor.NextFeature
Loop
... View more
11-08-2011
04:23 AM
|
0
|
0
|
952
|
|
POST
|
How does one set a row value to null? pRow.Value(i) = "" sets it to an empty string pRow.Value(i) = nothing also sets it to an empty string pRow.Value(i) = system.dbnull generates an error in the field calculator you can create an expression like Field1 = null and it will set the values to Null, but how do you do it in .NET? Try:
pRow.Value(i) = System.DBNull.Value
... View more
11-07-2011
06:43 AM
|
0
|
0
|
999
|
|
POST
|
Unfortunately code didn't work. I modified it a little but still get exception on the CreateFeatureBuffer. I would like to give some explanation about what I'm trying to do. At the beginning I do not have any .mdb files. Only axMapControl on the form and MXD map file. Before opening this form, I'm trying to add a new layer to the existing map with some Points from the ADO.NET dataset. Using your code I'm trying to create an empty mdb file and then set up its parameters. For UID.Value I'm using GUID Id for AddData. Thank you Code works perfectly fine for me. So, yes it works. This is coming out of an implementation I built that takes an ADO.NET DataTable (that has lat/lon values in it) and converts this into a Point FeatureLayer. I never said this code would "create an empty mdb file". Actually, I specifically show you where you need to change the path to the EXISTING Personal Geodatabase that you have already setup. You are getting your error on the CreateFeatureBuffer probably because pFeatureClass is getting set to Nothing. Did you step thru the code? What is pFeatureClass after it passes this line:
''** Create new FeatClass in PGDB
pFeatureClass = pFWS.CreateFeatureClass(LayerName, _
pFields, _
pUID, _
Nothing, _
esriFeatureType.esriFTSimple, _
"Shape", "")
My guess is that it's nothing after this because, from what it sounds like in your post, that you don't have the PGDB already setup and connceting to it. Check this line and make sure that the IFeatureWorkspace is getting set properly:
pFWS = pWorkspaceFactory.OpenFromFile(db_path, 0)
... View more
10-21-2011
03:53 AM
|
0
|
0
|
2094
|
|
POST
|
An additional function you will need to add to complete the code previously posted:
Function MakeGeoTrans(ByVal pFromSR As ISpatialReference, ByVal pToSR As ISpatialReference) As IGeoTransformation
Dim pSRF As ISpatialReferenceFactory2
pSRF = New SpatialReferenceEnvironment
Dim pGeoTrans As IGeoTransformation
'Set the transformation method you want (must be compatible with the input and output data sets)
pGeoTrans = pSRF.CreateGeoTransformation(esriSRGeoTransformationType.esriSRGeoTransformation_NAD1983_To_WGS1984_1)
pGeoTrans.PutSpatialReferences(pFromSR, pToSR)
MakeGeoTrans = pGeoTrans
End Function
Also, here is something else that might be useful if you are integrating ADO.NET into your GIS applications. This is an example I've uploaded to ArcScritps that will take an IFeatureLayer and covert it to an ADO.NET DataTable, great for adding/filling DataGridViews in your GIS applications. http://resources.arcgis.com/gallery/file/arcobjects-net-api/details?entryID=675318D8-1422-2418-8814-772B0A56383D
... View more
10-20-2011
05:27 AM
|
0
|
0
|
2094
|
|
POST
|
Galina, You have a couple of options -- create an X/Y event layer or generate a brand new point layer. Here's a Sub I developed that accepts an ADO.NET DataTable of Latitude and Longitude values, connects to an existing Personal Geodatabase, creates a new point FeatureClass in that PGDB and adds it to the TOC. This accepts the DataTable and a name string variable to build the layer, so you may have to alter the path/location of the PGDB and the lat/lon field names to your specifications. Also, adjust the CoordSystem parameters.
Public Sub buildNewLayer(ByVal inDT As DataTable, _
ByVal LayerName As String)
Dim pFeatureClass As IFeatureClass
Dim pSpRFc As SpatialReferenceEnvironment
pSpRFc = New SpatialReferenceEnvironment
'Setup Geographic CoordSys for GPS input pts
Dim pGCS As IGeographicCoordinateSystem
Dim pSpRefWGS As ISpatialReference
pGCS = pSpRFc.CreateGeographicCoordinateSystem(esriSRGeoCSType.esriSRGeoCS_WGS1984)
pGCS.SetDomain(-200, 200, -200, 200)
pSpRefWGS = pGCS
'Setup Projected CoordSys for GPS output pts
Dim pPCS As IProjectedCoordinateSystem
Dim pSpRefNAD83 As ISpatialReference
pPCS = pSpRFc.CreateProjectedCoordinateSystem(esriSRProjCSType.esriSRProjCS_NAD1983SPCS_FLWestFT)
pPCS.SetDomain(420000, 690000, 880000, 1150000)
pSpRefNAD83 = pPCS
'GeoTransformation declared
Dim pGeoTrans As IGeoTransformation
pGeoTrans = MakeGeoTrans(pSpRefWGS, pSpRefNAD83)
'**Open the PGDB for temp layers
Dim db_path As String = "C:\MyPGDB.mdb" 'name your PGDB here
Dim pWS As IWorkspace
Dim pFWS As IFeatureWorkspace
Dim pWorkspaceFactory As IWorkspaceFactory
pWorkspaceFactory = New ESRI.ArcGIS.DataSourcesGDB.AccessWorkspaceFactory
pFWS = pWorkspaceFactory.OpenFromFile(db_path, 0)
pWS = pFWS
' Set up a simple fields collection
Dim pFields As ESRI.ArcGIS.Geodatabase.IFields
Dim pFieldsEdit As ESRI.ArcGIS.Geodatabase.IFieldsEdit
pFields = New ESRI.ArcGIS.Geodatabase.Fields
pFieldsEdit = New ESRI.ArcGIS.Geodatabase.Fields
pFieldsEdit = pFields
Dim pField As ESRI.ArcGIS.Geodatabase.IField
Dim pFieldEdit As ESRI.ArcGIS.Geodatabase.IFieldEdit
pField = New ESRI.ArcGIS.Geodatabase.Field
pFieldEdit = pField
'*** set up geometry field ***
Dim pGeomDef As ESRI.ArcGIS.Geodatabase.IGeometryDef
Dim pGeomDefedit As ESRI.ArcGIS.Geodatabase.IGeometryDefEdit
pGeomDef = New ESRI.ArcGIS.Geodatabase.GeometryDef
pGeomDefedit = pGeomDef
With pGeomDefedit
.GeometryType_2 = ESRI.ArcGIS.Geometry.esriGeometryType.esriGeometryPoint
.SpatialReference_2 = pSpRefNAD83
End With
pField = New ESRI.ArcGIS.Geodatabase.Field
pFieldEdit = pField
pFieldEdit.Name_2 = "Shape"
pFieldEdit.AliasName_2 = "Geometry"
pFieldEdit.Type_2 = esriFieldType.esriFieldTypeGeometry
pFieldEdit.GeometryDef_2 = pGeomDef
pFieldsEdit.AddField(pField)
'' create the object id field
pField = New ESRI.ArcGIS.Geodatabase.Field
pFieldEdit = pField
pFieldEdit.Name_2 = "OBJECTID"
pFieldEdit.Type_2 = esriFieldType.esriFieldTypeOID
pFieldsEdit.AddField(pField)
For i = 0 To inDT.Columns.Count - 1
pField = New ESRI.ArcGIS.Geodatabase.Field
pFieldEdit = pField
With pFieldEdit 'set all the properties according to the columns in the recordset
.Length_2 = inDT.Columns(i).MaxLength
.Name_2 = inDT.Columns(i).ColumnName
.Type_2 = ESRI.ArcGIS.Geodatabase.esriFieldType.esriFieldTypeInteger
End With
Dim ColName As String = inDT.Columns(i).ColumnName.ToString
Dim dtColType As String = inDT.Columns(i).DataType.ToString
If inDT.Columns(i).DataType.FullName.ToString = "System.Int32" Then
pFieldEdit.Type_2 = ESRI.ArcGIS.Geodatabase.esriFieldType.esriFieldTypeInteger
ElseIf inDT.Columns(i).DataType.FullName.ToString = "System.String" Then
pFieldEdit.Type_2 = ESRI.ArcGIS.Geodatabase.esriFieldType.esriFieldTypeString
ElseIf inDT.Columns(i).DataType.FullName.ToString = "System.Double" Then
pFieldEdit.Type_2 = ESRI.ArcGIS.Geodatabase.esriFieldType.esriFieldTypeDouble
ElseIf inDT.Columns(i).DataType.FullName.ToString = "System.Decimal" Then
pFieldEdit.Type_2 = ESRI.ArcGIS.Geodatabase.esriFieldType.esriFieldTypeDouble
ElseIf inDT.Columns(i).DataType.FullName.ToString = "System.DateTime" Then
pFieldEdit.Type_2 = ESRI.ArcGIS.Geodatabase.esriFieldType.esriFieldTypeDate
End If
pFieldsEdit.AddField(pField)
Next i
Try
'**Check for existing FeatClass and delete if present
Dim pExistingDs As ESRI.ArcGIS.Geodatabase.IDataset
Dim pEnumDataset As IEnumDataset
pEnumDataset = pWS.Datasets(esriDatasetType.esriDTFeatureClass)
pExistingDs = pEnumDataset.Next
Do Until pExistingDs Is Nothing
If pExistingDs.Name = LayerName Then
If pExistingDs.CanDelete Then
pExistingDs.Delete()
End If
End If
pExistingDs = pEnumDataset.Next
Loop
'** create a UID for simple features
Dim pUID As ESRI.ArcGIS.esriSystem.UID
pUID = New ESRI.ArcGIS.esriSystem.UID
pUID.Value = UID_FEATURE
''** Create new FeatClass in PGDB
pFeatureClass = pFWS.CreateFeatureClass(LayerName, _
pFields, _
pUID, _
Nothing, _
esriFeatureType.esriFTSimple, _
"Shape", "")
Catch ex As Exception
MsgBox(ex.ToString)
End Try
Dim pFeatCur As IFeatureCursor
Dim pFeatBuf As IFeatureBuffer
pFeatBuf = pFeatureClass.CreateFeatureBuffer
pFeatCur = pFeatureClass.Insert(True)
'Add attributes to the FeatClass from ADO.NET Datasource
Dim tmpPoint As IPoint
Dim pGeo As ESRI.ArcGIS.Geometry.IGeometry
Dim dtCol As DataColumn
Dim dtColname As String
Dim row As DataRow
Try
For i = 0 To inDT.Rows.Count - 1
row = inDT.Rows(i)
If Not IsDBNull(row.Item("latitude")) And Not IsDBNull(row.Item("longitude")) Then
'***add the rest of the attributes
For Each dtCol In inDT.Columns
dtColname = dtCol.ColumnName.ToString
Dim dtColType As String = dtCol.DataType.ToString
If Not IsDBNull(row.Item(dtColname)) Then
pFeatBuf.Value(pFeatBuf.Fields.FindField(dtColname)) = row.Item(dtColname)
Else
If dtCol.DataType.FullName.ToString = "System.Int32" Then
pFeatBuf.Value(pFeatBuf.Fields.FindField(dtColname)) = CInt(0)
ElseIf dtCol.DataType.FullName.ToString = "System.String" Then
pFeatBuf.Value(pFeatBuf.Fields.FindField(dtColname)) = CStr("NA")
ElseIf dtCol.DataType.FullName.ToString = "System.Double" Then
pFeatBuf.Value(pFeatBuf.Fields.FindField(dtColname)) = CDbl(0.0)
ElseIf dtCol.DataType.FullName.ToString = "System.Decimal" Then
pFeatBuf.Value(pFeatBuf.Fields.FindField(dtColname)) = CDec(0.0)
ElseIf dtCol.DataType.FullName.ToString = "System.DateTime" Then
pFeatBuf.Value(pFeatBuf.Fields.FindField(dtColname)) = CDate(Now())
End If
End If
Next
'*Add the new point
tmpPoint = New ESRI.ArcGIS.Geometry.Point
tmpPoint.PutCoords((CDec(row.Item("longitude"))), CDec(row.Item("latitude")))
'*Set the new point to match Projected CoordSys of SDE FeatureClass'
pGeo = tmpPoint
pGeo.SpatialReference = pSpRefWGS
pGeo.Project(pSpRefNAD83)
'*Create a point
pGeo.SnapToSpatialReference()
pFeatBuf.Shape = pGeo
pFeatCur.InsertFeature(pFeatBuf)
Else
End If
Next
pFeatCur.Flush()
Dim pDoc As ESRI.ArcGIS.ArcMapUI.IMxDocument
Dim pMap As ESRI.ArcGIS.Carto.IMap
pDoc = m_pApp.Document
pMap = pDoc.FocusMap
Dim pLayer As IFeatureLayer
pLayer = New FeatureLayer
pLayer.FeatureClass = pFeatureClass
pLayer.Name = pFeatureClass.AliasName
pDoc.AddLayer(pLayer)
Catch ex As Exception
MsgBox(ex.ToString)
Me.Dispose()
Finally
DisposeCOMObject(pFeatCur)
End Try
pFeatBuf = Nothing
pFeatureClass = Nothing
End Sub
... View more
10-20-2011
05:26 AM
|
0
|
0
|
2094
|
| Title | Kudos | Posted |
|---|---|---|
| 1 | 02-17-2020 10:47 AM | |
| 1 | 10-25-2022 11:46 AM | |
| 1 | 08-08-2022 01:40 PM | |
| 1 | 02-15-2019 08:21 AM | |
| 2 | 08-14-2023 07:14 AM |
| Online Status |
Offline
|
| Date Last Visited |
01-22-2025
02:28 PM
|