예제 #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
        private void SaveAsFile(OSMMetaManager manager, CubeSector root)
        {
            for (int i = 0; i < 257; i++)
            {
                for (int j = 0; j < 257; j++)
                {
                    for (int k = 1; k < naturalTypes.Count; k++)
                    {
                        bool containsThisType = false;
                        containsThisType |= gridPoints[root][i, j].relations.Any(x => manager.relationInfo[x].ContainsKeyValue(manager, "natural", naturalTypes[k]));
                        containsThisType |= gridPoints[root][i, j].ways.Any(x => manager.wayInfo[x].ContainsKeyValue(manager, "natural", naturalTypes[k]));
                        if (containsThisType)
                        {
                            gridPoints[root][i, j].naturalTypes.Add(k);
                        }
                    }
                }
            }
            string filePath = Path.Combine(OSMPaths.GetRenderRoot(), $"Coastline{root.sectorFace.GetFaceAcronym()}.txt");

            using (var writer = File.Open(filePath, FileMode.Create))
            {
                using (var bw = new BinaryWriter(writer))
                {
                    bw.Write(badRelations.Count);
                    foreach (var relation in badRelations)
                    {
                        bw.Write(relation);
                    }
                    for (int i = 0; i < 257; i++)
                    {
                        for (int j = 0; j < 257; j++)
                        {
                            GridPointInfo gridPoint = gridPoints[root][i, j];
                            bw.Write(gridPoint.naturalTypes.Count);
                            foreach (var naturalType in gridPoint.naturalTypes)
                            {
                                bw.Write(naturalType);
                            }
                            bw.Write(gridPoint.relations.Count);
                            foreach (var relation in gridPoint.relations)
                            {
                                bw.Write(relation);
                            }
                            bw.Write(gridPoint.ways.Count);
                            foreach (var way in gridPoint.ways)
                            {
                                bw.Write(way);
                            }
                        }
                    }
                }
            }
        }
예제 #3
0
        internal static BlobCollection GetAllBlobs(ISector sector)
        {
            List <Blob> blobs = new List <Blob>();

#if WINDOWS || LINUX
            string path = OSMPaths.GetSectorPath(sector);
            using (var reader = File.OpenRead(path))
            {
                while (true)
                {
                    Blob blob = ReadBlob(reader);
                    if (blob == null)
                    {
                        break;
                    }
                    blob.Init();
                    blobs.Add(blob);
                }
            }
#else
            string path = OSMPaths.GetSectorPath(sector);
            using (var reader = Activity1.ASSETS.Open(path))
            {
                while (true)
                {
                    Blob blob = ReadBlob(reader);
                    if (blob == null)
                    {
                        break;
                    }
                    blob.Init();
                    blobs.Add(blob);
                }
            }
#endif
            return(new BlobCollection(blobs, sector));
        }
예제 #4
0
        internal void LoadAll(string fileName)
        {
            string filePath = Path.Combine(OSMPaths.GetLocalCacheRoot(), fileName);

            using (var reader = File.Open(filePath, FileMode.Open))
            {
                using (var br = new BinaryReader(reader))
                {
                    int edgeInfoCount = br.ReadInt32();
                    for (int j = 0; j < edgeInfoCount; j++)
                    {
                        EdgeInfo e = new EdgeInfo();
                        e.wayID    = br.ReadInt64();
                        e.node1    = br.ReadInt64();
                        e.node2    = br.ReadInt64();
                        e.longLat1 = new LongLat(br.ReadDouble(), br.ReadDouble());
                        e.longLat2 = new LongLat(br.ReadDouble(), br.ReadDouble());
                        if (!edgeInfo.Contains(e))
                        {
                            edgeInfo.Add(e);
                        }
                    }
                    int wayInfoCount = br.ReadInt32();
                    for (int j = 0; j < wayInfoCount; j++)
                    {
                        WayInfo w = new WayInfo();
                        w.id        = br.ReadInt64();
                        w.startNode = br.ReadInt64();
                        w.endNode   = br.ReadInt64();
                        int keyValueCount = br.ReadInt32();
                        w.keys      = new List <int>();
                        w.values    = new List <int>();
                        w.relations = new List <long>();
                        for (int k = 0; k < keyValueCount; k++)
                        {
                            w.keys.Add(LoadIntoStringTable(br.ReadString()));
                            w.values.Add(LoadIntoStringTable(br.ReadString()));
                        }
                        if (!wayInfo.ContainsKey(w.id))
                        {
                            wayInfo[w.id] = w;
                        }
                    }
                    int relationInfoCount = br.ReadInt32();
                    for (int j = 0; j < relationInfoCount; j++)
                    {
                        RelationInfo r = new RelationInfo();
                        r.id = br.ReadInt64();
                        int keyValueCount = br.ReadInt32();
                        r.keys   = new List <int>();
                        r.values = new List <int>();
                        for (int k = 0; k < keyValueCount; k++)
                        {
                            r.keys.Add(LoadIntoStringTable(br.ReadString()));
                            r.values.Add(LoadIntoStringTable(br.ReadString()));
                        }
                        int roleValuesCount = br.ReadInt32();
                        r.roleValues = new List <int>();
                        for (int k = 0; k < roleValuesCount; k++)
                        {
                            r.roleValues.Add(LoadIntoStringTable(br.ReadString()));
                        }
                        int memidsCount = br.ReadInt32();
                        r.memids = new List <long>();
                        for (int k = 0; k < memidsCount; k++)
                        {
                            r.memids.Add(br.ReadInt64());
                            if (wayInfo.ContainsKey(r.memids.Last()))
                            {
                                wayInfo[r.memids.Last()].relations.Add(r.id);
                            }
                        }
                        int typesCount = br.ReadInt32();
                        r.types = new List <int>();
                        for (int k = 0; k < typesCount; k++)
                        {
                            r.types.Add(br.ReadInt32());
                        }
                        if (!relationInfo.ContainsKey(r.id))
                        {
                            relationInfo[r.id] = r;
                        }
                    }
                }
            }
        }
