Skip to content

If a way or relation has an id attribute, an "Attribute id already exists" exception will throws. #150

Description

@jetelain

Steps to reproduce:

Extract OSM data that contains way 4745698 (many other ways have the same issue, it's just an example):

  <way id="4745698">
    ...
    <tag k="area_ha" v="35.7400213134766"/>
    <tag k="farm_name" v="NA"/>
    <tag k="id" v="652"/>
    <tag k="is_in" v="Falkland Islands"/>
    <tag k="latitude" v="-51.307763637"/>
    <tag k="loc_name" v="Rabbit Island (Pebble)"/>
    <tag k="longitude" v="-59.726512313"/>
    <tag k="name" v="Rabbit Island"/>
    <tag k="natural" v="coastline"/>
    <tag k="notes" v="None"/>
    <tag k="oid" v="165.0"/>
    <tag k="place" v="islet"/>
    <tag k="source" v="smallislandsownership"/>
    <tag k="wider_area" v="Pebble Island"/>
  </way>

Read the resulting data with OsmSharp, and use the DefaultFeatureInterpreter to interpret the way.

An exception "Attribute id already exists!" will throws.

System.ArgumentException: Attribute id already exists!
   at NetTopologySuite.Features.AttributesTable.Add(String attributeName, Object attributeValue)
   at OsmSharp.Geo.DefaultFeatureInterpreter.TagsAndIdToAttributes(ICompleteOsmGeo osmObject)
   at OsmSharp.Geo.DefaultFeatureInterpreter.Interpret(ICompleteOsmGeo osmObject)
   at OsmSharp.Geo.FeatureInterpreter.Interpret(OsmGeo osmGeo, ISnapshotDb data)

I dont known the best way to handle this case.

  • I think the best option it to ignore the id tag from the way, and only keep the way id to be backward compatible. The id tag might be shifted to an other name, to be still accessible.
  • An other option would be to change how the id is transformed to tag with a reserved name that would not collide such as $id but this will broke all existing users of DefaultFeatureInterpreter.

Activity

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Metadata

Metadata

Assignees

No one assigned

    Labels

    No labels
    No labels

    Type

    No type

    Projects

    No projects

      Milestone

      No milestone

      Relationships

      None yet

      Development

      No branches or pull requests

      Issue actions