Skip to content

Failed Reprojection of Certain Geographic Polygons #9700

@moss-xyz

Description

@moss-xyz

Bug Description

In the process of plotting some h3 hexes, I started running into a wild bug: it seems there is some hitch during reprojection that is causing Vega to fill the entire outer boundary of the map with the polygon.

Below is a basic example, with a single hexagon in EPSG:4326 (WGS84) coordinates (where lat ranges from -90 to 90, and lon ranges from -180 to 180). Note that I kept the polygon unfilled so you could see what was happening.

{
  "$schema": "https://vega.github.io/schema/vega-lite/v5.20.1.json",
  "config": {"view": {"continuousHeight": 800, "continuousWidth": 800}},
  "data": {"name": "hex"},
  "datasets": {
    "hex": [
      {
        "geometry": {
          "coordinates": [
            [
              [174.82452404381874, -41.29790050306431],
              [174.81940173732693, -41.30098816110715],
              [174.82014390887468, -41.30593404925304],
              [174.82600905735126, -41.307792013940954],
              [174.8311312918481, -41.304704070903085],
              [174.83038844992387, -41.299758448186914],
              [174.82452404381874, -41.29790050306431]
            ]
          ],
          "type": "Polygon"
        },
        "hex": "88bb294289fffff",
        "type": "Feature"
      }
    ]
  },
  "mark": {"filled": false, "type": "geoshape"},
  "projection": {"type": "mercator"},
  "usermeta": {"embedOptions": {}},
  "width": "container"
}

Interestingly, the hexagon does correctly appear in this map - you just have to really zoom in to see it for some reason: update the code to change the following line...

"projection": {"type": "mercator","center":[174.77, -41.30], "scale":200000},

... and it appears!

Why do I say this is a specific issue to reprojection? Well, it doesn't happen if "type":"identity", and it happens with any type projection I put in there - equalEarth, transverseMercator, etc.

This is mainly posing an issue because it is messing up the auto-determined extent variable - I have to manually set center and scale properties to actually "see" the data I care about! I also have to plot my polygons are unfilled entities, i.e. I can't make a choropleth.

Worryingly, I can't make it be an issue on every polygon I plot... but it is happening to many of them. For example, this New Zealand outline seems to plot fine...

Toggle to show NZ Example This comes from Natural Earth, [per the Python documentation](https://altair-viz.github.io/user_guide/marks/geoshape.html#basic-map)
{
  "$schema": "https://vega.github.io/schema/vega-lite/v5.20.1.json",
  "config": {"view": {"continuousHeight": 300, "continuousWidth": 300}},
  "data": {"name": "data-f351af4caeb47fc8292d432c8b60b8aa"},
  "datasets": {
    "data-f351af4caeb47fc8292d432c8b60b8aa": [
      {
        "NAME": "New Zealand",
        "geometry": {
          "coordinates": [
            [
              [
                [176.8858236026052, -40.0659778785822],
                [176.50801720611926, -40.60480803808957],
                [176.01244022044023, -41.28962411882147],
                [175.23956749908297, -41.68830779395328],
                [175.06789839100935, -41.42589487077513],
                [174.65097293527847, -41.2818209775454],
                [175.22763024322356, -40.45923552832336],
                [174.9001566917899, -39.9089332008472],
                [173.82404666574394, -39.50885426204351],
                [173.85226199777532, -39.14660247167748],
                [174.57480187408035, -38.797683200842755],
                [174.74347374908098, -38.02780771255843],
                [174.6970166364506, -37.38112883885792],
                [174.2920284365792, -36.71109221776149],
                [174.31900353423552, -36.53482390721391],
                [173.8409965355357, -36.12198088963413],
                [173.0541711774596, -35.23712533950039],
                [172.63600548735377, -34.52910654066943],
                [173.00704227120946, -34.45066171645037],
                [173.55129845610747, -35.00618336358801],
                [174.3293904971262, -35.26549570082862],
                [174.61200890533044, -36.15639739354052],
                [175.33661583892712, -37.20909799575827],
                [175.3575964704376, -36.52619394302117],
                [175.80888675364253, -36.79894215265767],
                [175.9584900251275, -37.55538176854612],
                [176.76319542877656, -37.881253350578675],
                [177.4388131045605, -37.961248467766495],
                [178.01035444570866, -37.579824721020174],
                [178.51709354076274, -37.6953732236248],
                [178.27473107331383, -38.58281259537314],
                [177.97046023997927, -39.166342868812976],
                [177.20699262929918, -39.14577564876082],
                [176.93998050364706, -39.44973642350161],
                [177.0329464053401, -39.879942722331464],
                [176.8858236026052, -40.0659778785822]
              ]
            ],
            [
              [
                [169.66781456937315, -43.555325616226376],
                [170.52491987536615, -43.031688327812816],
                [171.125089960004, -42.51275359473782],
                [171.56971398344325, -41.767424411792135],
                [171.94870893787186, -41.514416599291124],
                [172.0972270042787, -40.956104424809716],
                [172.79857954334403, -40.4939620908235],
                [173.02037479074076, -40.919052422856446],
                [173.2472343285021, -41.33199879330081],
                [173.9584053897028, -40.926700534835646],
                [174.24758670480816, -41.34915536882171],
                [174.24851688058942, -41.77000823340673],
                [173.87644656808794, -42.23318409603879],
                [173.2227396995957, -42.970038344088614],
                [172.71124637277074, -43.372287693048555],
                [173.08011274647015, -43.853343601253606],
                [172.3085836123525, -43.86569426857136],
                [171.45292524646362, -44.2425188128437],
                [171.18513797432718, -44.89710418068486],
                [170.61669721911653, -45.908928724959736],
                [169.8314221540093, -46.35577483498757],
                [169.33233117093428, -46.641235446967876],
                [168.41135379462855, -46.61994475686363],
                [167.76374474514682, -46.29019744240919],
                [166.67688602118417, -46.219917494492236],
                [166.50914432196467, -45.85270476662619],
                [167.0464241885033, -45.110941257508635],
                [168.30376346259686, -44.12397307716614],
                [168.94940880765157, -43.935819187191434],
                [169.66781456937315, -43.555325616226376]
              ]
            ]
          ],
          "type": "MultiPolygon"
        },
        "type": "Feature"
      }
    ]
  },
  "mark": {"type": "geoshape"},
  "projection": {"type": "mercator"},
  "usermeta": {"embedOptions": {}},
  "width": "container"
}

Hope this makes sense to someone! I've pulled my hair out over it all day and can't figure out what is happening at all.

Checklist

  • I checked for duplicate issues.

Metadata

Metadata

Assignees

No one assigned

    Labels

    Type

    No type

    Projects

    No projects

    Milestone

    No milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions