コード例 #1
0
 /// <summary>
 /// Write nodes to doc 1 at a time as Json
 /// </summary>
 /// <returns></returns>
 public string WriteNodesToDoc(CreateTargetableWaysWithinRegions createTargetableWays, Dictionary <Relation, Polygon[]> relationRegion, IEnumerable <Node> nodeStreamer, string outPath)
 {
     using (var fs = File.Open(outPath, FileMode.OpenOrCreate, FileAccess.Write, FileShare.Read))
     {
         using (var sr = new StreamWriter(fs, Encoding.UTF8, 65536)) // set a larger buffer
         {
             foreach (var node in ThreadedNodeContainment(relationRegion, nodeStreamer))
             {
                 if (createTargetableWays.ProcessNode(node) || node.Relations.Count() > 0)
                 {
                     var nodeStr = JsonConvert.SerializeObject(node);
                     sr.WriteLine(nodeStr);
                 }
             }
         }
     }
     return(outPath);
 }
コード例 #2
0
        public void RunChain(string boundariesFilePath, string runnableWaysPath)
        {
            var relationRegion = GeometryFactory.GetRegionGeometry(boundariesFilePath, false, false);

            var thread1 = Task <Dictionary <Relation, Polygon[]> > .Factory.StartNew(() => this.CreateRelationPolygons(relationRegion.Relations));

            var thread2 = Task <Geometry> .Factory.StartNew(() => GeometryFactory.GetRegionGeometry(runnableWaysPath, true, false));

            Task.WaitAll(thread1, thread2);
            var waysRegion    = thread2.Result;
            var relationsDict = thread1.Result;

            var nodeStreamer = this.GetNodeStreamer(runnableWaysPath);

            var watch = Stopwatch.StartNew();
            var createTargetableWays = new CreateTargetableWaysWithinRegions(waysRegion.Ways, relationRegion.Relations);
            var time = watch.Elapsed;

            Console.WriteLine($"Done prepping ways in {time}");
            watch.Restart();

            WriteNodesToDoc(createTargetableWays, relationsDict, nodeStreamer, RouteCleanerSettings.GetInstance().TemporaryNodeOutLocation);
            time = watch.Elapsed;
            Console.WriteLine($"Done with NodeContainment in {time} seconds.");

            Console.WriteLine($"Found {createTargetableWays.OutputWays.Count} targetableWays");

            watch.Restart();
            var ways = createTargetableWays.OutputWays;

            var w = ways.Where(w => w.Id == "");


            ways = ConsolidateWays(ways);
            ways = UnconsolidateLargeWays(ways).ToList();  // todo is the problem?
            time = watch.Elapsed;
            Console.WriteLine($"Done with ConsolidatedWays in {time} seconds. Have {ways.Count} ways.");

            this.WriteWays(ways, RouteCleanerSettings.GetInstance().TemporaryTargetableWaysLocation);
        }