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

Non-noded intersection for geoshapes with positive-negative longitudes span #32805

Closed
antonymayi opened this issue Aug 13, 2018 · 2 comments
Closed

Comments

@antonymayi
Copy link

Elasticsearch version (bin/elasticsearch --version): 6.3.2
JVM version (java -version): 1.8.0_171
OS version (uname -a if on a Unix-like system): Ubuntu 16.04.5

Description of the problem including expected versus actual behavior:
Indexing geoshape with positive-negative longitudes span results in topology_exception (found non-noded intersection).

Steps to reproduce:

  1. Create mapping:
curl -X PUT "localhost:9200/oceans" -H 'Content-Type: application/json' -d'
{
    "settings" : {
        "index" : {
            "number_of_shards" : 2,
            "number_of_replicas" : 0
        }
    },
    "mappings": {
       "polygon": {
           "properties": {
               "name": { "type": "keyword" },
               "geometry": { "type": "geo_shape" }
           }
       }
    }
}
'
  1. Index a geojson with positive-negative longitude span - here the Atlantic ocean with following visualtization of the actual points:
    image
curl -X POST "localhost:9200/oceans/polygon/4" -H 'Content-Type: application/json' -d'
{"name": "Atlantic", "geometry": {"type": "Polygon", "coordinates": [[[19.511197231661868, -39.47031010715461], [19.51171875, -76.31035754301745], [-23.37890625, -80.76061470752452], [-65.56640625, -84.10695292268964], [-94.72316693336734, -76.81771433666425], [-66.92680261673468, -75.49039450753801], [-66.3536052334693, -57.10692623078937], [-65.37831150793261, -55.214725604601036], [-68.78897829779179, -55.07517059271076], [-70.4808998540836, -52.49506961393108], [-70.38778880508676, -48.777113719621426], [-59.32608270736283, -15.366324431361265], [-70.83230069269295, -4.559689313729644], [-65.21775397451671, -0.876847745554054], [-50.94200887980013, 0.135127231661438], [-76.91791322154383, 7.796441951241861], [-76.91792791658833, 7.796428858600954], [-79.37602271110781, 9.394925186836758], [-81.76047487874185, 8.43979717011046], [-84.24511834421465, 10.35832224155311], [-85.48480564240484, 12.5871380191716], [-93.13145220971876, 16.81534686461491], [-96.96547124308924, 16.79436807972076], [-98.67919921875, 24.70691524106633], [-98.67854779151178, 24.71019202371468], [-98.0859375, 30.164126343161097], [-91.77978515625, 31.456782472114313], [-86.59423828125, 35.77325759103725], [-82.935791015625, 32.20350534542368], [-82.93560451384513, 32.208841231886574], [-78.662109375, 36.491973470593685], [-76.475830078125, 41.713930073371294], [-81.617431640625, 41.02135510866602], [-87.484130859375, 41.15384235711447], [-93.1640625, 46.619261036171515], [-90.52734374999999, 49.088257784724675], [-85.60546875, 49.43241258024849], [-77.6513671875, 44.5826428195842], [-77.6513671875, 44.58312107016949], [-74.718017578125, 47.96785877999251], [-68.323974609375, 50.28933925329178], [-64.456787109375, 50.812877010308966], [-60.10682961863857, 50.23817940658074], [-60.10620117187501, 50.23842221881728], [-92.7596645109115, 73.8466940910422], [-45.38352860179686, 73.88672728124854], [-45.3515625, 85.08136441846642], [104.58984375, 85.08136441846642], [103.18359375, 78.80197997387756], [103.88671875, 76.22690740640385], [93.33984375, 67.47492238478702], [90.3515625, 61.60639637138628], [81.03515625, 48.922499263758255], [62.2265625, 50.84757295365389], [52.55859375, 52.482780222078226], [37.08984375, 52.5897007687178], [35.463983978034065, 60.47831216682088], [23.37890625, 53.56641415275043], [11.68974616177156, 52.50956126468238], [11.689883579746366, 52.50945931288085], [11.766357421875, 48.122101028190805], [6.932373046875, 47.30903424774781], [0.60435278800226, 47.88702058242903], [0.791029537877729, 43.59642879875736], [0.790983576928416, 43.59639862527959], [0.791015625, 43.59630591596548], [9.49095272307949, 44.96630757267702], [9.4482421875, 44.99588261816546], [14.3701171875, 47.18971246448421], [19.2919921875, 43.83452678223682], [19.399214033366754, 43.803926747210355], [21.533203125, 45.98169518512228], [41.57222662048956, 49.610683752792404], [41.904555757584106, 44.149843230762855], [41.923828125, 41.409775832009565], [40.25390625, 39.436192999314095], [29.619140625, 38.89103282648846], [29.61067711737512, 38.89769462928316], [29.696044921875, 37.38761749978395], [37.320556640625, 37.483576550426996], [34.892578125, 31.297327991404266], [31.607666015624996, 29.954934549656144], [18.973388671874996, 29.439597566602902], [10.511718575192013, 32.7007239084551], [10.5029296875, 32.69486597787505], [8.3056640625, 35.06597313798418], [4.7900390625, 35.460669951495305], [-4.91679222758553, 34.525302214820385], [-4.909928108365797, 34.50198555141892], [-13.36760885999325, 21.95901786341347], [-10.837837289203115, 8.612753750748837], [-10.87538055442204, 8.581276238559253], [12.304740061404274, 7.667736629398771], [20.118145528512706, -28.46720859372586], [16.981161283552446, -29.13892821983417], [12.68543717360466, -29.264495673908943], [8.543648082987536, -29.372326973594273], [12.5244140625, -35.81781315869662], [19.511197231661868, -39.47031010715461]]]}}
'

