Skip to content

HTTPS clone URL

Subversion checkout URL

You can clone with HTTPS or Subversion.

Download ZIP
Browse files

Prepare for polygon search

Internal functions can be re-used for the polygon search if
the geometry types are converted to atoms, which is the way
they are stored in the Erlang term representation.

Change-Id: I0b946648976938bc875ac1970731afe9c48c7c66
Reviewed-on: http://review.couchbase.org/10093
Reviewed-by: Filipe David Borba Manana <fdmanana@gmail.com>
Tested-by: Filipe David Borba Manana <fdmanana@gmail.com>
  • Loading branch information...
commit 60b7cf520321b8a6891c3ef2f8fa5c87a7a5fe7d 1 parent 18531c1
Volker Mische vmx authored fdmanana committed
Showing with 18 additions and 15 deletions.
  1. +13 −10 src/geocouch/couch_spatial_updater.erl
  2. +5 −5 test/100-updater.t
23 src/geocouch/couch_spatial_updater.erl
View
@@ -25,6 +25,8 @@
% for output (couch_http_spatial, couch_http_spatial_list)
-export([geocouch_to_geojsongeom/1]).
+% for polygon search
+-export([extract_bbox/2, geojsongeom_to_geocouch/1]).
-include("couch_db.hrl").
-include("couch_spatial.hrl").
@@ -276,12 +278,13 @@ process_results(Results) ->
process_result({K, V}) ->
{Geo} = ?JSON_DECODE(K),
Value = ?JSON_DECODE(V),
- Type = proplists:get_value(<<"type">>, Geo),
+ Type = binary_to_atom(proplists:get_value(<<"type">>, Geo), utf8),
Bbox = case Type of
- <<"GeometryCollection">> ->
+ 'GeometryCollection' ->
Geometries = proplists:get_value(<<"geometries">>, Geo),
lists:foldl(fun({Geometry}, CurBbox) ->
- Type2 = proplists:get_value(<<"type">>, Geometry),
+ Type2 = binary_to_atom(
+ proplists:get_value(<<"type">>, Geometry), utf8),
Coords = proplists:get_value(<<"coordinates">>, Geometry),
case proplists:get_value(<<"bbox">>, Geo) of
undefined ->
@@ -309,20 +312,20 @@ extract_bbox(Type, Coords) ->
extract_bbox(Type, Coords, InitBbox) ->
case Type of
- <<"Point">> ->
+ 'Point' ->
bbox([Coords], InitBbox);
- <<"LineString">> ->
+ 'LineString' ->
bbox(Coords, InitBbox);
- <<"Polygon">> ->
+ 'Polygon' ->
% holes don't matter for the bounding box
bbox(hd(Coords), InitBbox);
- <<"MultiPoint">> ->
+ 'MultiPoint' ->
bbox(Coords, InitBbox);
- <<"MultiLineString">> ->
+ 'MultiLineString' ->
lists:foldl(fun(Linestring, CurBbox) ->
bbox(Linestring, CurBbox)
end, InitBbox, Coords);
- <<"MultiPolygon">> ->
+ 'MultiPolygon' ->
lists:foldl(fun(Polygon, CurBbox) ->
bbox(hd(Polygon), CurBbox)
end, InitBbox, Coords)
@@ -352,7 +355,7 @@ geojsongeom_to_geocouch(Geom) ->
_ ->
proplists:get_value(<<"coordinates">>, Geom)
end,
- {binary_to_atom(Type, latin1), Coords}.
+ {binary_to_atom(Type, utf8), Coords}.
% @doc Transforms internal structure to a GeoJSON geometry (as Erlang terms)
geocouch_to_geojsongeom({Type, Coords}) ->
10 test/100-updater.t
View
@@ -80,25 +80,25 @@ test_bbox_initbbox() ->
"Bounding box with initial bounding box (b)").
test_extract_bbox() ->
- etap:is(?MOD:extract_bbox(<<"Point">>, [100.0, 0.0]),
+ etap:is(?MOD:extract_bbox('Point', [100.0, 0.0]),
[100.0, 0.0, 100.0, 0.0],
"Extract bounding box of a Point"),
- etap:is(?MOD:extract_bbox(<<"LineString">>, [[100.0, 0.0], [101.0, 1.0]]),
+ etap:is(?MOD:extract_bbox('LineString', [[100.0, 0.0], [101.0, 1.0]]),
[100.0, 0.0, 101.0, 1.0],
"Extract bounding box of a LineString"),
- etap:is(?MOD:extract_bbox(<<"Polygon">>, [
+ etap:is(?MOD:extract_bbox('Polygon', [
[[100.0, 0.0], [101.0, 0.0], [101.0, 1.0], [100.0, 1.0], [100.0, 0.0]],
[[100.2, 0.2], [100.8, 0.2], [100.8, 0.8], [100.2, 0.8], [100.2, 0.2]]
]),
[100.0, 0.0, 101.0, 1.0],
"Extract bounding box of a Polygon"),
- etap:is(?MOD:extract_bbox(<<"MultiLineString">>, [
+ etap:is(?MOD:extract_bbox('MultiLineString', [
[[100.0, 0.0], [101.0, 1.0]],
[[102.0, 2.0], [103.0, 3.0]]
]),
[100.0, 0.0, 103.0, 3.0],
"Extract bounding box of a Polygon"),
- etap:is(?MOD:extract_bbox(<<"MultiPolygon">>, [
+ etap:is(?MOD:extract_bbox('MultiPolygon', [
[[[102.0, 2.0], [103.0, 2.0], [103.0, 3.0], [102.0, 3.0],
[102.0, 2.0]]],
[[[100.0, 0.0], [101.0, 0.0], [101.0, 1.0], [100.0, 1.0],
Please sign in to comment.
Something went wrong with that request. Please try again.