Apologies for my ignorance, I'm new to this. How do I know what feature class I used to call IFeatureClass::CreatFeature? And how do I open the feature class from the database I want? This is where I call CreateFeature, about half way down.Public Sub go()
initlicence()
'MonitorThread = New Thread(AddressOf Monitor)
'MonitorThread.Priority = ThreadPriority.BelowNormal
'MonitorThread.Start()
' convertjunctionfile(0.002910881)
Dim featureclass1 As IFeatureClass = GetFeatureClass("StopsInput")
Dim featureclassCensus As IFeatureClass = GetFeatureClass("census_enumerator_areas")
'Dim featureclassPOW As IFeatureClass = GetFeatureClass("pow_area_point")
Dim featureclassED As IFeatureClass = GetFeatureClass("electoral_divisions")
Dim EDindex As Integer = -1
Dim censusindex As Integer = -1
Dim eastingsindex As Integer = -1
Dim northingsindex As Integer = -1
For j = 0 To header.Length - 1
Select Case header(j)
Case "Residence_ED"
EDindex = j
Case "Residence_2006_Enumeration_Area"
censusindex = j
Case "Fuzz_East_250"
eastingsindex = j
Case "Fuzz_North_250"
northingsindex = j
End Select
Next
'check headers have been read in corrrectly
If (EDindex = -1 Or censusindex = -1 Or eastingsindex = -1 Or northingsindex = -1) Then
MsgBox("Error reading in input file header")
End If
'MsgBox("total header length: " + header.Length.ToString)
'MsgBox("EDindex" + EDindex.ToString)
' MsgBox("censusindex" + censusindex.ToString)
' MsgBox("eastingsindex" + eastingsindex.ToString)
MsgBox("northingsindex" + northingsindex.ToString)
Dim route1length As Integer
Dim startOID As Integer = 0
Dim inputVals() As String
Dim startpoint As ESRI.ArcGIS.Geometry.Point
Dim endpoint As ESRI.ArcGIS.Geometry.Point = New ESRI.ArcGIS.Geometry.Point
Dim route1() As Integer
Dim routeClass As RouteClass = New RouteClass
Dim crowflies As Double = Nothing
routeClass.Init()
Dim OutputDatabase1 As OutputDatabase = New OutputDatabase
Dim numPrevProcessed As Integer = 0
If continue_from_prev_from_form = True Then
OutputDatabase1.continueFromOld()
numPrevProcessed = OutputDatabase1.getNumberProcessed()
'MsgBox("num prev processed: " + numPrevProcessed.ToString)
'This loop cycles past any previously processed details
For m As Integer = 1 To numPrevProcessed
TextFromFile1.Read()
Next
Else 'Initialise database using header information
OutputDatabase1.init(header)
MsgBox("OutputGeodatabase")
End If
'initialise variables
For Me.person_number = (numPrevProcessed + 1) To (number_to_process_fromform + numPrevProcessed + 1)
'updates global person number, for error reporting purposes
person_no_global = person_number
'Clears any previous route stops from the screen
DeleteRows(featureclass1)
inputVals = TextFromFile1.Read()
MsgBox(inputVals.ToString)
'This if statement exits the loop if the reader reaches the end of the file
If inputVals Is Nothing Then
TextFromFile1.errorwriter("End of input file. All entries processed", person_number)
Exit For
End If
'Conditions to check that input file info is all present and intact
If (IsNumeric(inputVals(censusindex)) Or IsNumeric(inputVals(EDindex))) And IsNumeric(inputVals(eastingsindex)) And IsNumeric(inputVals(northingsindex)) Then
MsgBox("1")
If (Not IsNumeric(inputVals(censusindex))) Or inputVals(censusindex) = "*" Then
startpoint = FindCentroid(featureclassED, inputVals(EDindex), False)
MsgBox("2")
Else
startpoint = FindCentroid(featureclassCensus, inputVals(censusindex), True)
MsgBox("startpoint: " + startpoint.ToString)
MsgBox("3")
'If point can't be found from census area then use
If startpoint Is Nothing Then
startpoint = FindCentroid(featureclassED, inputVals(EDindex), False)
MsgBox("4")
End If
End If
'initialise startOID and route
startOID = Nothing
route1 = Nothing
route1length = 0
crowflies = Nothing
Command1.resultDistance = 0
'condition in case startpoint can't be found
If Not startpoint Is Nothing Then
MsgBox("11")
MsgBox("person: " + person_no_global.ToString)
'Dim endpoint As ESRI.ArcGIS.Geometry.Point = FindPOW(featureclassPOW, 400)
endpoint.X = inputVals(eastingsindex) + (Rnd(person_number + 0.2) - 0.5) * 2 * 125
endpoint.Y = inputVals(northingsindex) + (Rnd(person_number + 0.3) - 0.5) * 2 * 125
CreateFeature("StopsInput", startpoint.X, startpoint.Y, featureclass1)
CreateFeature("StopsInput", endpoint.X, endpoint.Y, featureclass1)
'selectall()
'Call routing functions
MsgBox("6 " + startpoint.X.ToString)
'route1 = Router()
route1 = routeClass.SolveRoute()
MsgBox("7")
If Not route1 Is Nothing Then
MsgBox("Route Nothing")
startOID = OutputDatabase1.WriteToRouteTableRowField(person_number, route1)
route1length = route1.Length
Else
route1length = 0
MsgBox("route length")
End If
crowflies = crowFliesDistance(startpoint, endpoint)
MsgBox("8")
End If
OutputDatabase1.WriteToMainTableRowField(person_number, startOID, inputVals, route1length, crowflies, resultDistance)
MsgBox("9")
Else
OutputDatabase1.WriteToMainTableRowField(person_number, Nothing, inputVals, 0, 0, 0)
MsgBox("10")
TextFromFile1.errorwriter("Missing info (ED/census or POW co-ords for routing. Person no", person_number)
End If
'updates progress bar every 10 people
'If person_number Mod 10 = 0 Then
'progressNum = CType(System.Math.Abs(((person_number - numPrevProcessed) * 100) / number_to_process_fromform), Integer)
'If progressNum <= 100 Then
'UpdateUI(progressNum)
'End If
If person_number Mod 100 = 0 Then
'OPTIONAL GARBAGE COLLECTOR CALL
'Used to force system to clean out unused areas of ram every 100 cycles
System.GC.Collect()
End If
'End If
'progressbox1.ProgressBar1.Value = 49 + person_number * 50
'progressbox1.Refresh()
'routeprogress.Invoke(New UpdateUIDelegate() ), New Object() {50 + person_number * 50})
MsgBox(person_number)
Next person_number
'routeClass.SaveLayerToDisk(routeClass.naLayerStore, System.Environment.CurrentDirectory + "\RouteGEN.lyr")
'routeprogress
System.GC.Collect()
'errorwriter("Finished successfully", person_number)
'Adds Route layer to display
'Dim mxDocument As IMxDocument = GetMxDocumentFromArcMap(m_application)
'Dim activeView As IActiveView = mxDocument.ActiveView
'AddLayerFromFile(activeView, routeClass.SHAPE_WORKSPACE + "RouteGEN.lyr")
'ESRI License Initializer generated code.
'Do not make any call to ArcObjects after ShutDownApplication()
OutputDatabase1 = Nothing
Try
'progressbox1.Close()
MonitorThread.Abort()
'progressbox1 = Nothing
Catch ex As Exception
End Try
m_AOLicenseInitializer.ShutdownApplication()
MsgBox("Routing done: " + (person_number - 1).ToString + " routes calculated in total. Finished at: " + TimeOfDay.ToLongTimeString())
End Sub