public virtual RoadNetwork CreateNetwork(FeatureSource featureSource) { featureSource.Open(); QTreeSpatialIndex qtree = new QTreeSpatialIndex(featureSource.GetBoundingBox()); #if DEBUG long featureCount = featureSource.GetCount(); #endif RoadNetwork roadNetwork = new RoadNetwork(); Collection<Feature> features = featureSource.GetAllFeatures(ReturningColumnsType.NoColumns); featureSource.Close(); Collection<Collection<Feature>> featureGroups = GroupFeatures(features); int done = 0; var tasks = (from items in featureGroups select Task.Factory.StartNew(() => { var clonedFeatureSource = featureSource.CloneDeep(); clonedFeatureSource.Open(); foreach (var feature in items) { Collection<LineShape> processingLineShapes = GeometryHelper.GetLineShapes(feature); // Get the lineshape of the processing feature. foreach (LineShape processingLineShape in processingLineShapes) { BuildNetworkNode(clonedFeatureSource, qtree, roadNetwork, processingLineShape.Vertices[0]); BuildNetworkNode(clonedFeatureSource, qtree, roadNetwork, processingLineShape.Vertices[processingLineShape.Vertices.Count - 1]); } done++; Console.WriteLine(string.Format("Done {0} in {1}", feature.Id, done)); } })).ToArray(); //foreach (Feature feature in features) //{ // Task.Factory.StartNew(() => // { // Collection<LineShape> processingLineShapes = GeometryHelper.GetLineShapes(feature); // // Get the lineshape of the processing feature. // foreach (LineShape processingLineShape in processingLineShapes) // { // BuildNetworkNode(featureSource, qtree, roadNetwork, processingLineShape.Vertices[0]); // BuildNetworkNode(featureSource, qtree, roadNetwork, processingLineShape.Vertices[processingLineShape.Vertices.Count - 1]); // } // } // ); Task.WaitAll(tasks); #if DEBUG #endif //} //featureSource.Close(); return roadNetwork; }
public virtual RoadNetwork CreateNetwork(FeatureSource featureSource) { featureSource.Open(); QTreeSpatialIndex qtree = new QTreeSpatialIndex(featureSource.GetBoundingBox()); #if DEBUG long featureCount = featureSource.GetCount(); #endif RoadNetwork roadNetwork = new RoadNetwork(); Collection <Feature> features = featureSource.GetAllFeatures(ReturningColumnsType.NoColumns); featureSource.Close(); Collection <Collection <Feature> > featureGroups = GroupFeatures(features); int done = 0; var tasks = (from items in featureGroups select Task.Factory.StartNew(() => { var clonedFeatureSource = featureSource.CloneDeep(); clonedFeatureSource.Open(); foreach (var feature in items) { Collection <LineShape> processingLineShapes = GeometryHelper.GetLineShapes(feature); // Get the lineshape of the processing feature. foreach (LineShape processingLineShape in processingLineShapes) { BuildNetworkNode(clonedFeatureSource, qtree, roadNetwork, processingLineShape.Vertices[0]); BuildNetworkNode(clonedFeatureSource, qtree, roadNetwork, processingLineShape.Vertices[processingLineShape.Vertices.Count - 1]); } done++; Console.WriteLine(string.Format("Done {0} in {1}", feature.Id, done)); } })).ToArray(); //foreach (Feature feature in features) //{ // Task.Factory.StartNew(() => // { // Collection<LineShape> processingLineShapes = GeometryHelper.GetLineShapes(feature); // // Get the lineshape of the processing feature. // foreach (LineShape processingLineShape in processingLineShapes) // { // BuildNetworkNode(featureSource, qtree, roadNetwork, processingLineShape.Vertices[0]); // BuildNetworkNode(featureSource, qtree, roadNetwork, processingLineShape.Vertices[processingLineShape.Vertices.Count - 1]); // } // } // ); Task.WaitAll(tasks); #if DEBUG #endif //} //featureSource.Close(); return(roadNetwork); }
private void BuildNetworkNode(FeatureSource featureSource, QTreeSpatialIndex qtree, RoadNetwork roadNetwork, Vertex vertex) { RectangleShape startSmallBounds = GeometryHelper.CreateSmallRectangle(vertex, tolerance); Collection <string> idsInside = qtree.GetFeatureIdsIntersectingBoundingBox(startSmallBounds); if (idsInside.Count <= 0) { Node startNode = CreateNode(featureSource, roadNetwork, vertex); roadNetwork.Nodes.Add(startNode); qtree.Add(new PointShape(vertex)); } }
private void BuildNetworkNode(FeatureSource featureSource, QTreeSpatialIndex qtree, RoadNetwork roadNetwork, Vertex vertex) { RectangleShape startSmallBounds = GeometryHelper.CreateSmallRectangle(vertex, tolerance); Collection<string> idsInside = qtree.GetFeatureIdsIntersectingBoundingBox(startSmallBounds); if (idsInside.Count <= 0) { Node startNode = CreateNode(featureSource, roadNetwork, vertex); roadNetwork.Nodes.Add(startNode); qtree.Add(new PointShape(vertex)); } }