itinero / OpenLR

A C# Implementation of the OpenLR specification using Itinero.
https://www.itinero.tech
Other
18 stars 12 forks source link

NullReferenceException on OffsetPercentage #73

Closed emij closed 7 years ago

emij commented 7 years ago

https://github.com/itinero/OpenLR/blob/3b3908363be42a6fc07174e5c99fee59041dcf39/OpenLR/Referenced/Codecs/ReferencedLineCodec.cs#L172

What I could gather from the OpenLR specification the offset values are optional. I got an exception because the binary-encoded locations I tried to decode did not have these values, so I changed line 172 and 173 to:

lineLocation.PositiveOffsetPercentage = (location.PositiveOffsetPercentage == null) ? 0 : location.PositiveOffsetPercentage.Value; lineLocation.NegativeOffsetPercentage = (location.NegativeOffsetPercentage == null) ? 0 : location.PositiveOffsetPercentage.Value;

I also noticed this: https://github.com/itinero/OpenLR/blob/develop/samples/Samples.OSM/Program.cs#L64

should be: "decodedLine.toFeatures...", right?

xivk commented 7 years ago

Thanks again! 👍

xivk commented 7 years ago

Carefull if you are using the above code:

lineLocation.PositiveOffsetPercentage = (location.PositiveOffsetPercentage == null) ? 0 : location.PositiveOffsetPercentage.Value; lineLocation.NegativeOffsetPercentage = (location.NegativeOffsetPercentage == null) ? 0 : location.PositiveOffsetPercentage.Value;