Hi every one , I must create an api services that the user can post an geometry (location) and retrieve it.
I use PostgreSql as my database and Postgis extension. But now to make it simple I just created a sample app which my controller have a parameter type geometry and try to post it.
First i installed a nugget for NTS
Install-Package Npgsql.EntityFrameworkCore.PostgreSQL.NetTopologySuite -Version 3.1.2
Here are my sample model
using NetTopologySuite.Geometries; namespace GeoLocationAPI.Models { public class GeoLocation { public string Name { get; set; } public Geometry Location { get; set; } } }
And here are my controller
using GeoLocationAPI.Models; using Microsoft.AspNetCore.Mvc; namespace GeoLocationAPI.Controllers { [ApiController] [Route("[controller]")] public class WeatherForecastController : ControllerBase { [HttpPost] public IActionResult AddLocation(GeoLocation geoLocation) { return Ok(); } } }
My swagger look like accepting the geometry data type
{"name": "string","location": {"userData": {},"srid": 4326
}
}
but when i try to post a data i got an error like this
System.NotSupportedException: Deserialization of reference types without parameterless constructor is not supported. Type 'NetTopologySuite.Geometries.Geometry'