예제 #5
0
        internal void SaveAll(string fileName)
        {
            string filePath = Path.Combine(OSMPaths.GetLocalCacheRoot(), fileName);

            using (var writer = File.Open(filePath, FileMode.Create))
            {
                using (var bw = new BinaryWriter(writer))
                {
                    bw.Write(edgeInfo.Count);
                    foreach (var e in edgeInfo)
                    {
                        bw.Write(e.wayID);
                        bw.Write(e.node1);
                        bw.Write(e.node2);
                        bw.Write(e.longLat1.X);
                        bw.Write(e.longLat1.Y);
                        bw.Write(e.longLat2.X);
                        bw.Write(e.longLat2.Y);
                    }
                    bw.Write(wayInfo.Count);
                    foreach (var w in wayInfo.Values)
                    {
                        bw.Write(w.id);
                        bw.Write(w.startNode);
                        bw.Write(w.endNode);
                        bw.Write(w.keys.Count);
                        for (int i = 0; i < w.keys.Count; i++)
                        {
                            bw.Write(stringTable[w.keys[i]]);
                            bw.Write(stringTable[w.values[i]]);
                        }
                    }
                    bw.Write(relationInfo.Count);
                    foreach (var r in relationInfo.Values)
                    {
                        bw.Write(r.id);
                        bw.Write(r.keys.Count);
                        for (int i = 0; i < r.keys.Count; i++)
                        {
                            bw.Write(stringTable[r.keys[i]]);
                            bw.Write(stringTable[r.values[i]]);
                        }
                        bw.Write(r.roleValues.Count);
                        foreach (var roleValue in r.roleValues)
                        {
                            bw.Write(stringTable[roleValue]);
                        }
                        bw.Write(r.memids.Count);
                        foreach (var memid in r.memids)
                        {
                            bw.Write(memid);
                        }
                        bw.Write(r.types.Count);
                        foreach (var type in r.types)
                        {
                            bw.Write(type);
                        }
                    }
                }
            }
        }