Provide logs (if relevant):

{
    "error": {
        "caused_by": {
            "reason": "found non-noded intersection between LINESTRING ( -180.0 -78.56262183968872, -23.37890625 -80.76061470752452 ) and LINESTRING ( -65.56640625 -84.10695292268964, -94.72316693336734 -76.81771433666425 ) [ (-82.25677483863264, -79.93433306095552, NaN) ]",
            "type": "topology_exception"
        },
        "reason": "failed to parse [geometry]",
        "root_cause": [
            {
                "reason": "failed to parse [geometry]",
                "type": "mapper_parsing_exception"
            }
        ],
        "type": "mapper_parsing_exception"
    },
    "status": 400
}
@DaveCTurner
Copy link
Contributor

http://geojsonlint.com also rejects this geometry because it runs clockwise. Quoting the docs:

IMPORTANT NOTE: WKT does not enforce a specific order for vertices thus ambiguous polygons around the dateline and poles are possible. GeoJSON mandates that the outer polygon must be counterclockwise and interior shapes must be clockwise, which agrees with the Open Geospatial Consortium (OGC) Simple Feature Access specification for vertex ordering.

Elasticsearch accepts both clockwise and counterclockwise polygons if they appear not to cross the dateline (i.e. they cross less than 180° of longitude), but for polygons that do cross the dateline (or for other polygons wider than 180°) Elasticsearch requires the vertex ordering to comply with the OGC and GeoJSON specifications. Otherwise, an unintended polygon may be created and unexpected query/filter results will be returned.

This polygon is wider than 180°, so Elastisearch tries to fix its orientation, but this isn't possible. The fix is to orient it correctly:

