Skip to content

Commit

Permalink
geo_in_rectangle: support east longitude to west longitude without index
Browse files Browse the repository at this point in the history
TODO: Document it.

geo_in_rectangle(column, "200x-100", "100x100") means

             |
        +---200---+
        |    |    |
        +---100---+
             |
     ---+----+----+---
       -100  |   100

geo_in_rectangle(column, "200x100", "100x-100") means

             |
     ---+   200   +---
        |    |    |
     ---+   100   +---
             |
     ---+----+----+---
       -100  |   100
  • Loading branch information
kou committed Dec 8, 2013
1 parent 7d4db6f commit 99cfc6e
Show file tree
Hide file tree
Showing 27 changed files with 1,125 additions and 4 deletions.
28 changes: 24 additions & 4 deletions lib/geo.c
Expand Up @@ -2079,10 +2079,30 @@ grn_bool
grn_geo_in_rectangle_raw(grn_ctx *ctx, grn_geo_point *point,
grn_geo_point *top_left, grn_geo_point *bottom_right)
{
return ((top_left->longitude <= point->longitude) &&
(point->longitude <= bottom_right->longitude) &&
(bottom_right->latitude <= point->latitude) &&
(point->latitude <= top_left->latitude));
if (point->latitude > top_left->latitude) {
return GRN_FALSE;
}
if (point->latitude < bottom_right->latitude) {
return GRN_FALSE;
}

if (top_left->longitude > 0 && bottom_right->longitude < 0) {
if (point->longitude >= top_left->longitude) {
return GRN_TRUE;
}
if (point->longitude <= bottom_right->longitude) {
return GRN_TRUE;
}
return GRN_FALSE;
} else {
if (point->longitude < top_left->longitude) {
return GRN_FALSE;
}
if (point->longitude > bottom_right->longitude) {
return GRN_FALSE;
}
return GRN_TRUE;
}
}

grn_bool
Expand Down
264 changes: 264 additions & 0 deletions test/command/fixture/geo/in_rectangle/north/around_180.grn
@@ -0,0 +1,264 @@
#@include fixture/geo/in_rectangle/ddl.grn

