POST
|
I've tested function ConvertShapefileToFeatureClass() which converts dedicated shapefile to gdb (file geodatabase) and it works very well. As a result of this function, the shapefile were converted into feature class in the file geodatabase. Now, I want to save the converted shapefile into SDE database (in SQL server). I use the same function and modify the 'targetWsPath' to SDE connection. Unfortunately an error occured, 'create output feature class failed'. here i attach my code and the error. really appreciate if someone can tell me what's happening 😞 Public Sub ConvertShapefileToFCSDE() ESRI.ArcGIS.RuntimeManager.BindLicense(ESRI.ArcGIS.ProductCode.Engine) Dim aoInitialize As IAoInitialize aoInitialize = New AoInitialize aoInitialize.Initialize(esriLicenseProductCode.esriLicenseProductCodeEngine) ' Open the source and target workspaces. Dim sourceWorkspacePath As String = "C:\projek peta melaka" Dim pProp As IPropertySet = New PropertySet Dim wFac As New SdeWorkspaceFactory Dim targetWorkspace As IWorkspace Dim targetWsPath As String = "Provider=SQLNCLI10;" + _ "Data Source=" + My.Settings.Server + ";" + _ "Initial Catalog=" + My.Settings.Database + ";" + _ "User ID=" + My.Settings.User + ";" + _ "Password=" + My.Settings.Password + ";" pProp.SetProperty("Server", My.Settings.Server) pProp.SetProperty("Instance", My.Settings.Instance) pProp.SetProperty("Database", My.Settings.Database) pProp.SetProperty("User", My.Settings.User) pProp.SetProperty("Password", My.Settings.Password) pProp.SetProperty("Version", My.Settings.Version) targetWorkspace = wFac.Open(pProp, 0) WS = targetWorkspace 'Dim targetWorkspacePath As String = "C:\projek peta melaka\Melaka.gdb" Dim sourceWorkspaceFactory As IWorkspaceFactory = New ShapefileWorkspaceFactoryClass() Dim targetWorkspaceFactory As IWorkspaceFactory = New FileGDBWorkspaceFactoryClass() Dim sourceWorkspace As IWorkspace = sourceWorkspaceFactory.OpenFromFile(sourceWorkspacePath, 0) 'Dim targetWorkspace As IWorkspace = targetWorkspaceFactory.Open(targetWsPath, 0) ' Cast the workspaces to the IDataset interface and get name objects. Dim sourceWorkspaceDataset As IDataset = CType(sourceWorkspace, IDataset) Dim targetWorkspaceDataset As IDataset = CType(targetWorkspace, IDataset) Dim sourceWorkspaceDatasetName As IName = sourceWorkspaceDataset.FullName Dim targetWorkspaceDatasetName As IName = targetWorkspaceDataset.FullName Dim sourceWorkspaceName As IWorkspaceName = CType(sourceWorkspaceDatasetName, IWorkspaceName) Dim targetWorkspaceName As IWorkspaceName = CType(targetWorkspaceDatasetName, IWorkspaceName) ' Create a name object for the shapefile and cast it to the IDatasetName interface. Dim sourceFeatureClassName As IFeatureClassName = New FeatureClassNameClass() Dim sourceDatasetName As IDatasetName = CType(sourceFeatureClassName, IDatasetName) sourceDatasetName.Name = "tsempdm.shp" sourceDatasetName.WorkspaceName = sourceWorkspaceName ' Create a name object for the FGDB feature class and cast it to the IDatasetName interface. Dim targetFeatureClassName As IFeatureClassName = New FeatureClassNameClass() Dim targetDatasetName As IDatasetName = CType(targetFeatureClassName, IDatasetName) targetDatasetName.Name = "tsemp" targetDatasetName.WorkspaceName = targetWorkspaceName ' Open source feature class to get field definitions. Dim sourceName As IName = CType(sourceFeatureClassName, IName) Dim sourceFeatureClass As IFeatureClass = CType(sourceName.Open(), IFeatureClass) ' Create the objects and references necessary for field validation. Dim fieldChecker As IFieldChecker = New FieldCheckerClass() Dim sourceFields As IFields = sourceFeatureClass.Fields Dim targetFields As IFields = Nothing Dim enumFieldError As IEnumFieldError = Nothing ' Set the required properties for the IFieldChecker interface. fieldChecker.InputWorkspace = sourceWorkspace fieldChecker.ValidateWorkspace = targetWorkspace ' Validate the fields and check for errors. fieldChecker.Validate(sourceFields, enumFieldError, targetFields) If Not enumFieldError Is Nothing Then ' Handle the errors in a way appropriate to your application. Console.WriteLine("Errors were encountered during field validation.") End If ' Find the shape field. Dim shapeFieldName As String = sourceFeatureClass.ShapeFieldName Dim shapeFieldIndex As Integer = sourceFeatureClass.FindField(shapeFieldName) Dim shapeField As IField = sourceFields.Field(shapeFieldIndex) ' Get the geometry definition from the shape field and clone it. Dim geometryDef As IGeometryDef = shapeField.GeometryDef Dim geometryDefClone As IClone = CType(geometryDef, IClone) Dim targetGeometryDefClone As IClone = geometryDefClone.Clone() Dim targetGeometryDef As IGeometryDef = CType(targetGeometryDefClone, IGeometryDef) '----------- ' Cast the IGeometryDef to the IGeometryDefEdit interface. Dim targetGeometryDefEdit As IGeometryDefEdit = CType(targetGeometryDef, IGeometryDefEdit) ' Set the IGeometryDefEdit properties. targetGeometryDefEdit.GridCount_2 = 1 targetGeometryDefEdit.GridSize_2(0) = 0.75 ' Create the converter and run the conversion. Dim featureDataConverter As IFeatureDataConverter = New FeatureDataConverterClass() Dim enumInvalidObject As IEnumInvalidObject = featureDataConverter.ConvertFeatureClass(sourceFeatureClassName, Nothing, Nothing, targetFeatureClassName, targetGeometryDef, targetFields, "", 1000, 0) ' Check for errors. Dim invalidObjectInfo As IInvalidObjectInfo = Nothing enumInvalidObject.Reset() Do While Not (invalidObjectInfo) Is Nothing ' Handle the errors in a way appropriate to the application. Console.WriteLine("Errors occurred for the following feature: {0}", invalidObjectInfo.InvalidObjectID) invalidObjectInfo = enumInvalidObject.Next() Loop End Sub
... View more
12-21-2011
09:36 PM
|
0
|
0
|
2742
|
POST
|
Not too long after I posted this message, I found an explanation for the behavior I described. I was, indeed, initializing an ArcObjects class as a private member of my class before calling RuntimeManager.Bind(). That initialization didn't throw an exception; but by creating it after calling RuntimeManager.Bind(), I no longer seem to see the problem mentioned in my post. hi patbullberry, eventho this thread was created long time ago, may i know where to call the runtimemanager.bind? i have the same problem, where this exception occurs when i execute my project. some how, i've called runtimemanager.bind() in my sub form and it was ok. but when i compile the whole project, the exception appeared again in my main form. really appreciate your feed back 🙂
... View more
11-20-2011
11:10 PM
|
0
|
0
|
389
|
POST
|
i tried this function to convert shapefiles to feature class. unfortunately, this error occured . the 'melaka.gdb' is a empty file geodatabase. from my understanding, the error happens when the function try to open the melaka.gdb file. i have no idea why and how to fix this. refer image in the attachment. can someone help me on this?
... View more
11-16-2011
11:14 PM
|
0
|
2
|
512
|
Online Status |
Offline
|
Date Last Visited |
11-11-2020
02:24 AM
|