$ curl 'http://localhost:9200/oceans/polygon/good?pretty' -H 'Content-type: application/json' --data-binary $'{"name":"Atlantic","geometry":{"coordinates":[[[19.511197231661868,-39.47031010715461],[12.5244140625,-35.81781315869662],[8.543648082987536,-29.372326973594273],[12.68543717360466,-29.264495673908943],[16.981161283552446,-29.13892821983417],[20.118145528512706,-28.46720859372586],[12.304740061404274,7.667736629398771],[-10.87538055442204,8.581276238559253],[-10.837837289203115,8.612753750748837],[-13.36760885999325,21.95901786341347],[-4.909928108365797,34.50198555141892],[-4.91679222758553,34.525302214820385],[4.7900390625,35.460669951495305],[8.3056640625,35.06597313798418],[10.5029296875,32.69486597787505],[10.511718575192013,32.7007239084551],[18.973388671874996,29.439597566602902],[31.607666015624996,29.954934549656144],[34.892578125,31.297327991404266],[37.320556640625,37.483576550426996],[29.696044921875,37.38761749978395],[29.61067711737512,38.89769462928316],[29.619140625,38.89103282648846],[40.25390625,39.436192999314095],[41.923828125,41.409775832009565],[41.904555757584106,44.149843230762855],[41.57222662048956,49.610683752792404],[21.533203125,45.98169518512228],[19.399214033366754,43.803926747210355],[19.2919921875,43.83452678223682],[14.3701171875,47.18971246448421],[9.4482421875,44.99588261816546],[9.49095272307949,44.96630757267702],[0.791015625,43.59630591596548],[0.790983576928416,43.59639862527959],[0.791029537877729,43.59642879875736],[0.60435278800226,47.88702058242903],[6.932373046875,47.30903424774781],[11.766357421875,48.122101028190805],[11.689883579746366,52.50945931288085],[11.68974616177156,52.50956126468238],[23.37890625,53.56641415275043],[35.463983978034065,60.47831216682088],[37.08984375,52.5897007687178],[52.55859375,52.482780222078226],[62.2265625,50.84757295365389],[81.03515625,48.922499263758255],[90.3515625,61.60639637138628],[93.33984375,67.47492238478702],[103.88671875,76.22690740640385],[103.18359375,78.80197997387756],[104.58984375,85.08136441846642],[-45.3515625,85.08136441846642],[-45.38352860179686,73.88672728124854],[-92.7596645109115,73.8466940910422],[-60.10620117187501,50.23842221881728],[-60.10682961863857,50.23817940658074],[-64.456787109375,50.812877010308966],[-68.323974609375,50.28933925329178],[-74.718017578125,47.96785877999251],[-77.6513671875,44.58312107016949],[-77.6513671875,44.5826428195842],[-85.60546875,49.43241258024849],[-90.52734374999999,49.088257784724675],[-93.1640625,46.619261036171515],[-87.484130859375,41.15384235711447],[-81.617431640625,41.02135510866602],[-76.475830078125,41.713930073371294],[-78.662109375,36.491973470593685],[-82.93560451384513,32.208841231886574],[-82.935791015625,32.20350534542368],[-86.59423828125,35.77325759103725],[-91.77978515625,31.456782472114313],[-98.0859375,30.164126343161097],[-98.67854779151178,24.71019202371468],[-98.67919921875,24.70691524106633],[-96.96547124308924,16.79436807972076],[-93.13145220971876,16.81534686461491],[-85.48480564240484,12.5871380191716],[-84.24511834421465,10.35832224155311],[-81.76047487874185,8.43979717011046],[-79.37602271110781,9.394925186836758],[-76.91792791658833,7.796428858600954],[-76.91791322154383,7.796441951241861],[-50.94200887980013,0.135127231661438],[-65.21775397451671,-0.876847745554054],[-70.83230069269295,-4.559689313729644],[-59.32608270736283,-15.366324431361265],[-70.38778880508676,-48.777113719621426],[-70.4808998540836,-52.49506961393108],[-68.78897829779179,-55.07517059271076],[-65.37831150793261,-55.214725604601036],[-66.3536052334693,-57.10692623078937],[-66.92680261673468,-75.49039450753801],[-94.72316693336734,-76.81771433666425],[-65.56640625,-84.10695292268964],[-23.37890625,-80.76061470752452],[19.51171875,-76.31035754301745],[19.511197231661868,-39.47031010715461]]],"type":"Polygon"}}'
{
  "_index" : "oceans",
  "_type" : "polygon",
  "_id" : "good",
  "_version" : 3,
  "result" : "updated",
  "_shards" : {
    "total" : 1,
    "successful" : 1,
    "failed" : 0
  },
  "_seq_no" : 2,
  "_primary_term" : 1
}

@antonymayi
Copy link
Author

thanks!

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

No branches or pull requests

2 participants