예제 #6
0
        private void SaveAsImage(OSMMetaManager manager, CubeSector frRoot)
        {
            // finally, render those coast images
            string mapFile = OSMPaths.GetCoastlineImagePath(frRoot);
            Bitmap map     = new Bitmap(256, 256);

            for (int i = 0; i < 256; i++)
            {
                for (int j = 0; j < 256; j++)
                {
                    int land1 = gridPoints[frRoot][i, j].naturalTypes.Contains(0) ? 0 : -1;
                    int land2 = gridPoints[frRoot][i + 1, j].naturalTypes.Contains(0) ? 0 : -1;
                    int land3 = gridPoints[frRoot][i, j + 1].naturalTypes.Contains(0) ? 0 : -1;
                    int land4 = gridPoints[frRoot][i + 1, j + 1].naturalTypes.Contains(0) ? 0 : -1;
                    if (gridPoints[frRoot][i, j].relations.Any(x => manager.relationInfo[x].ContainsKeyValue(manager, "natural", "water")))
                    {
                        land1 = 1;
                    }
                    if (gridPoints[frRoot][i, j].ways.Any(x => manager.wayInfo[x].ContainsKeyValue(manager, "natural", "water")))
                    {
                        land1 = 1;
                    }
                    if (gridPoints[frRoot][i + 1, j].relations.Any(x => manager.relationInfo[x].ContainsKeyValue(manager, "natural", "water")))
                    {
                        land2 = 1;
                    }
                    if (gridPoints[frRoot][i + 1, j].ways.Any(x => manager.wayInfo[x].ContainsKeyValue(manager, "natural", "water")))
                    {
                        land2 = 1;
                    }
                    if (gridPoints[frRoot][i, j + 1].relations.Any(x => manager.relationInfo[x].ContainsKeyValue(manager, "natural", "water")))
                    {
                        land3 = 1;
                    }
                    if (gridPoints[frRoot][i, j + 1].ways.Any(x => manager.wayInfo[x].ContainsKeyValue(manager, "natural", "water")))
                    {
                        land3 = 1;
                    }
                    if (gridPoints[frRoot][i + 1, j + 1].relations.Any(x => manager.relationInfo[x].ContainsKeyValue(manager, "natural", "water")))
                    {
                        land4 = 1;
                    }
                    if (gridPoints[frRoot][i + 1, j + 1].ways.Any(x => manager.wayInfo[x].ContainsKeyValue(manager, "natural", "water")))
                    {
                        land4 = 1;
                    }
                    if (gridPoints[frRoot][i, j].relations.Any(x => manager.relationInfo[x].ContainsKeyValue(manager, "natural", "glacier")))
                    {
                        land1 = 2;
                    }
                    if (gridPoints[frRoot][i, j].ways.Any(x => manager.wayInfo[x].ContainsKeyValue(manager, "natural", "glacier")))
                    {
                        land1 = 2;
                    }
                    if (gridPoints[frRoot][i + 1, j].relations.Any(x => manager.relationInfo[x].ContainsKeyValue(manager, "natural", "glacier")))
                    {
                        land2 = 2;
                    }
                    if (gridPoints[frRoot][i + 1, j].ways.Any(x => manager.wayInfo[x].ContainsKeyValue(manager, "natural", "glacier")))
                    {
                        land2 = 2;
                    }
                    if (gridPoints[frRoot][i, j + 1].relations.Any(x => manager.relationInfo[x].ContainsKeyValue(manager, "natural", "glacier")))
                    {
                        land3 = 2;
                    }
                    if (gridPoints[frRoot][i, j + 1].ways.Any(x => manager.wayInfo[x].ContainsKeyValue(manager, "natural", "glacier")))
                    {
                        land3 = 2;
                    }
                    if (gridPoints[frRoot][i + 1, j + 1].relations.Any(x => manager.relationInfo[x].ContainsKeyValue(manager, "natural", "glacier")))
                    {
                        land4 = 2;
                    }
                    if (gridPoints[frRoot][i + 1, j + 1].ways.Any(x => manager.wayInfo[x].ContainsKeyValue(manager, "natural", "glacier")))
                    {
                        land4 = 2;
                    }
                    Color color = Color.FromArgb(128, 128, 128);

                    if (land1 == 2 && land2 == 2 && land3 == 2 && land4 == 2)
                    {
                        color = Color.FromArgb(255, 255, 255);
                    }
                    if (land1 == 1 && land2 == 1 && land3 == 1 && land4 == 1)
                    {
                        color = Color.FromArgb(0, 0, 255);
                    }
                    if (land1 == 0 && land2 == 0 && land3 == 0 && land4 == 0)
                    {
                        color = Color.FromArgb(0, 255, 0);
                    }
                    if (land1 == -1 && land2 == -1 && land3 == -1 && land4 == -1)
                    {
                        color = Color.FromArgb(0, 0, 255);
                    }

                    //color = Color.FromArgb(255, 255, 255);
                    //if (gridTops[frRoot][i, j].relations.Any(x => x == 1279614)) color = Color.FromArgb(0, 255, 0);
                    //if (gridLefts[frRoot][i, j].relations.Any(x => x == 1279614)) color = Color.FromArgb(255, 0, 0);
                    //if (gridLefts[frRoot][i, j].relations.Any(x => x == 1279614) && gridTops[frRoot][i, j].relations.Any(x => x == 1279614)) color = Color.FromArgb(0, 0, 0);

                    map.SetPixel(i, j, color);
                }
            }
            map.Save(mapFile, ImageFormat.Png);
        }