コード例 #1
0
        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);
        }
コード例 #2
0
        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;
        }