summaryrefslogtreecommitdiff
path: root/src/mongo/db/geo
diff options
context:
space:
mode:
authorHari Khalsa <hkhalsa@10gen.com>2013-04-25 13:10:00 -0400
committerHari Khalsa <hkhalsa@10gen.com>2013-04-29 11:14:11 -0400
commit7f0c71f871e5faa548cb47aee932495694f68244 (patch)
tree36a4e7bcbce1f4a68d79cebb8ba61c03ed5feebb /src/mongo/db/geo
parentbdcc3c3fd1e477df099f818673bab848fcfcba6f (diff)
downloadmongo-7f0c71f871e5faa548cb47aee932495694f68244.tar.gz
SERVER-9401 remove duplicate points in lines because S2 doesn't like them
Diffstat (limited to 'src/mongo/db/geo')
-rw-r--r--src/mongo/db/geo/geoparser.cpp12
1 files changed, 12 insertions, 0 deletions
diff --git a/src/mongo/db/geo/geoparser.cpp b/src/mongo/db/geo/geoparser.cpp
index f74022dde76..3de520be0be 100644
--- a/src/mongo/db/geo/geoparser.cpp
+++ b/src/mongo/db/geo/geoparser.cpp
@@ -123,6 +123,16 @@ namespace mongo {
*out = coordsToPoint(coords);
}
+ void eraseDuplicatePoints(vector<S2Point>* vertices) {
+ for (size_t i = 1; i < vertices->size(); ++i) {
+ if ((*vertices)[i - 1] == (*vertices)[i]) {
+ vertices->erase(vertices->begin() + i);
+ // We could have > 2 adjacent identical vertices, and must examine i again.
+ --i;
+ }
+ }
+ }
+
bool GeoParser::isGeoJSONLineString(const BSONObj& obj) {
BSONElement type = obj.getFieldDotted(GEOJSON_TYPE);
if (type.eoo() || (String != type.type())) { return false; }
@@ -141,12 +151,14 @@ namespace mongo {
if (!isArrayOfCoordinates(coordinateArray)) { return false; }
vector<S2Point> vertices;
parsePoints(obj.getFieldDotted(GEOJSON_COORDINATES).Array(), &vertices);
+ eraseDuplicatePoints(&vertices);
return S2Polyline::IsValid(vertices);
}
void GeoParser::parseGeoJSONLineString(const BSONObj& obj, S2Polyline* out) {
vector<S2Point> vertices;
parsePoints(obj.getFieldDotted(GEOJSON_COORDINATES).Array(), &vertices);
+ eraseDuplicatePoints(&vertices);
out->Init(vertices);
}