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

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

Closed

Description

@zmiao

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"]
        }
      } 
    ]
  }

Activity

  1. self-assigned this
    on Mar 20, 2020
  2. changed the title [-]`within` expression behaves incorrectly when geometry longitude is beyond [-180, 180][/-] [+]`within` expression behaves incorrectly when geometry crosses 180th Meridian[/+] on Mar 23, 2020
  3. zmiao commented on Mar 23, 2020

    @zmiao
    ContributorAuthor

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

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Metadata

Metadata

Assignees

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