Skip to content
This repository has been archived by the owner on Aug 8, 2023. It is now read-only.

within expression behaves incorrectly when geometry crosses 180th Meridian #16326

Closed
zmiao opened this issue Mar 20, 2020 · 1 comment · Fixed by #16330
Closed

within expression behaves incorrectly when geometry crosses 180th Meridian #16326

zmiao opened this issue Mar 20, 2020 · 1 comment · Fixed by #16330
Assignees

Comments

@zmiao
Copy link
Contributor

zmiao commented Mar 20, 2020

Currently, the within expression only supports calculation for geometries that are with longitudes between -180 to 180. The expression will return incorrect value for those geometries that beyond this range.
cc: @chloekraw @tmpsantos @asheemmamoowala @mourner

Taking the following style as example, the correct behavior should be that all the points with red colors.

{
    "version": 8,
    "metadata": {
      "test": {
        "width": 150,
        "height": 150
      }
    },
    "zoom": 3,
    "center": [-1, -27],
    "sources": {
      "line": {
        "type": "geojson",
        "data": {
          "type": "FeatureCollection",
          "features": [
          {
            "type": "Feature",
            "properties": {},
            "geometry": {
                "type": "Point",
                "coordinates": 
                      [
                        -200.0,
                        83.0
                      ]
            }
          },
          {
            "type": "Feature",
            "properties": {},
            "geometry": {
                "type": "Point",
                "coordinates": 
                      [
                        170.0,
                        81.0
                      ]
                }
           }, 
           {
            "type": "Feature",
            "properties": {},
            "geometry": {
                "type": "Point",
                "coordinates": 
                      [
                        -170.0,
                        81.0
                      ]
            }
          }   
          ]
        }
      },
      "polygon": {
        "type": "geojson",
        "data": {
          "type": "FeatureCollection",
          "features": [
            {
                "type": "Feature",
                "properties": {},
                "geometry": {
                  "type": "Polygon",
                  "coordinates": [
                    [
                      
                        [
                            -205.83984375,
                            80.44493052181339
                        ],
                        [
                            -135,
                            80.44493052181339
                        ],
                        [
                            -135,
                            84.30218294503882
                        ],
                        [
                            -205.83984375,
                            84.30218294503882
                        ],
                        [
                            -205.83984375,
                            80.44493052181339
                        ]
                   
                    ]
                  ]
                }
              }
            ]
          }
        }
    },
    "layers": [
      {
        "id": "border",
        "type": "fill",
        "source": "polygon",
        "paint": {
          "fill-color": "white",
          "fill-opacity": 0.5
        }
      },
      {
        "id": "line",
        "type": "circle",
        "source": "line",
        "paint": {
            "circle-color": ["case", ["within", {
                "type": "Polygon",
                "coordinates": [
                  [
                    [
                        -205.83984375,
                        80.44493052181339
                    ],
                    [
                        -135,
                        80.44493052181339
                    ],
                    [
                        -135,
                        84.30218294503882
                    ],
                    [
                        -205.83984375,
                        84.30218294503882
                    ],
                    [
                        -205.83984375,
                        80.44493052181339
                    ]
                  ]
                ]
              }],  "red", "blue"]
        }
      } 
    ]
  }
@zmiao zmiao self-assigned this Mar 20, 2020
@zmiao zmiao changed the title within expression behaves incorrectly when geometry longitude is beyond [-180, 180] within expression behaves incorrectly when geometry crosses 180th Meridian Mar 23, 2020
@zmiao
Copy link
Contributor Author

zmiao commented Mar 23, 2020

An equivalent ticket in gl js: mapbox/mapbox-gl-js#9442

Sign up for free to subscribe to this conversation on GitHub. Already have an account? Sign in.
Labels
None yet
Projects
None yet
Development

Successfully merging a pull request may close this issue.

1 participant