Esempio n. 1
0
        private OSMWay CreateBuilding(int index, Building building)
        {
            OSMWay           returnWay     = null;
            List <OSMWayND>  buildingPaths = new List <OSMWayND>();
            List <OSMWayTag> buildingTags  = new List <OSMWayTag>();

            if (Tagger.CreateBuildingTags(building, out buildingTags))
            {
                int     buildingWidth  = building.Width;
                int     BuildingLength = building.Length;
                Vector3 buildingCentre = building.m_position;
                Vector3 directionRight = new Vector3(Mathf.Cos(building.m_angle), 0f, Mathf.Sin(building.m_angle)) * 8f;
                Vector3 directionUp    = new Vector3(directionRight.z, 0f, -directionRight.x);

                cityCentre += buildingCentre; //Gets averaged out later, for finding centre of city based on buildings

                osmNodes.Add(CreateNode(unindexedNodeOffset++, buildingCentre - (((float)buildingWidth / 2f) * directionRight) - (((float)BuildingLength / 2f) * directionUp)));
                osmNodes.Add(CreateNode(unindexedNodeOffset++, buildingCentre + (((float)buildingWidth / 2f) * directionRight) - (((float)BuildingLength / 2f) * directionUp)));
                osmNodes.Add(CreateNode(unindexedNodeOffset++, buildingCentre + (((float)buildingWidth / 2f) * directionRight) + (((float)BuildingLength / 2f) * directionUp)));
                osmNodes.Add(CreateNode(unindexedNodeOffset++, buildingCentre - (((float)buildingWidth / 2f) * directionRight) + (((float)BuildingLength / 2f) * directionUp)));

                buildingPaths.Add(new OSMWayND {
                    @ref = (uint)unindexedNodeOffset - 4
                });
                buildingPaths.Add(new OSMWayND {
                    @ref = (uint)unindexedNodeOffset - 3
                });
                buildingPaths.Add(new OSMWayND {
                    @ref = (uint)unindexedNodeOffset - 2
                });
                buildingPaths.Add(new OSMWayND {
                    @ref = (uint)unindexedNodeOffset - 1
                });
                buildingPaths.Add(new OSMWayND {
                    @ref = (uint)unindexedNodeOffset - 4
                });                                                                       //Need to connect back to the first point

                returnWay = new OSMWay {
                    changeset = 50000000, id = (uint)index, timestamp = DateTime.Now, user = "******", nd = buildingPaths.ToArray(), tag = buildingTags.ToArray(), version = 1
                };
            }

            return(returnWay);
        }
Esempio n. 2
0
        private void ExportBuildings()
        {
            BuildingManager buildingManager = Singleton <BuildingManager> .instance;

            Building[] buildings = buildingManager.m_buildings.m_buffer;

            foreach (Building building in buildings)
            {
                Building.Flags buildingFlags = building.m_flags;

                if (buildingFlags.IsFlagSet(Building.Flags.Created))
                {
                    OSMWay generatedBuilding = CreateBuilding(unindexedWayOffset++, building);

                    if (generatedBuilding != null)
                    {
                        osmWays.Add(generatedBuilding);
                    }
                }
            }
        }
Esempio n. 3
0
        private void ExportWays()
        {
            NetManager netManager = Singleton <NetManager> .instance;

            NetSegment[] netSegments = netManager.m_segments.m_buffer;
            for (int segmentId = 0; segmentId < netSegments.Length; segmentId++)
            {
                NetSegment       netSegment   = netSegments[segmentId];
                NetSegment.Flags segmentFlags = netSegment.m_flags;

                if (segmentFlags.IsFlagSet(NetSegment.Flags.Created))
                {
                    OSMWay generatedWay = CreateWay(unindexedWayOffset++, netSegment, (ushort)segmentId);

                    if (generatedWay != null)
                    {
                        osmWays.Add(generatedWay);
                    }
                }
            }
        }
