Web API ODAtA Spatial support

Topics: ASP.NET Web API
Jan 14, 2014 at 9:47 AM
Are spatial queries supported via Web API?

I am trying to make a query like:
$filter=geo.distance(Location,geography'SRID=4326;POINT (12.3 -23.43)') lt 500.0

I get:

No function signature for the function with name 'geo.distance' matches the specified arguments. The function signatures considered are: geo.distance(Edm.GeographyPoint Nullable=true, Edm.GeographyPoint Nullable=true); geo.distance(Edm.GeometryPoint Nullable=true, Edm.GeometryPoint Nullable=true).

If this is not supported, when it would be? Is there a roadmap for that?
Jan 28, 2014 at 5:48 PM
+1
May 26, 2014 at 2:11 AM


I will try to explain with more detail.



Database



I have a database table called Resturants with three columns


•ResturantID (Long)
•Name (String)
•Phone (int)
•Position (Georgraphy)



I have data for resturants with their LAT & LONG stored in Position column witch is Georgraphy column.



EF6 Code FIRST



Then I have an Entity framework 6 for that table (CODE FIRST). I used the reverse engineer to generate CODE and I get a class as below:



public partial class Resturants

{

public long ResturantID {get;set}

public string Name{get:set:}

public int Phone{get;set}

public System.Data.Entity.Spatial.DbGeorgraphy Position { get;set; }

}





WEB API 2.2 with ODATA v4 (Latest Pre release from Nuget)



I have successfully created the ODATA v4 using the link . 



Now when I run the WEB API service I get



http://localhost:3665/OData/$metadata  <?xml ver=1.0 Encoding=UTF-8>

<edmx:Edmx xmlns:edmx=http://docs.oasis-open.org/odata/ns/edmx version=4.0>

<Schema xmlns:edmx=http://docs.oasis-open.org/odata/ns/edmx Namespace ="Resturnants.EF.Tables>

<Entity type Abstract="true" Name ="Resturants">

<key>

<PropertyRef Name="ResturantID">

</key>

<property Name="ResturantID" Type="Edm:Int64">

<property Name="Name" Type="Edm:String">

<property Name="Phone" Type="Edm:Int32">

<property Name="Position" Type="System.Data.Entity.Spatial.DbGeorgraphy ">

.......

.........



Why ODATA v4



Reason I had to go V4 is 'casue ODATA v3 does not support spatial functions like :

"Get me all resturants by given Lat & Long" OOTB.




I do not wish to write my own ODATA v3 functions to translate LINQ queries to SQL for Geo spatial calculations.





Questions:


1.In my Web API metadata I am expecting the Position column to be Edm:Georgraphy NOT what you see above i.e System.Data.Entity.Spatial.DbGeorgraphy.
2.Do you know why I cannot use WEB API OData v4 OOTB functions like e.g:



http://localhost:3665/OData/Resturants()?$filter=geo.Distance(Position,geography' Point(-122.03547668457 47.6316604614258)') lt 900



thanks



May 27, 2014 at 11:18 PM
Guys, Sorry for long post last time. Just letting everybody know that this is a bug. See below comments from a MS contact:

The type of Position column is System.Data.Entity.Spatial.DbGeography. Then I searched about DbGeography and DEM.Geography. I found this article:

Do Entity Framework Provide Utility that convert DB Type To C# Type

www.csharpcode.info/ask-57536.html

In this article, we can find that System.Data.Entity.Spatial.DbGeography is a ClrEquivalentType of Edm.Geography. And it also mentioned that EF.Utility.CS.ttinclude will internally uses classes from System.Data.Metedata.Edm Namespace. So based on the article and the test results, I think this is a bug that EF doesn’t convert System.Data.Entity.Spatial.DbGeography to edm.Geography internally.
Sep 25, 2014 at 3:48 AM
Some workaround for Odata v3

http://webapiodata.blogspot.com.au/
Jan 12, 2015 at 3:13 PM
Any news regarding this? We're using OData V4 and we're trying to use geo.intersects but we get the same error, i.e:

No function signature for the function with name 'geo.distance' matches the specified arguments. The function signatures considered are: geo.distance(Edm.GeographyPoint Nullable=true, Edm.GeographyPoint Nullable=true); geo.distance(Edm.GeometryPoint Nullable=true, Edm.GeometryPoint Nullable=true).

BR,
Max.