Microsoft delivered geospatial assist, which lets you shop region data on your documents and perform spatial calculations for distance and intersections among factors and polygons.
- Spatial records describes the location and shape of gadgets in area.
- Typically, it is able to be used to symbolize the location of someone, an area of hobby, or the boundary of a town, or a lake.
- Common use instances regularly involve proximity queries. For e.G., "discover all universities close to my current vicinity".
A Point denotes a unmarried function in space which represents the precise region, e.G. Avenue deal with of specific university. A factor is represented in DocumentDB the usage of its coordinate pair (longitude and range). Following is an instance of JSON point.
{
"type":"Point",
"coordinates":[ 28.3, -10.7 ]
}
{
"id":"case-university",
"name":"CASE: Center For Advanced Studies In Engineering",
"city":"Islamabad",
"location": {
"type":"Point",
"coordinates":[ 33.7194136, -73.0964862 ]
}
}
To retrieve the university name primarily based at the location, you could use the subsequent query.
SELECT c.name FROM c
WHERE c.id = "case-university" AND ST_ISVALID({
"type":"Point",
"coordinates":[ 33.7194136, -73.0964862 ] })
When the above query is accomplished you will acquire the subsequent output.
[
{
"name": "CASE: Center For Advanced Studies In Engineering"
}
]
Create Document with Geospatial Data in .NET
You can create a document with geospatial information, allow’s check a simple instance in which a college file is created.
private async static Task CreateDocuments(DocumentClient client) {
Console.WriteLine();
Console.WriteLine("**** Create Documents ****");
Console.WriteLine();
var uniDocument = new UniversityProfile {
Id = "nust",
Name = "National University of Sciences and Technology",
City = "Islamabad",
Loc = new Point(33.6455715, 72.9903447)
};
Document document = await CreateDocument(client, uniDocument);
Console.WriteLine("Created document {0} from typed object", document.Id);
Console.WriteLine();
}
Following is the implementation for the UniversityProfile class.
public class UniversityProfile {
[JsonProperty(PropertyName = "id")]
public string Id { get; set; }
[JsonProperty("name")]
public string Name { get; set; }
[JsonProperty("city")]
public string City { get; set; }
[JsonProperty("location")]
public Point Loc { get; set; }
}
When the above code is compiled and done, you will obtain the subsequent output.
**** Create Documents ****
Created new document: nust
{
"id": "nust",
"name": "National University of Sciences and Technology",
"city": "Islamabad",
"location": {
"type": "Point",
"coordinates": [
33.6455715,
72.9903447
]
},
"_rid": "Ic8LAMEUVgANAAAAAAAAAA==",
"_ts": 1450200910,
"_self": "dbs/Ic8LAA==/colls/Ic8LAMEUVgA=/docs/Ic8LAMEUVgANAAAAAAAAAA==/",
"_etag": "\"00004100-0000-0000-0000-56704f4e0000\"",
"_attachments": "attachments/"
}
Created document nust from typed object