예제 #1
0
        /// <summary>
        /// Interprets an OSM-object and returns the corresponding geometry.
        /// </summary>
        public override FeatureCollection Interpret(ICompleteOsmGeo osmObject)
        {
            // DISCLAIMER: this is a very very very simple geometry interpreter and
            // contains hardcoded all relevant tags.

            var collection = new FeatureCollection();

            if (osmObject == null)
            {
                return(collection);
            }

            TagsCollectionBase tags;

            switch (osmObject.Type)
            {
            case OsmGeoType.Node:
                var newCollection = new TagsCollection(
                    osmObject.Tags);
                newCollection.RemoveKey("FIXME");
                newCollection.RemoveKey("node");
                newCollection.RemoveKey("source");

                if (newCollection.Count > 0)
                {     // there is still some relevant information left.
                    collection.Add(new Feature(new Point((osmObject as Node).GetCoordinate()),
                                               TagsAndIdToAttributes(osmObject)));
                }
                break;

            case OsmGeoType.Way:
                tags = osmObject.Tags;

                if (tags == null)
                {
                    return(collection);
                }

                bool isArea = false;
                if ((tags.ContainsKey("building") && !tags.IsFalse("building")) ||
                    (tags.ContainsKey("landuse") && !tags.IsFalse("landuse")) ||
                    (tags.ContainsKey("amenity") && !tags.IsFalse("amenity")) ||
                    (tags.ContainsKey("harbour") && !tags.IsFalse("harbour")) ||
                    (tags.ContainsKey("historic") && !tags.IsFalse("historic")) ||
                    (tags.ContainsKey("leisure") && !tags.IsFalse("leisure")) ||
                    (tags.ContainsKey("man_made") && !tags.IsFalse("man_made")) ||
                    (tags.ContainsKey("military") && !tags.IsFalse("military")) ||
                    (tags.ContainsKey("natural") && !tags.IsFalse("natural")) ||
                    (tags.ContainsKey("office") && !tags.IsFalse("office")) ||
                    (tags.ContainsKey("place") && !tags.IsFalse("place")) ||
                    (tags.ContainsKey("public_transport") && !tags.IsFalse("public_transport")) ||
                    (tags.ContainsKey("shop") && !tags.IsFalse("shop")) ||
                    (tags.ContainsKey("sport") && !tags.IsFalse("sport")) ||
                    (tags.ContainsKey("tourism") && !tags.IsFalse("tourism")) ||
                    (tags.ContainsKey("waterway") && !tags.IsFalse("waterway")) ||
                    (tags.ContainsKey("wetland") && !tags.IsFalse("wetland")) ||
                    (tags.ContainsKey("water") && !tags.IsFalse("water")) ||
                    (tags.ContainsKey("aeroway") && !tags.IsFalse("aeroway")))
                {     // these tags usually indicate an area.
                    isArea = true;
                }

                if (tags.IsTrue("area"))
                {     // explicitly indicated that this is an area.
                    isArea = true;
                }
                else if (tags.IsFalse("area"))
                {     // explicitly indicated that this is not an area.
                    isArea = false;
                }

                // check for a closed line if area.
                var coordinates = (osmObject as CompleteWay).GetCoordinates();
                if (isArea && coordinates.Count > 1 &&
                    !coordinates[0].Equals2D(coordinates[coordinates.Count - 1]))
                {     // not an area, first and last coordinate do not match.
                    Logger.Log("DefaultFeatureInterpreter", TraceEventType.Warning, "{0} is supposed to be an area but first and last coordinates do not match.",
                               osmObject.ToInvariantString());
                }
                else if (!isArea && coordinates.Count < 2)
                {     // not a linestring, needs at least two coordinates.
                    Logger.Log("DefaultFeatureInterpreter", TraceEventType.Warning, "{0} is supposed to be a linestring but has less than two coordinates.",
                               osmObject.ToInvariantString());
                }
                else if (isArea && coordinates.Count < 4)
                {    // not a linearring, needs at least four coordinates, with first and last identical.
                    Logger.Log("DefaultFeatureInterpreter", TraceEventType.Warning, "{0} is supposed to be a linearring but has less than four coordinates.",
                               osmObject.ToInvariantString());
                }
                else
                {
                    if (isArea)
                    {     // area tags leads to simple polygon
                        var lineairRing = new Feature(new LinearRing(coordinates.
                                                                     ToArray <Coordinate>()), TagsAndIdToAttributes(osmObject));
                        collection.Add(lineairRing);
                    }
                    else
                    {     // no area tag leads to just a line.
                        var lineString = new Feature(new LineString(coordinates.
                                                                    ToArray <Coordinate>()), TagsAndIdToAttributes(osmObject));
                        collection.Add(lineString);
                    }
                }
                break;

            case OsmGeoType.Relation:
                var relation = (osmObject as CompleteRelation);
                tags = relation.Tags;

                if (tags == null)
                {
                    return(collection);
                }

                if (tags.TryGetValue("type", out var typeValue))
                {     // there is a type in this relation.
                    if (typeValue == "multipolygon" || typeValue == "linearring")
                    { // this relation is a multipolygon.
                        var feature = this.InterpretMultipolygonRelation(relation);
                        if (feature != null)
                        {     // add the geometry.
                            collection.Add(feature);
                        }
                    }
                    else if (typeValue == "boundary" && tags.Contains("boundary", "administrative"))
                    {     // this relation is a boundary.
                        var feature = this.InterpretMultipolygonRelation(relation);
                        if (feature != null)
                        {     // add the geometry.
                            collection.Add(feature);
                        }
                    }
                }
                break;

            default:
                throw new ArgumentOutOfRangeException();
            }
            return(collection);
        }
예제 #2
0
        public override FeatureCollection Interpret(ICompleteOsmGeo osmObject)
        {
            FeatureCollection featureCollection = new FeatureCollection();

            if (osmObject != null)
            {
                switch (osmObject.Type)
                {
                case CompleteOsmType.Node:
                    TagsCollection tagsCollection = new TagsCollection((IEnumerable <Tag>)osmObject.Tags);
                    string         key1           = "FIXME";
                    tagsCollection.RemoveKey(key1);
                    string key2 = "node";
                    tagsCollection.RemoveKey(key2);
                    string key3 = "source";
                    tagsCollection.RemoveKey(key3);
                    if (tagsCollection.Count > 0)
                    {
                        featureCollection.Add(new Feature((Geometry) new Point((osmObject as Node).Coordinate), (GeometryAttributeCollection) new SimpleGeometryAttributeCollection((IEnumerable <Tag>)osmObject.Tags)));
                        break;
                    }
                    break;

                case CompleteOsmType.Way:
                    TagsCollectionBase tags = osmObject.Tags;
                    bool flag = false;
                    if (tags.ContainsKey("building") && !tags.IsFalse("building") || tags.ContainsKey("landuse") && !tags.IsFalse("landuse") || (tags.ContainsKey("amenity") && !tags.IsFalse("amenity") || tags.ContainsKey("harbour") && !tags.IsFalse("harbour")) || (tags.ContainsKey("historic") && !tags.IsFalse("historic") || tags.ContainsKey("leisure") && !tags.IsFalse("leisure") || (tags.ContainsKey("man_made") && !tags.IsFalse("man_made") || tags.ContainsKey("military") && !tags.IsFalse("military"))) || (tags.ContainsKey("natural") && !tags.IsFalse("natural") || tags.ContainsKey("office") && !tags.IsFalse("office") || (tags.ContainsKey("place") && !tags.IsFalse("place") || tags.ContainsKey("power") && !tags.IsFalse("power")) || (tags.ContainsKey("public_transport") && !tags.IsFalse("public_transport") || tags.ContainsKey("shop") && !tags.IsFalse("shop") || (tags.ContainsKey("sport") && !tags.IsFalse("sport") || tags.ContainsKey("tourism") && !tags.IsFalse("tourism")))) || (tags.ContainsKey("waterway") && !tags.IsFalse("waterway") || tags.ContainsKey("wetland") && !tags.IsFalse("wetland") || (tags.ContainsKey("water") && !tags.IsFalse("water") || tags.ContainsKey("aeroway") && !tags.IsFalse("aeroway"))))
                    {
                        flag = true;
                    }
                    if (tags.IsTrue("area"))
                    {
                        flag = true;
                    }
                    else if (tags.IsFalse("area"))
                    {
                        flag = false;
                    }
                    if (flag)
                    {
                        Feature feature = new Feature((Geometry) new LineairRing((osmObject as CompleteWay).GetCoordinates().ToArray <GeoCoordinate>()), (GeometryAttributeCollection) new SimpleGeometryAttributeCollection((IEnumerable <Tag>)tags));
                        featureCollection.Add(feature);
                        break;
                    }
                    Feature feature1 = new Feature((Geometry) new LineString((osmObject as CompleteWay).GetCoordinates().ToArray <GeoCoordinate>()), (GeometryAttributeCollection) new SimpleGeometryAttributeCollection((IEnumerable <Tag>)tags));
                    featureCollection.Add(feature1);
                    break;

                case CompleteOsmType.Relation:
                    CompleteRelation relation = osmObject as CompleteRelation;
                    string           str;
                    if (relation.Tags.TryGetValue("type", out str))
                    {
                        if (str == "multipolygon")
                        {
                            Feature feature2 = this.InterpretMultipolygonRelation(relation);
                            if (feature2 != null)
                            {
                                featureCollection.Add(feature2);
                                break;
                            }
                            break;
                        }
                        int num = str == "boundary" ? 1 : 0;
                        break;
                    }
                    break;
                }
            }
            return(featureCollection);
        }
        /// <summary>
        /// Interprets an OSM-object and returns the corresponding geometry.
        /// </summary>
        /// <param name="osmObject"></param>
        /// <returns></returns>
        public override GeometryCollection Interpret(CompleteOsmGeo osmObject)
        {
            // DISCLAIMER: this is a very very very simple geometry interpreter and
            // contains hardcoded all relevant tags.

            GeometryCollection collection = new GeometryCollection();
            TagsCollectionBase tags;

            if (osmObject != null)
            {
                switch (osmObject.Type)
                {
                case CompleteOsmType.Node:
                    TagsCollection newCollection = new TagsCollection(
                        osmObject.Tags);
                    newCollection.RemoveKey("FIXME");
                    newCollection.RemoveKey("node");
                    newCollection.RemoveKey("source");

                    if (newCollection.Count > 0)
                    {     // there is still some relevant information left.
                        collection.Add(new Point((osmObject as CompleteNode).Coordinate));
                    }
                    break;

                case CompleteOsmType.Way:
                    tags = osmObject.Tags;

                    bool isArea = false;
                    if ((tags.ContainsKey("building") && !tags.IsFalse("building")) ||
                        (tags.ContainsKey("landuse") && !tags.IsFalse("landuse")) ||
                        (tags.ContainsKey("amenity") && !tags.IsFalse("amenity")) ||
                        (tags.ContainsKey("harbour") && !tags.IsFalse("harbour")) ||
                        (tags.ContainsKey("historic") && !tags.IsFalse("historic")) ||
                        (tags.ContainsKey("leisure") && !tags.IsFalse("leisure")) ||
                        (tags.ContainsKey("man_made") && !tags.IsFalse("man_made")) ||
                        (tags.ContainsKey("military") && !tags.IsFalse("military")) ||
                        (tags.ContainsKey("natural") && !tags.IsFalse("natural")) ||
                        (tags.ContainsKey("office") && !tags.IsFalse("office")) ||
                        (tags.ContainsKey("place") && !tags.IsFalse("place")) ||
                        (tags.ContainsKey("power") && !tags.IsFalse("power")) ||
                        (tags.ContainsKey("public_transport") && !tags.IsFalse("public_transport")) ||
                        (tags.ContainsKey("shop") && !tags.IsFalse("shop")) ||
                        (tags.ContainsKey("sport") && !tags.IsFalse("sport")) ||
                        (tags.ContainsKey("tourism") && !tags.IsFalse("tourism")) ||
                        (tags.ContainsKey("waterway") && !tags.IsFalse("waterway")) ||
                        (tags.ContainsKey("wetland") && !tags.IsFalse("wetland")) ||
                        (tags.ContainsKey("water") && !tags.IsFalse("water")) ||
                        (tags.ContainsKey("aeroway") && !tags.IsFalse("aeroway")))
                    {     // these tags usually indicate an area.
                        isArea = true;
                    }

                    if (tags.IsTrue("area"))
                    {     // explicitly indicated that this is an area.
                        isArea = true;
                    }
                    else if (tags.IsFalse("area"))
                    {     // explicitly indicated that this is not an area.
                        isArea = false;
                    }

                    if (isArea)
                    {     // area tags leads to simple polygon
                        LineairRing lineairRing = new LineairRing((osmObject as CompleteWay).GetCoordinates().ToArray <GeoCoordinate>());
                        lineairRing.Attributes = new SimpleGeometryAttributeCollection(tags);
                        collection.Add(lineairRing);
                    }
                    else
                    {     // no area tag leads to just a line.
                        LineString lineString = new LineString((osmObject as CompleteWay).GetCoordinates().ToArray <GeoCoordinate>());
                        lineString.Attributes = new SimpleGeometryAttributeCollection(tags);
                        collection.Add(lineString);
                    }
                    break;

                case CompleteOsmType.Relation:
                    CompleteRelation relation = (osmObject as CompleteRelation);
                    tags = relation.Tags;

                    string typeValue;
                    if (tags.TryGetValue("type", out typeValue))
                    {     // there is a type in this relation.
                        if (typeValue == "multipolygon")
                        { // this relation is a multipolygon.
                            Geometry geometry = this.InterpretMultipolygonRelation(relation);
                            if (geometry != null)
                            {     // add the geometry.
                                collection.Add(geometry);
                            }
                        }
                        else if (typeValue == "boundary")
                        {     // this relation is a boundary.
                        }
                    }
                    break;
                }
            }
            return(collection);
        }
