public void ForEachFeatures(ShapeFileFeatureSource featureSource, Func <Feature, int, int, int, bool> process) { if (!featureSource.IsOpen) { featureSource.Open(); } int currentProgress = 0; int currentFeatureCount = featureSource.GetCount(); for (int i = 0; i < currentFeatureCount; i++) { var currentFeature = featureSource.GetFeatureById((i + 1).ToString(), featureSource.GetDistinctColumnNames()); if (process != null) { currentProgress++; var currentPercentage = currentProgress * 100 / currentFeatureCount; var canceled = process(currentFeature, currentProgress, currentFeatureCount, currentPercentage); if (canceled) { break; } } } }
private void btnRaiseEvent_Click(object sender, EventArgs e) { cancel = false; gbProgress.Visible = true; processedCount = 0; pgBuildingData.Minimum = 0; pgBuildingData.Value = 0; ShapeFileFeatureSource featureSource = new ShapeFileFeatureSource(Path.Combine(rootPath, "DallasCounty-4326.shp")); featureSource.Open(); pgBuildingData.Maximum = featureSource.GetCount(); lbTotalCount.Text = pgBuildingData.Maximum.ToString(CultureInfo.InvariantCulture); featureSource.Close(); RtgRoutingSource.GenerateRoutingData(Path.Combine(rootPath, "BuildingRoutingDataEvent.rtg"), featureSource, BuildRoutingDataMode.Rebuild, "DallasCounty-4326.shp"); if (cancel) { MessageBox.Show("Building routing data has been cancelled!"); } else { MessageBox.Show("Finish building routing data!"); } gbProgress.Visible = false; }
private void btnGenerateRoadData_Click(object sender, EventArgs e) { // Please uncomment the code below to disassemble the shapefile // RoutingHelper.GenerateRoutableShapeFile(@"..\..\SampleData\Edmonton.shp", @"..\..\SampleData\RoutableEdmonton.shp"); ShapeFileFeatureSource disassembledFeatureSource = new ShapeFileFeatureSource(@"..\..\SampleData\RoutableEdmonton.shp"); disassembledFeatureSource.Open(); lbDisassebledCount.Text = disassembledFeatureSource.GetCount().ToString(CultureInfo.InvariantCulture); disassembledFeatureSource.Close(); MessageBox.Show("Finish building routing data!"); }