Esempio n. 4
0
        private OSMWay CreateBuilding(int index, Building building)
        {
            OSMWay returnWay = null;
            List<OSMWayND> buildingPaths = new List<OSMWayND>();
            List<OSMWayTag> buildingTags = new List<OSMWayTag>();

            if (Tagger.CreateBuildingTags(building, out buildingTags))
            {
                int buildingWidth = building.Width;
                int BuildingLength = building.Length;
                Vector3 buildingCentre = building.m_position;
                Vector3 directionRight = new Vector3(Mathf.Cos(building.m_angle), 0f, Mathf.Sin(building.m_angle)) * 8f;
                Vector3 directionUp = new Vector3(directionRight.z, 0f, -directionRight.x);

                cityCentre += buildingCentre; //Gets averaged out later, for finding centre of city based on buildings

                osmNodes.Add(CreateNode(unindexedNodeOffset++, buildingCentre - (((float)buildingWidth / 2f) * directionRight) - (((float)BuildingLength / 2f) * directionUp)));
                osmNodes.Add(CreateNode(unindexedNodeOffset++, buildingCentre + (((float)buildingWidth / 2f) * directionRight) - (((float)BuildingLength / 2f) * directionUp)));
                osmNodes.Add(CreateNode(unindexedNodeOffset++, buildingCentre + (((float)buildingWidth / 2f) * directionRight) + (((float)BuildingLength / 2f) * directionUp)));
                osmNodes.Add(CreateNode(unindexedNodeOffset++, buildingCentre - (((float)buildingWidth / 2f) * directionRight) + (((float)BuildingLength / 2f) * directionUp)));

                buildingPaths.Add(new OSMWayND { @ref = (uint)unindexedNodeOffset - 4 });
                buildingPaths.Add(new OSMWayND { @ref = (uint)unindexedNodeOffset - 3 });
                buildingPaths.Add(new OSMWayND { @ref = (uint)unindexedNodeOffset - 2 });
                buildingPaths.Add(new OSMWayND { @ref = (uint)unindexedNodeOffset - 1 });
                buildingPaths.Add(new OSMWayND { @ref = (uint)unindexedNodeOffset - 4 }); //Need to connect back to the first point

                returnWay = new OSMWay { changeset = 50000000, id = (uint)index, timestamp = DateTime.Now, user = "******", nd = buildingPaths.ToArray(), tag = buildingTags.ToArray(), version = 1 };
            }

            return returnWay;
        }
Esempio n. 5
0
        private OSMWay CreateWay(int index, NetSegment segment, ushort segmentId)
        {
            OSMWay returnWay = null;
            NetSegment.Flags segmentFlags = segment.m_flags;
            NetManager netManager = Singleton<NetManager>.instance;
            List<OSMWayND> wayPaths = new List<OSMWayND>();
            List<OSMWayTag> wayTags;
            ushort startNodeId = segment.m_startNode, endNodeId = segment.m_endNode;

            if(startNodeId != 0 && endNodeId != 0)
            {
                Vector3 startNodeDirection = segment.m_startDirection;
                Vector3 endNodeDirection = segment.m_endDirection;

                if(segmentFlags.IsFlagSet(NetSegment.Flags.Invert))
                {
                    startNodeId = segment.m_endNode;
                    endNodeId = segment.m_startNode;
                    startNodeDirection = segment.m_endDirection;
                    endNodeDirection = segment.m_startDirection;
                }

                NetNode startNode = netManager.m_nodes.m_buffer[startNodeId];
                NetNode endNode = netManager.m_nodes.m_buffer[endNodeId];
                Vector3 startNodePosition = startNode.m_position;
                Vector3 endNodePosition = endNode.m_position;

                wayPaths.Add(new OSMWayND { @ref = startNodeId });

                if (Vector3.Angle(startNodeDirection, -endNodeDirection) > 3f)
                {
                    Vector3 midPointA = Vector3.zero, midPointB = Vector3.zero;
                    NetSegment.CalculateMiddlePoints(startNodePosition, startNodeDirection, endNodePosition, endNodeDirection, false, false, out midPointA, out midPointB);
                    Bezier3 bezier = new Bezier3(startNodePosition, midPointA, midPointB, endNodePosition);

                    osmNodes.Add(CreateNode(unindexedNodeOffset++, bezier.Position(0.25f)));
                    osmNodes.Add(CreateNode(unindexedNodeOffset++, bezier.Position(0.5f)));
                    osmNodes.Add(CreateNode(unindexedNodeOffset++, bezier.Position(0.75f)));

                    wayPaths.Add(new OSMWayND { @ref = (uint)unindexedNodeOffset - 3 });
                    wayPaths.Add(new OSMWayND { @ref = (uint)unindexedNodeOffset - 2 });
                    wayPaths.Add(new OSMWayND { @ref = (uint)unindexedNodeOffset - 1 });
                }

                wayPaths.Add(new OSMWayND { @ref = endNodeId });

                if(Tagger.CreateWayTags(segment, out wayTags))
                {
                    if (haveRoadNamerMod)
                    {
                        // If road namer mod is available, then attempt to get the name asscociated with the segment, if any
                        string roadName = RoadNamerManager.Instance().getSegmentName((ushort)(segmentId));
                        if (roadName != null)
                        {
                            //If a name is available, add a name tag
                            wayTags.Add(new OSMWayTag { k = "name", v = StringUtilities.RemoveTags(roadName) });
                        }
                    }
                    returnWay = new OSMWay { changeset = 50000000, id = (uint)index, timestamp = DateTime.Now, user = "******", nd = wayPaths.ToArray(), tag = wayTags.ToArray(), version = 1 };
                }
                else
                {
                    UniqueLogger.AddLog("Road names missing from search", segment.Info.name, "");
                }
            }

            return returnWay;
        }
