I have identified a problem polygon in a shapefile that I am uploading with the intention of storing the data in my SQL database.
When I create a feature in code I check the IsValid function and it returns True.
When I then pass the WKT to SQL and validate it there it fails.
You can see this by simply creating a feature as below and calling IsValid() and it returns True. Using the same WKT in SQL will fail due to there not being enough distinct points to make a polygon.
Can you please let me know why this would be happening and if there is a way to fix this? If IsValid doesn’t work as expected my only alternative is to do the validation in SQL which is not ideal.
Feature newFeature = new Feature(“POLYGON((-2.679141 56.696908,-2.67976050884605 56.696614232902,-2.67976050884605 56.696614232902,-2.679141 56.696908))”);
DECLARE @geodata varchar(max) = 'POLYGON((-2.679141 56.696908,-2.67976050884605 56.696614232902,-2.67976050884605 56.696614232902,-2.679141 56.696908))'
DECLARE @geo geometry
SET @geo = geometry::STGeomFromText(@geoData, 4326)
SELECT @geo
Feature.IsValid() always returning True
Hi Simon,
I think the case is happened is because we are using NTS lib to check if the wkt is valid but in sql server, it is using sqltypes component to do this. I am guessing there are some differences rules for the validations. As a solution, we provide an alternative way by using SqlTypes, please try the blow codes:
bool isValid = SqlTypesGeometryHelper.IsValid(new Feature("POLYGON((-2.679141 56.696908,-2.67976050884605
56.696614232902,-2.67976050884605 56.696614232902,-2.679141 56.696908))"));
It will return false.
Thanks,
Troy