itinero / routing

The routing core of itinero.
Apache License 2.0
221 stars 70 forks source link

Question: add a custom tag to edge meta data #225

Closed alecava58 closed 5 years ago

alecava58 commented 5 years ago

I'm trying to add an edge meta data value but I get and exception "Collection is readonly". May be I make mistake, what is the right way to add a meta data value to one or more edges?

following my snippet:

        foreach (var vertex in GetVerticesByCircle(network, latitude[0], longitude[0], radius))
        {
            edgeEnumerator.MoveTo(vertex);
            while (edgeEnumerator.MoveNext())
            {
                var edgeData = edgeEnumerator.Data;
                var metaData = routerDb.EdgeMeta.Get(edgeData.MetaId);
                metaData.AddOrReplace("custom", "5000");
            }
        }
alecava58 commented 5 years ago

I solved creating a new AttributeCollection and add the new AttributeCollection to routerDb.EdgeMeta collection. Then I create a new EdgeData object and update the EdgeData. This way works but there are a lot of new EdgeMeta objects all with the same attributes collection. How I can reuse the EdgeMeta ids with the same attributes collection?

`

while (edgeEnumerator.MoveNext())
{
   var edge = routerDb.Network.GetEdge(edgeEnumerator.Id);
   var metaData = routerDb.EdgeMeta.Get(edge.Data.MetaId);

   IAttributeCollection newMetaData = new AttributeCollection();
   foreach (var a in metaData)
      newMetaData.AddOrReplace(a.Key, a.Value);
   newMetaData.AddOrReplace("custom", "5000");
   var newMetaId = routerDb.EdgeMeta.Add(newMetaData);
   var newEdgeData = new EdgeData { Distance = edge.Data.Distance, Profile = edge.Data.Profile, MetaId = newMetaId };
   routerDb.Network.UpdateEdgeData(edgeEnumerator.Id, newEdgeData);
}

`

alecava58 commented 5 years ago

Solved using EdgeProfiles collection.