/// <summary> /// Checks a Feature object for errors in its Geometry. E.g. self intersection. /// </summary> /// <param name="feature">The feature.</param> /// <returns>Validation result.</returns> public GeometryValidationResult ValidateFeatureGeometry(Feature feature) { GeometryValidationResult result = new GeometryValidationResult(); GeometryConversionTool geometryConversionTool = new GeometryConversionTool(); List <SqlGeometry> sqlGeometries = geometryConversionTool.FeatureGeometryToSqlGeometries(feature); if (sqlGeometries.Any()) { foreach (SqlGeometry sqlGeometry in sqlGeometries) { result = ValidateGeometry(sqlGeometry); if (!result.IsValid) { return(result); } } return(result); } return(new GeometryValidationResult { IsValid = true, StatusCode = (int)GeometryValidationStatusId.Valid, GeometryValidationStatusId = GeometryValidationStatusId.Valid }); }
/// <summary> /// Checks a SqlGeometry object for errors. E.g. self intersection. /// </summary> /// <param name="sqlGeometry">The SQL geometry.</param> /// <returns>Validation result.</returns> public GeometryValidationResult ValidateGeometry(SqlGeometry sqlGeometry) { const int DESCRIPTION_START_INDEX = 7; const int STATUS_CODE_END_INDEX = 5; string str = sqlGeometry.IsValidDetailed(); int statusCode = int.Parse(str.Substring(0, STATUS_CODE_END_INDEX)); string description = str.Substring(DESCRIPTION_START_INDEX, str.Length - DESCRIPTION_START_INDEX); GeometryValidationStatusId geometryValidationStatusId; if (!TryConvertIntToEnum(statusCode, out geometryValidationStatusId)) { geometryValidationStatusId = GeometryValidationStatusId.Unknown; } GeometryValidationResult result = new GeometryValidationResult { StatusCode = statusCode, Description = description, IsValid = geometryValidationStatusId == GeometryValidationStatusId.Valid, GeometryValidationStatusId = geometryValidationStatusId }; return(result); }