Skip to content

Way geometry can have duplicate (pillar) nodes #1694

Open

Description

@easbar

I encountered some cases where the way geometry contained duplicate points (so basically 'loops' within the geometry of an edge). I could work around this somehow, but at the same time I am wondering whether or not this should even be allowed. Maybe make sure this does not happen during import already ?

Activity

  1. karussell commented on Aug 26, 2019

    @karussell
    Member

    Do you mean this is a bug or an OSM data problem and do you have an example? Is this related to #1353?

    Update: also related to #999

  2. easbar commented on Aug 26, 2019

    @easbar
    MemberAuthor

    Yes I think this is an OSM data problem and I was wondering if this should be considered a GH bug or if it is ok. Using berlin-140101.osm.pbf from Geofabrik: http://download.geofabrik.de/europe/germany/berlin-140101.osm.pbf and adding this code at the end of GraphHopper#importOrLoad:

    AllEdgesIterator iter = ghStorage.getAllEdges();
    int numWith2 = 0;
    int numWithMoreThan2 = 0;
    while (iter.next()) {
          if (iter.getBaseNode() == iter.getAdjNode()) {
             System.out.println("this is a loop");
          }
          PointList geometry = iter.fetchWayGeometry(3);
          for (int i = 1; i < geometry.size(); i++) {
              if (PointList.equalsEps(geometry.getLat(i-1), geometry.getLat(i)) && PointList.equalsEps(geometry.getLon(i-1), geometry.getLon(i))) {
              if (geometry.size() > 2) {
                    numWithMoreThan2++;
                    System.out.println(geometry);
               } else {
                    numWith2++;
               }
           }
      }
    }
    System.out.println("Found " + numWith2 + " with two points");
    System.out.println("Found " + numWithMoreThan2 + " with more than two points");

    I am getting this output:

    at end
    (52.476454581539066,13.30634795068982), (52.47596396079579,13.30637868433547), (52.47569331844956,13.306412770742464), (52.47541354914189,13.306483923788754), (52.47541336287737,13.306484296317793)
    at end
    (52.50342754654797,13.373002522580382), (52.503383588121466,13.372910507907953), (52.503166962485764,13.372685500368897), (52.50316621742769,13.37268494157534)
    at end
    (52.53548441534082,13.46005045160764), (52.53523649726591,13.461802083145129), (52.53523593847236,13.461802828203204)
    at base
    (52.48337188698437,13.375550434936965), (52.48337170071986,13.375550807466004), (52.4833798963587,13.375753649527288)
    at base
    (52.45093727374682,13.59829579140907), (52.45093727374682,13.59829597767359), (52.45092293137885,13.598419098520706), (52.450935969895184,13.598492486741225)
    at end
    (52.42476841266681,13.573765685567983), (52.42490047421084,13.573678327508532), (52.42519179191869,13.57467558774372), (52.42519197818321,13.574676146537277)
    at base
    (52.56125355276287,13.36488623242571), (52.56125448408547,13.364887163748305), (52.561264169840456,13.364885487367633)
    at base
    (52.51816852058847,13.441084066951664), (52.51816852058847,13.441084253216182), (52.518056948141535,13.442171106685052), (52.518036831573475,13.442367429488169)
    at base
    (52.548136432799765,13.258880114381316), (52.5481368053288,13.25888104570391), (52.548243162369204,13.26015565380802), (52.54824297610468,13.260159192833882)
    at end
    (52.40361844905358,13.581324672281548), (52.404047416241035,13.582530176249076), (52.404047975034594,13.582531107571672)
    at base
    (52.42031669066064,13.553802413205856), (52.42031687692516,13.5538018544123), (52.420658672317686,13.55312254771119), (52.420889454056834,13.552670483723368)
    at base
    (52.55131298790827,13.405728639790311), (52.55131298790827,13.405728639790311), (52.5514577154396,13.403715679132544)
    at base
    (52.50141495841924,13.435063438901233), (52.5014145858902,13.435062880107676), (52.50065853820723,13.434184456635665)
    Found 2501 with two points
    Found 13 with more than two points

    So in summary:

    • there are quite a few cases where the coordinates of base and adj nodes are equal (within the 1.e-6 precision we are using). these are 'loops' in the real world but not really loops in the graph because the node ids are different, otherwise they would be excluded because of Do not create loop-edges #1531. Not sure if anything can/should be done about these cases, but either way this would be for another issue.

    • there are some (not many) cases where the geometry contains duplicate consecutive points ('loops in the geometry'). these are the ones I was concerned about here. in all of these cases a pillar node has the same coordinates as either the base or adj tower node (as also mentioned in should the DouglasPeucker be used for the whole geometry instead of only pillar nodes? #1353). there were no cases where the inter-tower-node geometry (pillar nodes only) has a loop. probably we can get rid of these cases when we apply DouglasPeucker to the whole geometry (including tower) as suggested in should the DouglasPeucker be used for the whole geometry instead of only pillar nodes? #1353.

  3. michaz commented on Aug 27, 2019

    @michaz
    Member

    there are quite a few cases where the coordinates of base and adj nodes are equal (within the 1.e-6 precision we are using). these are 'loops' in the real world

    I think they are not loops but barriers, right? Where a barrier node (like a gate) is exploded to a blocked edge.

    Loops should, on the contrary, should be fixed by inserting an artificial extra graph node, and not lead to coincident nodes. I think this works.

  4. easbar commented on Aug 27, 2019

    @easbar
    MemberAuthor

    Where a barrier node (like a gate) is exploded to a blocked edge.

    Is this some OSM convention or do we do this somewhere ?

    Loops should, on the contrary, should be fixed by inserting an artificial extra graph node, and not lead to coincident nodes. I think this works.

    We do this already (#1531). The problem here seems to be that we do Douglas-Peucker for the inner geometry only, but then the first/last pillar node can still be equal to the first/last tower node.

  5. michaz commented on Aug 27, 2019

    @michaz
    Member

    Is this some OSM convention or do we do this somewhere ?

    We do it.

  6. michaz commented on Aug 27, 2019

    @michaz
    Member

    Search for "addBarrierNode" in OSMReader

  7. karussell commented on Aug 27, 2019

    @karussell
    Member

    I think they are not loops but barriers, right? Where a barrier node (like a gate) is exploded to a blocked edge.

    Outch! Thanks @michaz for reminding me about this workaround. This is indeed a bit ugly.

  8. michaz commented on Aug 27, 2019

    @michaz
    Member

    Hmm, do you have a better idea? I stared at it for an hour and didn't. ,-)

  9. easbar commented on Aug 28, 2019

    @easbar
    MemberAuthor

    ok good to know, but so far I had no problems with these barrier edges (maybe we need to include them in the random graph tests though).

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