#@disable-logging
load --table LandMarks
[
["point"],
["0x-647999999"],
["0x-647999998"],
["0x-647999997"],
["0x-647999996"],
["0x-647999995"],
["0x-647999994"],
["0x-647999993"],
["0x-647999992"],
["0x647999992"],
["0x647999993"],
["0x647999994"],
["0x647999995"],
["0x647999996"],
["0x647999997"],
["0x647999998"],
["0x647999999"],
["1x-647999999"],
["1x-647999998"],
["1x-647999997"],
["1x-647999996"],
["1x-647999995"],
["1x-647999994"],
["1x-647999993"],
["1x-647999992"],
["1x647999992"],
["1x647999993"],
["1x647999994"],
["1x647999995"],
["1x647999996"],
["1x647999997"],
["1x647999998"],
["1x647999999"],
["2x-647999999"],
["2x-647999998"],
["2x-647999997"],
["2x-647999996"],
["2x-647999995"],
["2x-647999994"],
["2x-647999993"],
["2x-647999992"],
["2x647999992"],
["2x647999993"],
["2x647999994"],
["2x647999995"],
["2x647999996"],
["2x647999997"],
["2x647999998"],
["2x647999999"],
["3x-647999999"],
["3x-647999998"],
["3x-647999997"],
["3x-647999996"],
["3x-647999995"],
["3x-647999994"],
["3x-647999993"],
["3x-647999992"],
["3x647999992"],
["3x647999993"],
["3x647999994"],
["3x647999995"],
["3x647999996"],
["3x647999997"],
["3x647999998"],
["3x647999999"],
["4x-647999999"],
["4x-647999998"],
["4x-647999997"],
["4x-647999996"],
["4x-647999995"],
["4x-647999994"],
["4x-647999993"],
["4x-647999992"],
["4x647999992"],
["4x647999993"],
["4x647999994"],
["4x647999995"],
["4x647999996"],
["4x647999997"],
["4x647999998"],
["4x647999999"],
["5x-647999999"],
["5x-647999998"],
["5x-647999997"],
["5x-647999996"],
["5x-647999995"],
["5x-647999994"],
["5x-647999993"],
["5x-647999992"],
["5x647999992"],
["5x647999993"],
["5x647999994"],
["5x647999995"],
["5x647999996"],
["5x647999997"],
["5x647999998"],
["5x647999999"],
["6x-647999999"],
["6x-647999998"],
["6x-647999997"],
["6x-647999996"],
["6x-647999995"],
["6x-647999994"],
["6x-647999993"],
["6x-647999992"],
["6x647999992"],
["6x647999993"],
["6x647999994"],
["6x647999995"],
["6x647999996"],
["6x647999997"],
["6x647999998"],
["6x647999999"],
["7x-647999999"],
["7x-647999998"],
["7x-647999997"],
["7x-647999996"],
["7x-647999995"],
["7x-647999994"],
["7x-647999993"],
["7x-647999992"],
["7x647999992"],
["7x647999993"],
["7x647999994"],
["7x647999995"],
["7x647999996"],
["7x647999997"],
["7x647999998"],
["7x647999999"],
["8x-647999999"],
["8x-647999998"],
["8x-647999997"],
["8x-647999996"],
["8x-647999995"],
["8x-647999994"],
["8x-647999993"],
["8x-647999992"],
["8x647999992"],
["8x647999993"],
["8x647999994"],
["8x647999995"],
["8x647999996"],
["8x647999997"],
["8x647999998"],
["8x647999999"],
["9x-647999999"],
["9x-647999998"],
["9x-647999997"],
["9x-647999996"],
["9x-647999995"],
["9x-647999994"],
["9x-647999993"],
["9x-647999992"],
["9x647999992"],
["9x647999993"],
["9x647999994"],
["9x647999995"],
["9x647999996"],
["9x647999997"],
["9x647999998"],
["9x647999999"],
["10x-647999999"],
["10x-647999998"],
["10x-647999997"],
["10x-647999996"],
["10x-647999995"],
["10x-647999994"],
["10x-647999993"],
["10x-647999992"],
["10x647999992"],
["10x647999993"],
["10x647999994"],
["10x647999995"],
["10x647999996"],
["10x647999997"],
["10x647999998"],
["10x647999999"],
["11x-647999999"],
["11x-647999998"],
["11x-647999997"],
["11x-647999996"],
["11x-647999995"],
["11x-647999994"],
["11x-647999993"],
["11x-647999992"],
["11x647999992"],
["11x647999993"],
["11x647999994"],
["11x647999995"],
["11x647999996"],
["11x647999997"],
["11x647999998"],
["11x647999999"],
["12x-647999999"],
["12x-647999998"],
["12x-647999997"],
["12x-647999996"],
["12x-647999995"],
["12x-647999994"],
["12x-647999993"],
["12x-647999992"],
["12x647999992"],
["12x647999993"],
["12x647999994"],
["12x647999995"],
["12x647999996"],
["12x647999997"],
["12x647999998"],
["12x647999999"],
["13x-647999999"],
["13x-647999998"],
["13x-647999997"],
["13x-647999996"],
["13x-647999995"],
["13x-647999994"],
["13x-647999993"],
["13x-647999992"],
["13x647999992"],
["13x647999993"],
["13x647999994"],
["13x647999995"],
["13x647999996"],
["13x647999997"],
["13x647999998"],
["13x647999999"],
["14x-647999999"],
["14x-647999998"],
["14x-647999997"],
["14x-647999996"],
["14x-647999995"],
["14x-647999994"],
["14x-647999993"],
["14x-647999992"],
["14x647999992"],
["14x647999993"],
["14x647999994"],
["14x647999995"],
["14x647999996"],
["14x647999997"],
["14x647999998"],
["14x647999999"],
["15x-647999999"],
["15x-647999998"],
["15x-647999997"],
["15x-647999996"],
["15x-647999995"],
["15x-647999994"],
["15x-647999993"],
["15x-647999992"],
["15x647999992"],
["15x647999993"],
["15x647999994"],
["15x647999995"],
["15x647999996"],
["15x647999997"],
["15x647999998"],
["15x647999999"]
]
#@enable-logging
@@ -0,0 +1,93 @@
select LandMarks --sortby '_id' --output_columns 'point' --limit -1 --filter 'geo_in_rectangle(point, "4x647999997", "1x-647999997") > 0'
[
[
0,
0.0,
0.0
],
[
[
[
24
],
[
[
"point",
"WGS84GeoPoint"
]
],
[
"1x-647999999"
],
[
"1x-647999998"
],
[
"1x-647999997"
],
[
"1x647999997"
],
[
"1x647999998"
],
[
"1x647999999"
],
[
"2x-647999999"
],
[
"2x-647999998"
],
[
"2x-647999997"
],
[
"2x647999997"
],
[
"2x647999998"
],
[
"2x647999999"
],
[
"3x-647999999"
],
[
"3x-647999998"
],
[
"3x-647999997"
],
[
"3x647999997"
],
[
"3x647999998"
],
[
"3x647999999"
],
[
"4x-647999999"
],
[
"4x-647999998"
],
[
"4x-647999997"
],
[
"4x647999997"
],
[
"4x647999998"
],
[
"4x647999999"
]
]
]
]
@@ -0,0 +1,4 @@
#@include fixture/geo/in_rectangle/north/around_180.grn

select LandMarks --sortby '_id' --output_columns 'point' --limit -1 \
--filter 'geo_in_rectangle(point, "4x647999997", "1x-647999997") > 0'

0 comments on commit 99cfc6e

Please sign in to comment.