How to store GPS coordinate and search places in a radius from a NoSQL DBMS (like DynamoDB)

后端 未结 3 2086
无人共我
无人共我 2021-02-09 07:41

My team needs a DBMS like DynamoDB to store large amount of data, principally places and coordinates. I\'ve considered to use some GIS-based DBMS (like PostGIS) with an index on

3条回答
  •  粉色の甜心
    2021-02-09 08:41

    I'm currently researching this subject myself. I'm using MongoDb (I know you asked for DynamoDb, but you also asked for general NoSql usage) and my code looks like this:

    record structure:

    public class FrameDocument
    {
        [BsonId]
        public Guid Id { get; set; }
    
        [BsonElement("coordinates")]
        public Point[] Polygon { get; set; }
    }
    
    public class Point
    {
        [BsonElement("name")]
        public string Orientation { get; set; }
    
        [BsonElement("loc")]
        public double[] Location { get; set; }
    }
    

    connecting and ensuring index:

    MongoServer server = MongoServer.Create(connectionString);
    MongoDatabase database = server.GetDatabase(databaseName);
    database.GetCollection(collectionName).EnsureIndex(IndexKeys.GeoSpatial("coordinates.loc"));
    

    writing:

    var items = database.GetCollection(collectionName);
    items.InsertBatch(itemsToInsert);
    

    searching:

    double[,] points; // define you search coordinates
    var items = database.GetCollection(collectionName);
    var query = Query.WithinPolygon("coordinates.loc", points);
    var cursor = items.Find(query);
    

提交回复
热议问题