예제 #4
0
        /// <summary>
        /// Interprets an OSM-object and returns the corresponding geometry. Returns null on a failure.
        /// </summary>
        public Geometry Interpret(ICompleteOsmGeo osmObject)
        {
            // DISCLAIMER: this is a very very very simple geometry interpreter and
            // contains hardcoded all relevant tags.
            if (osmObject == null)
            {
                return(null);
            }

            switch (osmObject.Type)
            {
            case OsmGeoType.Node:
                var newCollection = new TagsCollection(
                    osmObject.Tags);
                newCollection.RemoveKey("FIXME");
                newCollection.RemoveKey("node");
                newCollection.RemoveKey("source");

                if (newCollection.Count > 0)
                {     // there is still some relevant information left.
                    return(new Point((osmObject as OsmSharp.Node).GetCoordinate()));
                }
                break;

            case OsmGeoType.Way:
                if (osmObject.Tags == null || osmObject.Tags.Count == 0)
                {
                    return(null);
                }

                bool isArea = false;
                // check for a closed line if area.
                var coordinates = (osmObject as CompleteWay).GetCoordinates();
                if (coordinates.Count > 1 && coordinates[0].Equals2D(coordinates[coordinates.Count - 1]))
                {                                                // This might be an area, or just a line that ends where it starts. Look at tags to decide.
                    if (osmObject.Tags.ContainsAnyKey(areaTags)) //These tags normally default to an area regardless of the value provided.
                    {
                        isArea = true;
                    }
                    string areaVal = "";
                    if (osmObject.Tags.TryGetValue("area", out areaVal))
                    {     // explicitly indicated that this is or isn't an area.
                        isArea = areaVal == "true";
                    }
                }

                if (!isArea && coordinates.Count < 2)
                {     // not a linestring, needs at least two coordinates.
                }
                else if (isArea && coordinates.Count < 4)
                {    // not a linearring, needs at least four coordinates, with first and last identical.
                }
                else
                {
                    if (isArea)
                    {     // area tags leads to simple polygon
                        return(new LinearRing(coordinates.ToArray()));
                    }
                    else
                    {     // no area tag leads to just a line.
                        return(new LineString(coordinates.ToArray()));
                    }
                }
                break;

            case OsmGeoType.Relation:
                var relation = (osmObject as CompleteRelation);
                if (relation.Tags == null || relation.Tags.Count == 0)
                {
                    return(null);
                }

                if (relation.Tags.TryGetValue("type", out var typeValue))
                {     // there is a type in this relation.
                    if (typeValue == "multipolygon" || typeValue == "linearring")
                    { // this relation is a multipolygon.
                        return(InterpretMultipolygonRelationNoRecursion(relation));
                    }
                    else if (typeValue == "boundary" && relation.Tags.Contains("boundary", "administrative"))
                    {     // this relation is a boundary.
                        return(InterpretMultipolygonRelationNoRecursion(relation));
                    }
                }
                break;

            default:
                throw new ArgumentOutOfRangeException();
            }
            return(null);
        }