netcore 空间数据序列化封装

这个项目已经不维护了,因为NetTopologySuite官方已经有了针对于的wepapi geometry序列化的方案, NetTopologySuite.IO.GeoJSON

针对于swagger部分我封装了在这里 dotgeo-extensions

nettopologysuite-aspnetcore-extensions

github repository

NuGet

NetTopologySuite 的扩展, 更加快速的与 aspnetcore 及 swagger ui 结合.

aspnetcore 程序中的序列化

Program.cs in net6

builder.Services.AddControllers()
    .AddJsonOptions(options =>
    {
        options.JsonSerializerOptions.Converters.AddWktJsonConverter();
    });

Startup.cs in net5 or later

Services.AddControllers()
    .AddJsonOptions(options =>
    {
        options.JsonSerializerOptions.Converters.AddWktJsonConverter();
    });

在其他项目中序列化

JsonSerializerOptions jsonSerializerOptions = new JsonSerializerOptions();
jsonSerializerOptions.Converters.AddWktJsonConverter();

var point = new Point(1,3);

var result = JsonSerializer.Serialize(point, jsonSerializerOptions);

Swagger UI

Services.AddSwaggerGen(options =>
{
    options.SchemaFilter<WKTSchemaFilter>();
});

posted @ 2022-03-16 16:35  辣椒鱼儿酱  阅读(101)  评论(0编辑  收藏  举报