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

Geo: Geo-shape circles using `radius` as diameter #7301

Closed
clintongormley opened this Issue Aug 15, 2014 · 1 comment

Comments

Projects
None yet
3 participants
@clintongormley
Copy link
Member

commented Aug 15, 2014

PUT /attractions
{
  "mappings": {
    "landmark": {
      "properties": {
        "name": {
          "type": "string"
        },
        "location": {
          "type": "geo_shape"
        }
      }
    }
  }
}

PUT /attractions/landmark/dam_square
{
    "name" : "Dam Square, Amsterdam",
    "location" : {
        "type" : "polygon", 
        "coordinates" : [[ 
          [ 4.89218, 52.37356 ], 
          [ 4.89205, 52.37276 ], 
          [ 4.89301, 52.37274 ], 
          [ 4.89392, 52.37250 ], 
          [ 4.89431, 52.37287 ], 
          [ 4.89331, 52.37346 ], 
          [ 4.89305, 52.37326 ], 
          [ 4.89218, 52.37356 ]
        ]]
    }
}

This point is less than 700m from the above shape, but the search only matches if you set the radius to 1.4km, ie twice the distance:

GET /attractions/landmark/_search
{
  "query": {
    "geo_shape": {
      "location": {
        "shape": {
          "type": "circle",
          "coordinates": [
            4.89994,
            52.37815
          ],
          "radius": "1.4km"
        }
      }
    }
  }
}

I've tried the same thing at much bigger distances and it exhibits the same problem. The radius needs to be double the distance in order to overlap, which makes me think that it is being used as a diameter instead.

@tincugabriel

This comment has been minimized.

Copy link

commented Aug 18, 2014

Is this an elasticsearch bug or a spatial4j bug ? The code and comments for SpatialContext.makeCircle() , which is being used , names the parameter distance instead of radius, which seems a bit ambiguous to me

colings86 added a commit to colings86/elasticsearch that referenced this issue Aug 20, 2014

Geo: fixes circle radius calculation
This change fixes the creation circle shapes o it calculates it correctly instead of essentially using the diameter as the radius.  The radius has to be converted into degrees but calculating the ratio of the desired radius to the circumference of the earth and then multiplying it by 360 (number of degrees around the earths circumference).  This issue here was that it was only multiplied by 180 making the result out by a factor of 2.  Also made the test for circles actually check to make sure it has the correct centre and radius.

Closes elastic#7301

colings86 added a commit that referenced this issue Aug 20, 2014

Geo: fixes circle radius calculation
This change fixes the creation circle shapes o it calculates it correctly instead of essentially using the diameter as the radius.  The radius has to be converted into degrees but calculating the ratio of the desired radius to the circumference of the earth and then multiplying it by 360 (number of degrees around the earths circumference).  This issue here was that it was only multiplied by 180 making the result out by a factor of 2.  Also made the test for circles actually check to make sure it has the correct centre and radius.

Closes #7301

@colings86 colings86 changed the title Geo-shape circles using `radius` as diameter Geo: Geo-shape circles using `radius` as diameter Aug 21, 2014

colings86 added a commit that referenced this issue Sep 8, 2014

Geo: fixes circle radius calculation
This change fixes the creation circle shapes o it calculates it correctly instead of essentially using the diameter as the radius.  The radius has to be converted into degrees but calculating the ratio of the desired radius to the circumference of the earth and then multiplying it by 360 (number of degrees around the earths circumference).  This issue here was that it was only multiplied by 180 making the result out by a factor of 2.  Also made the test for circles actually check to make sure it has the correct centre and radius.

Closes #7301
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
You can’t perform that action at this time.