There is a service that given certain criteria such as country state and town you get a well known text defining the polygon or multipolygon that contains the searched area.
You may have an example here.
Now i am trying to insert this data into an SQL Server database using C# and EF6.1 .
The code would be something like:
1st take the polygon string from the service and add it in a variable:
var polygon = GetPolygonFromService(country, state, town);
and then use that to insert in the db:
using(DataContext data = new DataCVontext())
{
var location = new Location
{
Country = country,
State = state,
Town = town,
GeoGraphy = DbGeography.FromText(polygon)
};
data.Locations.Add(location);
data.SaveChanges();
}
Now when i do that i get an error:
The incoming tabular data stream (TDS) remote procedure call (RPC) protocol stream is incorrect. Parameter 4 ("@3"): The supplied value is not a valid instance of data type geography. Check the source data for invalid values. An example of an invalid value is data of numeric type with scale greater than precision
After some research and some tests i have come to the conclusion that this happens because the order of each point in the polygon definition is such that the polygon defines the outer area instead of the inner one, so instead of trying to get the region of New York, it gets the rest of the earth excluding New York.
Is there a way to convert this to the right orientation?