-
Notifications
You must be signed in to change notification settings - Fork 3.2k
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
Cosmos: Spatial types, functions and spatial indexes #17317
Comments
I was super stoked to use EF Core with dotnet 3 - but I've run into an issue with GeoJSON and the Cosmos DB database. The GeoJSON spec says that coordinates must be stored as follows: {
"type": "Point",
"coordinates": [125.6, 10.1]
} So I created a C# POCO class like so: public class GeoLocation
{
[JsonProperty("type")]
public string Type { get; set; }
[JsonProperty("coordinates")]
public double[] Coordinates { get; set; }
} However using this with EF Core + Cosmos throws the following:
The biggest pain point for us is that Azure Search requires that coordinates be serialised as GEOJson, which is just not possible when using EF Core. In conclusion, it is not possible to use Cosmos, EF Core, and Azure Search with Geo Spacial data :( |
@AndriySvyryd Any easy workarounds using NetTopologySuite.IO.GeoJSON? var geoJsonString = new GeoJsonWriter().Write(point);
var point = new GeoJsonReader().Read<Point>(geoJsonString); |
Yes, setting up value converters should be enough to get basic functionality. |
@xtellurian Does it have to be embedded JSON or will it work as a string containing JSON? |
@AndriySvyryd Do we automatically embed JObject properties? var jObject = new JObject();
new GeoJsonWriter().Write(point, new JTokenWriter(jObject));
var point = new GeoJsonReader().Read<Point>(new JTokenReader(jObject)); |
We don't have any special handling for JObject, but string should work, I'll try it out later |
Thanks for jumping on this to help :) @bricelam {
"GeoLocation": "{ \"type\": \"Point\", \"coordinates\": [100.2093,-15.868]}"
} @AndriySvyryd I don't see a need to use NetTopologySuite.IO.GeoJSON ... |
lol, using NTS just to serialize points is definitely overkill. It’ll come in handy for more complex spatial scenarios though |
The problem with the solution above is that the whole It should be saved as
|
@cwoolum You'd be able to do it when #20584 is implemented. |
In the short term, I think that by utilizing that with a raw sql command, you could feasibly use |
@xtellurian this is literally not working! I just tried it with the data explorer. I added the GeoLocation property to a document and then filtered using the query: "WHERE ST_DISTANCE(c.GeoLocation, {"type": "Point", "coordinates":[100.209,-15.86]}) < 40000". No results were provided. As said by @cwoolum, it cannot work if the GeoJSON object is saved as a serialized string. Does anybody know how to make it works? |
@johnn82 It worked with Azure Search but I never tried using purely Cosmos |
@xtellurian - please, please, please provide a quick writeup and code sample of how to do this. |
Hello! Any news on this? |
This issue is in the Backlog milestone. We have not yet fully planned the next release but we will re-assess the backlog as part of this. However, keep in mind that there are many other high priority features with which it will be competing for resources. Make sure to vote (👍) for this issue if it is important to you. |
Use GeoJSON which supports point, polygon and linestring
The text was updated successfully, but these errors were encountered: