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

setSortKey does not create an error message when key is too large #398

Open
wipfli opened this issue Nov 30, 2022 · 7 comments
Open

setSortKey does not create an error message when key is too large #398

wipfli opened this issue Nov 30, 2022 · 7 comments
Labels
bug Something isn't working

Comments

@wipfli
Copy link
Contributor

wipfli commented Nov 30, 2022

I use the setSortKey to only keep text labels for the largest places in a given tile or subpart of a tile.

My processFeatures function looks like this:

  @Override
  public void processFeature(SourceFeature sourceFeature, FeatureCollector features) {
    if (sourceFeature.isPoint() && sourceFeature.hasTag("wikidata") && sourceFeature.hasTag("name") && (sourceFeature.hasTag("place") || sourceFeature.hasTag("natural") || sourceFeature.hasTag("waterway", "waterfall")))
    {
      var feature = features.point("qrank");
      feature
        .setZoomRange(0, 14)
        .setSortKey(-getQRank(sourceFeature.getTag("wikidata")))
        .setPointLabelGridSizeAndLimit(
          12, // only limit at z_ and below
          128, // break the tile up into _x_ px squares
          5 // any only keep the _ nodes with lowest sort-key in each _px square
        )
        .setBufferPixelOverrides(ZoomFunction.maxZoom(12, 128))
        .setAttr("@qrank", getQRank(sourceFeature.getTag("wikidata")));
      for (var entry : sourceFeature.tags().entrySet()) {
        feature.setAttr(entry.getKey(), entry.getValue());
      }
    }
  }

This works really well in Switzerland where the QRanks are I think all below 2.4M or so. But for larger cities, the label gets dropped. For example, Milano is not included in the map:

image

https://wipfli.github.io/swiss-map/#map=8.78/45.5971/9.3084

I think this is because the QRank of Milano is 4402075 while the maximum allowed key is int SORT_KEY_MAX = 4194303.

From the source code, I would have expected to get an error message when I give a too large or a too small sort key, but I did not get any error message. Is this expected?

I think this is the relevant part of Planetiler:

    public Feature setSortKey(int sortKey) {
      assert sortKey >= FeatureGroup.SORT_KEY_MIN && sortKey <= FeatureGroup.SORT_KEY_MAX : "Sort key " + sortKey +
        " outside of allowed range [" + FeatureGroup.SORT_KEY_MIN + ", " + FeatureGroup.SORT_KEY_MAX + "]";
      this.sortKey = sortKey;
      return this;
    }
@wipfli wipfli added the bug Something isn't working label Nov 30, 2022
@erik
Copy link
Contributor

erik commented Dec 5, 2022

I've run into this as well. If there's not already some reference in the documentation (if there is I've missed it) maybe mentioning somewhere that -ea should be given to the JVM is a good idea.

@wipfli
Copy link
Contributor Author

wipfli commented Dec 5, 2022

What is -ea?

@wipfli
Copy link
Contributor Author

wipfli commented Dec 5, 2022

Thanks for the hint...

@erik
Copy link
Contributor

erik commented Dec 5, 2022

By default, assertions are disabled, -ea ("enable assertions") turns them back on, and would cause all the assert statements to throw exceptions during runtime. https://www.oreilly.com/library/view/introduction-to-jvm/9781787127944/f5b7a6d8-4e0f-41a0-b9c9-0651720472d4.xhtml

@wipfli
Copy link
Contributor Author

wipfli commented Dec 5, 2022

Thanks

@msbarry
Copy link
Contributor

msbarry commented Jan 2, 2023

yeah I use assert here so it throws when run from tests but has no runtime overhead. The original intended workflow here would be to have a unit test that exposes the issue (or at least run once with -ea to test), but do you think always logging a warning at runtime would be better?

@wipfli
Copy link
Contributor Author

wipfli commented Jan 2, 2023

Probably it is enough to highlight the -ea flag in the readme. Should I make a pull request?

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
bug Something isn't working
Projects
None yet
Development

No branches or pull requests

3 participants