Esempio n. 6
0
        private OSMWay CreateWay(int index, NetSegment segment)
        {
            OSMWay returnWay = null;
            NetSegment.Flags segmentFlags = segment.m_flags;
            NetManager netManager = Singleton<NetManager>.instance;
            List<OSMWayND> wayPaths = new List<OSMWayND>();
            List<OSMWayTag> wayTags;
            ushort startNodeId = segment.m_startNode, endNodeId = segment.m_endNode;

            if(startNodeId != 0 && endNodeId != 0)
            {
                Vector3 startNodeDirection = segment.m_startDirection;
                Vector3 endNodeDirection = segment.m_endDirection;

                if(segmentFlags.IsFlagSet(NetSegment.Flags.Invert))
                {
                    startNodeId = segment.m_endNode;
                    endNodeId = segment.m_startNode;
                    startNodeDirection = segment.m_endDirection;
                    endNodeDirection = segment.m_startDirection;
                }

                NetNode startNode = netManager.m_nodes.m_buffer[startNodeId];
                NetNode endNode = netManager.m_nodes.m_buffer[endNodeId];
                Vector3 startNodePosition = startNode.m_position;
                Vector3 endNodePosition = endNode.m_position;

                wayPaths.Add(new OSMWayND { @ref = startNodeId });

                if (Vector3.Angle(startNodeDirection, -endNodeDirection) > 3f)
                {
                    Vector3 midPointA = Vector3.zero, midPointB = Vector3.zero;
                    NetSegment.CalculateMiddlePoints(startNodePosition, startNodeDirection, endNodePosition, endNodeDirection, false, false, out midPointA, out midPointB);
                    Bezier3 bezier = new Bezier3(startNodePosition, midPointA, midPointB, endNodePosition);

                    osmNodes.Add(CreateNode(unindexedNodeOffset++, bezier.Position(0.25f)));
                    osmNodes.Add(CreateNode(unindexedNodeOffset++, bezier.Position(0.5f)));
                    osmNodes.Add(CreateNode(unindexedNodeOffset++, bezier.Position(0.75f)));

                    wayPaths.Add(new OSMWayND { @ref = (uint)unindexedNodeOffset - 3 });
                    wayPaths.Add(new OSMWayND { @ref = (uint)unindexedNodeOffset - 2 });
                    wayPaths.Add(new OSMWayND { @ref = (uint)unindexedNodeOffset - 1 });
                }

                wayPaths.Add(new OSMWayND { @ref = endNodeId });

                if(Tagger.CreateWayTags(segment, out wayTags))
                {
                    returnWay = new OSMWay { changeset = 50000000, id = (uint)index, timestamp = DateTime.Now, user = "******", nd = wayPaths.ToArray(), tag = wayTags.ToArray(), version = 1 };
                }
                else
                {
                    UniqueLogger.AddLog("Road names missing from search", segment.Info.name, "");
                }
            }

            return returnWay;
        }
Esempio n. 7
0
        private OSMWay CreateWay(int index, NetSegment segment, ushort segmentId)
        {
            OSMWay returnWay = null;

            NetSegment.Flags segmentFlags = segment.m_flags;
            NetManager       netManager   = Singleton <NetManager> .instance;
            List <OSMWayND>  wayPaths     = new List <OSMWayND>();
            List <OSMWayTag> wayTags;
            ushort           startNodeId = segment.m_startNode, endNodeId = segment.m_endNode;

            if (startNodeId != 0 && endNodeId != 0)
            {
                Vector3 startNodeDirection = segment.m_startDirection;
                Vector3 endNodeDirection   = segment.m_endDirection;

                if (segmentFlags.IsFlagSet(NetSegment.Flags.Invert))
                {
                    startNodeId        = segment.m_endNode;
                    endNodeId          = segment.m_startNode;
                    startNodeDirection = segment.m_endDirection;
                    endNodeDirection   = segment.m_startDirection;
                }

                NetNode startNode         = netManager.m_nodes.m_buffer[startNodeId];
                NetNode endNode           = netManager.m_nodes.m_buffer[endNodeId];
                Vector3 startNodePosition = startNode.m_position;
                Vector3 endNodePosition   = endNode.m_position;

                wayPaths.Add(new OSMWayND {
                    @ref = startNodeId
                });

                if (Vector3.Angle(startNodeDirection, -endNodeDirection) > 3f)
                {
                    Vector3 midPointA = Vector3.zero, midPointB = Vector3.zero;
                    NetSegment.CalculateMiddlePoints(startNodePosition, startNodeDirection, endNodePosition, endNodeDirection, false, false, out midPointA, out midPointB);
                    Bezier3 bezier = new Bezier3(startNodePosition, midPointA, midPointB, endNodePosition);

                    osmNodes.Add(CreateNode(unindexedNodeOffset++, bezier.Position(0.25f)));
                    osmNodes.Add(CreateNode(unindexedNodeOffset++, bezier.Position(0.5f)));
                    osmNodes.Add(CreateNode(unindexedNodeOffset++, bezier.Position(0.75f)));

                    wayPaths.Add(new OSMWayND {
                        @ref = (uint)unindexedNodeOffset - 3
                    });
                    wayPaths.Add(new OSMWayND {
                        @ref = (uint)unindexedNodeOffset - 2
                    });
                    wayPaths.Add(new OSMWayND {
                        @ref = (uint)unindexedNodeOffset - 1
                    });
                }

                wayPaths.Add(new OSMWayND {
                    @ref = endNodeId
                });

                if (Tagger.CreateWayTags(segment, out wayTags))
                {
                    if (haveRoadNamerMod)
                    {
                        // If road namer mod is available, then attempt to get the name asscociated with the segment, if any
                        string roadName = RoadNamerManager.Instance().getSegmentName((ushort)(segmentId));
                        if (roadName != null)
                        {
                            //If a name is available, add a name tag
                            wayTags.Add(new OSMWayTag {
                                k = "name", v = StringUtilities.RemoveTags(roadName)
                            });
                        }
                    }
                    returnWay = new OSMWay {
                        changeset = 50000000, id = (uint)index, timestamp = DateTime.Now, user = "******", nd = wayPaths.ToArray(), tag = wayTags.ToArray(), version = 1
                    };
                }
                else
                {
                    UniqueLogger.AddLog("Road names missing from search", segment.Info.name, "");
                }
            }

            return(returnWay);
        }
Esempio n. 8
0
        public bool Mapped(OSMWay way, ref List<uint> points, ref RoadTypes rt, ref int layer)
        {
            if (way.tag == null || way.nd == null || way.nd.Count() < 2)
            {
                return false;
            }
            rt = RoadTypes.None;
            bool oneWay = false;
            bool invert = false;
            var surface = "";

            foreach (var tag in way.tag)
            {
                if (tag.k.Trim().ToLower() == "oneway")
                {
                    oneWay = true;
                    if (tag.v.Trim() == "-1")
                    {
                        invert = true;
                    }
                }
                else if(tag.k.Trim().ToLower() =="bridge"){
                    layer = Math.Max(layer, 1);
                }
                else if (tag.k.Trim().ToLower() == "layer")
                {
                    int.TryParse(tag.v.Trim(), out layer);
                }
                else if (tag.k.Trim().ToLower() == "surface")
                {
                    surface = tag.v.Trim().ToLower();
                }
                else
                {
                    var kvp = new KeyValuePair<string, string>(tag.k.Trim(), tag.v.Trim());
                    if (roadTypeMapping.ContainsKey(kvp))
                    {
                        rt = roadTypeMapping[kvp];
                    }
                }
            }
            if (oneWay)
            {
                rt = GetOneway(rt);
            }

            if (rt != RoadTypes.None)
            {
                if (surface != "")
                {
                    rt = CheckSurface(rt, surface);
                }

                points = new List<uint>();
                if (invert)
                {
                    for (var i = way.nd.Count() - 1; i >= 0; i -=1 )
                    {
                        points.Add(way.nd[i].@ref);
                    }
                }
                else
                {
                    foreach (var nd in way.nd)
                    {
                        points.Add(nd.@ref);
                    }
                }
                return true;
            }
            return false;
        }