Uploaded image for project: 'Core Server'
  1. Core Server
  2. SERVER-14360

Add support for SWEREF99TM coordinates in geo

    • Type: Icon: Improvement Improvement
    • Resolution: Unresolved
    • Priority: Icon: Major - P3 Major - P3
    • None
    • Affects Version/s: 2.6.3
    • Component/s: Geo, Index Maintenance
    • Labels:
    • Query Integration

      We are building an API which contains geometries in both WGS84 and SWEREF99TM coordinate system, so the end user can choose what coordinate system to use.
      We have indexed the collection as follows:

      db.test.ensureIndex({"WGS84" : "2dsphere"},{ "min": -180, "max": 180})
      db.test.ensureIndex({"SWEREF99TM" : "2dsphere"},{ "min": 250000, "max": 7680000.0})
      

      We can insert WGS84 geometries without any problem, but the SWEREF99TM geometries throws the error:

      WriteConcern detected an error 'insertDocument :: caused by :: 16755 Can't extract geo keys from object, malformed geometry?
      

      I downloaded the source code for mongodb and found the following in geoparser.cpp:

      bool isValidLngLat(double lng, double lat) {
          return lat >= -90 && lat <= 90 && lng >= -180 && lng <= 180;
      }
      

      This means that we cannot use coordinate systems other than WGS84. My SWEREF99TM is a valid GEOJSON (checked with geojsonlint.com).

      I have made a simple c# program to reproduce the problem.

      string gj = "{\"SWEREF99TM\":{\"type\":\"LineString\",\"coordinates\":[[380694.924325359, 6167754.54137404], [380640.498108361, 6167711.07075937]]}}";
      BsonDocument bdGeo = BsonSerializer.Deserialize<BsonDocument>(gj);
      MongoClient client = new MongoClient("mongodb://localhost");
      client.GetServer().GetDatabase("test").GetCollection("test").Save(bdGeo); //throws WriteConcern detected an error 'insertDocument :: caused by :: 16755 Can't extract geo keys from object, malformed geometry?
      

      The boundary of SWEREF99TM is

      minX = 250000;
      maxX = 920000;
      minY = 6100000;
      maxY = 7680000;
      

      So, this can be considered as a bug/feature request so we can use coordinate systems other than WGS84 with 2dsphere indexes and and the new geotypes like MultiLineStrings.

      Untli now we had only simple geometries like Points and LineStrings and used 2d index, but from now we have to support MultiLineStrings and to Index this we have to use the new 2dsphere indexing feature.

      More about SWEREF99TM http://www.lantmateriet.se/en/Maps-and-geographic-information/GPS-and-geodetic-surveys/Reference-systems/Two-dimensional-systems/SWEREF-99-projections/

            Assignee:
            backlog-query-integration [DO NOT USE] Backlog - Query Integration
            Reporter:
            daniel.moqvist@knowit.se daniel moqvist
            Votes:
            4 Vote for this issue
            Watchers:
            11 Start watching this issue

              Created:
              Updated: