Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

PBF StreamSource to FeatureSource - 'Attribute id already exists!' when creating Feature list #146

Open
digi-chris opened this issue Jan 27, 2023 · 3 comments

Comments

@digi-chris
Copy link

digi-chris commented Jan 27, 2023

Hi all, hoping someone can help with this. I have some basic code that loads a PBF file as a PBFOsmStreamSource, uses a FilterBox to reduce the size of the search area and then converts this to a FeatureSource:

FileStream fs = File.OpenRead(filename);
var source = new PBFOsmStreamSource(fs);
var s = source.FilterBox(x1, y2, x2, y1);
filtered = from osmGeo in s
                where osmGeo.Type == OsmSharp.OsmGeoType.Node ||
                osmGeo.Type == OsmSharp.OsmGeoType.Way
                select osmGeo;

features = filtered.ToFeatureSource();
var featureList = features.ToList();

On small areas (say, about 1km), this code works fine.. but as soon as I make the FilterBox area fairly large, the last line of this code causes an exception, stating:

'Attribute id already exists!'

Any idea why this is happening? Is there some way I can filter out duplicate attribute ids?

Thanks!

Chris.

@digi-chris
Copy link
Author

Just to add - this is the stack trace:

   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.Streams.Features.Interpreted.InterpretedFeatureStreamSource.MoveNext()
   at System.Linq.Enumerable.WhereEnumerableIterator`1.ToList()
   at System.Linq.Enumerable.ToList[TSource](IEnumerable`1 source)

Looking at what DefaultFeatureInterpreter.TagsAndIdToAttributes actually does, I'm wondering if there's something amiss with the PBF, with the specific area I'm looking at... but I don't know how to filter out the problem.

@digi-chris
Copy link
Author

OK, so I don't know if this helps, but in DefaultFeatureInterpreter.cs, line 523 and 524:

            var attr = osmObject.Tags.ToAttributeTable();
            attr.Add("id", osmObject.Id);

The osmObject.Tags attribute table already contains an Id, and on the next line it tries to add another, different, Id.

@digi-chris
Copy link
Author

Thought I would give an update on this - I was actually trying to draw in an incredibly large area - bigger than I'd realised.

I still think it should be possible, or at least the error should be trappable, but for my use-case I'd just miscalculated the size of the region, and once I got it down to what I actually wanted, the error didn't appear.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

No branches or pull requests

1 participant