Пример #1
0
 private static void LoadAll()
 {
     GLOBAL_FINAL = new OSMMetaFinal();
     // init
     GLOBAL_FINAL.gridPoints = new Dictionary <ISector, GridPointInfo[, ]>();
     foreach (var root in ZCoords.GetSectorManager().GetTopmostOSMSectors())
     {
         GridPointInfo[,] gp = new GridPointInfo[257, 257];
         for (int x = 0; x < 257; x++)
         {
             for (int y = 0; y < 257; y++)
             {
                 gp[x, y] = new GridPointInfo();
             }
         }
         GLOBAL_FINAL.gridPoints[root] = gp;
     }
     for (int r = 0; r < 6; r++)
     {
         var    frRoot   = new CubeSector((CubeSector.CubeSectorFace)r, 0, 0, 0);
         string filePath = Path.Combine(OSMPaths.GetRenderRoot(), $"Coastline{frRoot.sectorFace.GetFaceAcronym()}.txt");
         using (var writer = File.Open(filePath, FileMode.Open))
         {
             using (var br = new BinaryReader(writer))
             {
                 int badRelationsCount = br.ReadInt32();
                 for (int i = 0; i < badRelationsCount; i++)
                 {
                     GLOBAL_FINAL.badRelations.Add(br.ReadInt64());
                 }
                 for (int i = 0; i < 257; i++)
                 {
                     for (int j = 0; j < 257; j++)
                     {
                         GridPointInfo gridPoint         = GLOBAL_FINAL.gridPoints[frRoot][i, j];
                         int           naturalTypesCount = br.ReadInt32();
                         for (int k = 0; k < naturalTypesCount; k++)
                         {
                             gridPoint.naturalTypes.Add(br.ReadInt32());
                         }
                         int relationsCount = br.ReadInt32();
                         for (int k = 0; k < relationsCount; k++)
                         {
                             gridPoint.relations.Add(br.ReadInt64());
                         }
                         int waysCount = br.ReadInt32();
                         for (int k = 0; k < waysCount; k++)
                         {
                             gridPoint.ways.Add(br.ReadInt64());
                         }
                     }
                 }
             }
         }
     }
 }
Пример #2
0
        internal SectorConstrainedOSMAreaGraph GetCoastAreaMap(string key, string value)
        {
            // remember: "If you regard this as tracing around an area of land, then the coastline way should be running counterclockwise."
            // gather ways with matching starts/ends to form a super-way, coast ways should always run the same direction, so this becomes easier
            SuperWayCollection            superWays = GenerateSuperWayCollection(EnumerateWays().Where(x => x.keyValues.ContainsKey(key) && x.keyValues[key] == value), false);
            SectorConstrainedOSMAreaGraph map       = DoMultipolygon(superWays);

            if (OSMMetaFinal.IsPixelLand(sector) || borderWay.refs.Count > 5) // just return a big ol' square
            {
                SectorConstrainedOSMAreaGraph temp = new SectorConstrainedOSMAreaGraph();
                for (int i = 1; i < borderWay.refs.Count; i++)
                {
                    if (!temp.nodes.ContainsKey(borderWay.refs[i]))
                    {
                        temp.nodes[borderWay.refs[i]] = new List <AreaNode>();
                        temp.nodes[borderWay.refs[i]].Add(new AreaNode()
                        {
                            id = borderWay.refs[i]
                        });
                    }
                }
                for (int i = 1; i < borderWay.refs.Count; i++)
                {
                    AreaNode prev = temp.nodes[borderWay.refs[i - 1]].Single();
                    AreaNode next = temp.nodes[borderWay.refs[i]].Single();
                    if (prev.id != next.id)
                    {
                        prev.next = next;
                        next.prev = prev;
                    }
                }
                map = map.Intersect(temp, this);
            }
            BlobsIntersector.FixLoops(new List <SectorConstrainedOSMAreaGraph>()
            {
                map
            }, this);
            if (Constants.DEBUG_MODE)
            {
                map.CheckValid();
            }
            return(map);
        }
Пример #3
0
        public BlobCollection(List <Blob> blobs, ISector sector)
        {
            borderWay      = new Way();
            borderWay.id   = -10;
            borderWay.refs = new List <long>()
            {
                -900, -901, -902, -903, -900
            };                                                                  // arbitrary for now, but ccw for land
            nodes.Add(-900, new Vector2d(0, 0));
            nodes.Add(-901, new Vector2d(0, 1));
            nodes.Add(-902, new Vector2d(1, 1));
            nodes.Add(-903, new Vector2d(1, 0));

            this.blobs         = blobs;
            this.sector        = sector;
            this.gridPointInfo = OSMMetaFinal.GetGridPointInfo(sector);
            // initialize
            ISector rootSector = sector.GetRoot();

            foreach (var blob in blobs)
            {
                if (blob.type != "OSMData")
                {
                    continue;
                }
                // build node data
                for (int i = 0; i < blob.pBlock.primitivegroup.Count; i++)
                {
                    var pGroup = blob.pBlock.primitivegroup[i];
                    for (int j = 0; j < pGroup.dense.Count; j++)
                    {
                        var d = pGroup.dense[j];
                        for (int k = 0; k < d.id.Count; k++)
                        {
                            double longitude = .000000001 * (blob.pBlock.lon_offset + (blob.pBlock.granularity * d.lon[k]));
                            double latitude  = .000000001 * (blob.pBlock.lat_offset + (blob.pBlock.granularity * d.lat[k]));
                            nodes[d.id[k]] = sector.ProjectToLocalCoordinates(new LongLat(longitude * Math.PI / 180, latitude * Math.PI / 180).ToSphereVector());
                        }
                    }
                }
            }
        }