OData Edm.Geography和Edm.Geometry基本类型

本文介绍OData 4.0规范中的一系列地理和平面空间相关的基本类型,包括地理点、线、多边形等,并提及Microsoft.Spatial库支持这些类型的操作。

摘要生成于 C知道 ,由 DeepSeek-R1 满血版支持, 前往体验 >

         OData 4.0规范 中定义了一系列地理空间和平面空间相关的基本类型,用于表示地理和平面空间数据,如下表所示。但奇怪的是,OData的文档却没有给出这些类型的详细定义。

Edm.Geography

Abstract base type for all Geography types

Edm.GeographyPoint

A point in a round-earth coordinate system

Edm.GeographyLineString

Line string in a round-earth coordinate system

Edm.GeographyPolygon

Polygon in a round-earth coordinate system

Edm.GeographyMultiPoint

Collection of points in a round-earth coordinate system

Edm.GeographyMultiLineString

Collection of line strings in a round-earth coordinate system

Edm.GeographyMultiPolygon

Collection of polygons in a round-earth coordinate system

Edm.GeographyCollection

Collection of arbitrary Geography values


Edm.Geometry

Abstract base type for all Geometry types

Edm.GeometryPoint

Point in a flat-earth coordinate system

Edm.GeometryLineString

Line string in a flat-earth coordinate system

Edm.GeometryPolygon

Polygon in a flat-earth coordinate system

Edm.GeometryMultiPoint

Collection of points in a flat-earth coordinate system

Edm.GeometryMultiLineString

Collection of line strings in a flat-earth coordinate system

Edm.GeometryMultiPolygon

Collection of polygons in a flat-earth coordinate system

Edm.GeometryCollection

Collection of arbitrary Geometry values


       OData所定义的这些基本类型,在Microsoft.Spatial中都有实现, Microsoft.Spatial nuget 专门实现了地理空间和几何平面空间操作的类型和方法。Microsoft.Spatial支持 OData v4.0。


        除了Microsoft.Spatial之外,微软在System.Data.Spatial类库中也实现了用于支持SQL空间数据的类型, How to consume SQL Spatial Data with Web API V2.2 for OData V4 》一文介绍了如何使用OData Web API来暴露SQL的空间和平面数据。OData WebApi的实例中也包括了如何使用Microsoft.Spatical类库 - ODataSpatialSample


### 推送固件布局至OData服务器 为了实现将固件布局数据推送到 OData 服务器,在 C# 中可以利用 `System.Web.OData` 其他相关库来构建客户端应用程序。通常情况下,操作流程涉及创建实体对象并调用适当的服务方法来进行更新或插入。 #### 创建 OData 客户端实例 首先需要安装必要的 NuGet 包以便能够访问 OData 资源: ```bash Install-Package Microsoft.AspNet.OData.Client ``` 接着初始化服务根 URI 并配置容器用于后续的数据交互: ```csharp var containerUri = new Uri("http://example.com/odata/"); var container = new Container(containerUri); container.Format.UseJson(); ``` #### 准备要上传的对象模型 定义表示固件布局的类结构,并填充具体属性值准备提交给远程服务器: ```csharp public class FirmwareLayout { public int Id { get; set; } public string Name { get; set; } public byte[] LayoutBlob { get; set; } // 假设二进制形式存储布局信息 } // 实例化新的固件布局条目 FirmwareLayout layoutEntry = new FirmwareLayout{ Name = "Sample Layout", LayoutBlob = File.ReadAllBytes(@"path\to\layoutfile.bin") }; ``` #### 执行推送操作 通过 AddObject 方法向指定集合添加新记录,之后 SaveChanges 提交更改以完成实际写入动作: ```csharp try { var firmwareSet = container.AddToFirmwareLayouts(layoutEntry); container.SaveChanges(); // 尝试保存修改到远端数据库 } catch (DataServiceRequestException ex){ Console.WriteLine($"Error occurred while saving changes: {ex.Message}"); } ``` 上述过程展示了基本模式下如何使用 C# 向支持 OData 协议的服务端发送新增请求[^1]。
评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值