예제 #1
0
        /// <summary>
        /// Returns true if the given object is of the given type.
        /// </summary>
        /// <param name="osmGeo"></param>
        /// <param name="types"></param>
        /// <returns></returns>
        public static bool IsOfType(this CompleteOsmGeo osmGeo, MapCSSTypes types)
        {
            string area = string.Empty;

            switch (types)
            {
            case MapCSSTypes.Node:
                return(osmGeo.Type == CompleteOsmType.Node);

            case MapCSSTypes.Way:
                return(osmGeo.Type == CompleteOsmType.Way);

            case MapCSSTypes.Relation:
                return(osmGeo.Type == CompleteOsmType.Relation);

            case MapCSSTypes.Line:
                if (osmGeo.Type == CompleteOsmType.Way)
                {     // the type is way way. now check for a line.
                    var way = (osmGeo as CompleteWay);
                    if (way != null &&
                        way.Nodes[0] == way.Nodes[way.Nodes.Count - 1])
                    {     // first node is the same as the last one.
                        if (way.Tags != null &&
                            way.Tags.TryGetValue("area", out area) &&
                            area == "yes")
                        {     // oeps, an area.
                            return(false);
                        }
                        return(true);
                    }
                    else
                    {                 // first node is different from the last one.
                        return(true); // even if there is an area=yes tag this cannot be an area.
                    }
                }
                break;

            case MapCSSTypes.Area:
                if (osmGeo.Type == CompleteOsmType.Way)
                {     // the type is way way. now check for a line.
                    var way = (osmGeo as CompleteWay);
                    if (way != null &&
                        way.Nodes != null &&
                        (way.Nodes.Count > 2 && (way.Nodes[0] == way.Nodes[way.Nodes.Count - 1])))
                    {     // first node is the same as the last one.
                        return(true);
                    }
                }
                return(false);

            default:
                throw new ArgumentOutOfRangeException("types");
            }
            return(false);
        }
예제 #2
0
파일: MapCSSTypes.cs 프로젝트: JoeCooper/ui
        /// <summary>
        /// Returns true if the given object is of the given type.
        /// </summary>
        /// <param name="osmGeo"></param>
        /// <param name="types"></param>
        /// <returns></returns>
        public static bool IsOfType(this CompleteOsmGeo osmGeo, MapCSSTypes types)
        {
            string area = string.Empty;
            switch (types)
            {
                case MapCSSTypes.Node:
                    return osmGeo.Type == CompleteOsmType.Node;
                case MapCSSTypes.Way:
                    return osmGeo.Type == CompleteOsmType.Way;
                case MapCSSTypes.Relation:
                    return osmGeo.Type == CompleteOsmType.Relation;
                case MapCSSTypes.Line:
                    if (osmGeo.Type == CompleteOsmType.Way)
                    { // the type is way way. now check for a line.
                        var way = (osmGeo as CompleteWay);
                        if (way != null &&
                            way.Nodes[0] == way.Nodes[way.Nodes.Count - 1])
                        { // first node is the same as the last one.
                            if (way.Tags != null &&
                                way.Tags.TryGetValue("area", out area) &&
                                area == "yes")
                            { // oeps, an area.
                                return false;
                            }
                            return true;
                        }
                        else
                        { // first node is different from the last one.
                            return true; // even if there is an area=yes tag this cannot be an area.
                        }
                    }
					break;
                case MapCSSTypes.Area:
                    if (osmGeo.Type == CompleteOsmType.Way)
                    { // the type is way way. now check for a line.
                        var way = (osmGeo as CompleteWay);
                        if (way != null &&
                            way.Nodes != null &&
                            (way.Nodes.Count > 2 && (way.Nodes[0] == way.Nodes[way.Nodes.Count - 1])))
                        { // first node is the same as the last one.
                            return true;
                        }
                    }
                    return false;
                default:
                    throw new ArgumentOutOfRangeException("types");
            }
            return false;
        }
예제 #3
0
        /// <summary>
        /// Returns true if the given object is of the given type.
        /// </summary>
        /// <param name="vtf"></param>
        /// <param name="types"></param>
        /// <returns></returns>
        public static bool IsOfType(this Feature vtf, MapCSSTypes types)
        {
            string area = string.Empty;

            switch (types)
            {
            case MapCSSTypes.Node:
                return(vtf.GeometryType == GeometryType.Point);

            case MapCSSTypes.Way:
                return(vtf.GeometryType == GeometryType.LineString);

            case MapCSSTypes.Relation:
            // TODO: We don't have such elements in databases
            // return vtf.GeometryType == CompleteOsmType.Relation;
            case MapCSSTypes.Line:
                if (vtf.GeometryType == GeometryType.LineString)
                {     // the type is way way. now check for a line.
                    var way = vtf.Geometry.First();
                    if (way != null &&
                        way.Points[0] == way.Points[way.Points.Count - 1])
                    {     // first node is the same as the last one.
                        if (vtf.Tags != null &&
                            vtf.Tags.TryGetValue("area", out area) &&
                            area == "yes")
                        {     // oeps, an area.
                            return(false);
                        }
                        return(true);
                    }
                    else
                    {                 // first node is different from the last one.
                        return(true); // even if there is an area=yes tag this cannot be an area.
                    }
                }
                break;

            case MapCSSTypes.Area:
                return(vtf.GeometryType == GeometryType.Polygon);

            default:
                throw new ArgumentOutOfRangeException("types");
            }
            return(false);
        }